Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

emacs equivalent to vim's word completion with ctrl P

Tags:

emacs

With vim, I can autocomplete and get a list of any words in the buffer by hitting C-p while in insert mode.

Is there a similar command in emacs?

like image 254
dagda1 Avatar asked Sep 02 '14 09:09

dagda1


2 Answers

You can use the hippie-expand command for completion. To bind it to Alt + /, use

(global-set-key "\M-/" 'hippie-expand)
like image 75
choroba Avatar answered Sep 22 '22 11:09

choroba


In addition to hippie-expand, mentioned by @choroba, here are two other standard Emacs word-completion methods:

  • M-/ or C-M-/ -- Dynamic abbrev expansion (aka dabbrev). See the Emacs manual, node Dynamic Abbrev Expansion.

  • M-RET or C-RET in dynamic-completion-mode -- Standard Emacs library completion.el.

Library completion.el is old and apparently little known, but it works great. You can complete not only to words in the same buffer but to words (program symbols etc.) that you have used in the past, including past Emacs sessions.

Your most frequently used completions are prioritized. What you do when dynamic-completion-mode is on is recorded in a "database" on disk: the words you type or traverse, etc. To make good use of library completion.el, read the Commentary in the file. There is no other doc for it, but the Commentary is pretty clear (if not totally up-to-date).

Library Icicles enhances the use of both of the above word-completion methods, dabbrev and complete. When there are multiple possible completions it lets you choose one using better matching possibilities (e.g. substring, regexp, not just prefix).

like image 44
Drew Avatar answered Sep 20 '22 11:09

Drew