2

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.

cmal
  • 775
  • 3
  • 14
  • 6
    What does "just like in vim" mean ? – bertfred Oct 11 '16 at 05:56
  • I do not know much about vi. I just know that evil is a vi-layer for emacs: https://www.emacswiki.org/emacs/Evil Maybe, you can try that one. – Tobias Oct 11 '16 at 07: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
  • It can complete one line 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. I have not used evil before. Can evil do the same thing as I just said? and can I use evil just for completion? I've used to Emacs and have not used vim for at least 5 years. – cmal Oct 11 '16 at 12:25
  • vi/ViM doesn’t do completion on its own. What plugin do you use for that? What packages have you tried with Emacs already? – GergelyPolonkai Oct 11 '16 at 12:35
  • no plugin. I can open a bare vim and input a asdf hit Enter, and input a a, hit C-x C-p it will complete asdf for me. if i input a asdf.bbb, then i input a in a new line, and hit C-x C-p C-x C-p, it will complete asdf.bbb for me. – cmal Oct 11 '16 at 12:42
  • 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 08:00
  • @wasamasa ok thanks. Maybe it is time when i should start learning lisp – cmal Oct 12 '16 at 08:04
  • I couldn't follow your description of completion in Vim and so didn't understand what you wanted. So I ran Vim and tried it. Is what you want that repeated uses of completion add the stuff that comes in the buffer after the first thing completed? There is also a pink popup with completion options. Do you want something like that too? – Omar Oct 12 '16 at 18:38
  • If what you are after is that successive completions copy more and more text from where the first bit was found, you can do something that like with dabbrev-expand (normally bound to M-/): if after expanding you press <space> and then M-/ again, it copies the next bit of text after the completion. – Omar Oct 12 '16 at 18:49
  • Yes, I love all things about completion in vim. And yes, I've been using dabbrev-expand till now. one thing is it has no controls on what I want to complete(maybe this time I want to complete a word, next time I want to complete a line. i could only cycle from them), second thing is no pop up window shows, third thing is it needs another <space> or movement to do another completion and I cannot do series completions. Say I have a long sequence of method calls in functional programming, it need double amount of operations than vim. – cmal Oct 13 '16 at 01:58
  • Try the solution in this reddit post. It combines hippie-expand and company to give you a popup menu of lines from the current buffer. I think it'll give you what you want for line completion, at least. – nandkeypull Dec 12 '17 at 00:01

3 Answers3

6

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 01:02
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.

wasamasa
  • 22,178
  • 1
  • 66
  • 99
  • 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 00: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 07:50
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)

chen bin
  • 4,857
  • 20
  • 36