1

For example, I can open a bare vim (without plugin) and input some_long_object and then hit Enter to open a new line, and input a s, hit C-x C-p, it will complete some_long_object for me. If I input some_long_object.some_method_really_long on a new line, then I open a new line and input s, then hit C-x C-p C-x C-p, it will complete some_long_object.some_method_really_long for me.

Vim can also do the same kind of thing on lines.(not only complete word, but also lines)

Out-of-box Emacs seems not doing word completion, line completion, and series completion as good as Vim. It only has an expand. when I use Vim, I can C-x C-p to complete a word, (maybe it is a some_object)and sequentially hit another C-x C-p to complete it, hoping to check what should be following a some_object, (for example it is a some_object.some_method), and C-x C-l will complete line or (use in sequence) lines for me.

So vim can complete one thing after another and I need not think about what should appear next if I am sure what should appear when I hit C-x C-p.

And another thing, I can use C-x C-p to recall what method I've used in this buffer but do not have to really finish the completion.

I heard of but have not used evil before. Can evil do the same thing as I just said? and can I use evil just for completion, not using its other kdbs? I've used to Emacs key bindings and have not used vim for at least 5 years.


I'm been using hippie-expand for years. I don't like the way it does things because it does not give me any feedback how I can use it. It's like exploring on a website without UE designing. I even tried hippie-expand with ido menu. It's just not what I need. I'm not familiar with auto-complete because when I tried it a few years ago, it was full of problems, and besides that its user experience was not as good as vim's completion. Vim's completion just provides me everything what I need and not any more or or any less.

So is there any Emacs extensions, or tweeks that can help me to do completion just like the way as I said?


I've been using Emacs for years. Emacs provides me many huge good things, but with this simple completion thing, I've tried again and again. Maybe the user experience philosophy behind Emacs is not so good as Vim. For example, auto-complete claims it has built a LOW COST operation philosophy behind it. But for me, the simple thing is it uses a input-userlookup-feedback-input-userlookup-feedback loop in its philosophy. It is slower than vim, because vim use a input->not_good?->simple_adjust philosophy. Behind vim it is real Unix philosophy, which is splitting complex things to simple parts. Try to lower the feedback cost and decrease feedback-loop is the central thing what vim provide us.

  • 6
    What does "just like in vim" mean ? – bertfred Oct 11 '16 at 5:56
  • I do not know much about vi. I just know that evil is a vi-layer for emacs: emacswiki.org/emacs/Evil Maybe, you can try that one. – Tobias Oct 11 '16 at 7:04
  • Thanks for your answering. Sorry for not expressing myself clearly. I mean i want Emacs to do word completion, line completion, and completion one after another. when I use vim, I can C-x C-p to complete a word, (maybe it is a 'some_object')and do another C-x C-p to complete it by checking what should be following a 'some_object', (for example it is a 'some_object.some_method'), and C-x C-l do exactly the same thing. – cmal Oct 11 '16 at 12:24
  • 1
    Please edit your question to include the relevant stuff from your comments. Comments can be deleted at any time. The question should stand alone and be clear. – Drew Oct 11 '16 at 15:06
  • 1
    It may be surprising, but Emacs ain't Vim. If the existing options are not satisfying to you, it's time to hack together something yourself. That is the Emacs philosophy. – wasamasa Oct 12 '16 at 8:00
5

If you take a look at evil-maps.el, you'll see that it defines a few of Vim's completion commands:

(define-key evil-insert-state-map "\C-n" 'evil-complete-next)
(define-key evil-insert-state-map "\C-p" 'evil-complete-previous)
(define-key evil-insert-state-map "\C-x\C-n" 'evil-complete-next-line)
(define-key evil-insert-state-map "\C-x\C-p" 'evil-complete-previous-line)

The definition of C-x C-p is:

(evil-define-command evil-complete-previous-line (&optional arg)
  "Complete a whole line.
Calls `evil-complete-previous-line-func'."
  :repeat change
  (interactive "P")
  (if (minibufferp)
      (funcall evil-complete-previous-minibuffer-func)
    (funcall evil-complete-previous-line-func arg)))

Where evil-complete-previous-line-func happens to be:

#'(lambda (arg)
    (let ((hippie-expand-try-functions-list
           '(try-expand-line
             try-expand-line-all-buffers)))
      (hippie-expand arg)))

From this I can judge that what you're after is hippie-expand with the above customization to hippie-expand-try-functions-list. It is a more versatile tool than dabbrev if you're willing to invest a bit of time into it.

  • Thanks, hippie-expand is like walking on bare feet, even with ido menu, whereas Emacs' auto-complete like sitting in an broken cart, and Vim's simple completion implementation is just like flying in a plane. – cmal Oct 12 '16 at 0:50
  • 2
    Feel free to write an auto-complete-mode or company backend to hippie-expand. Poetry won't get you anywhere... – wasamasa Oct 12 '16 at 7:50
4

GNU Emacs has a way to complete words based on buffers you have open. It's bound to M-/ by default.

https://www.gnu.org/software/emacs/manual/html_node/emacs/Dynamic-Abbrevs.html

  • Thanks. What I really need is to change the way Emacs do completion, it's user exprience, the feedback it provides when doing completion, not what word/line Emacs can complete. – cmal Oct 12 '16 at 1:02
1

See https://github.com/redguardtoo/eacl - Emacs auto complete line(s)

The difference between eacl and other solutions:

  • it gets more candidate by grepping files (using GNU Grep) in current project (project root is automatically detected if you use git/svn/mercurial)

  • it can complete multi line statement by grepping (a statement ends with ",". Its definition can be customized by eacl-statement-regex)

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.