I am trying to move from Sublime to Emacs. (Because free and all that.) One thing that I miss is the convenient text expansion available by default in Sublime where it picks up similar strings in the same buffer and makes it easy to select a proper expansion. I am sure this is possible in emacs also but haven't figured out how yet.

When I start typing on a string that is already present in the buffer I would like to be able to expand using a shortcut like Ctrl-Space, Alt-Enter or something like that. How do I set this up?

Bonus question. How to find expansion candidates in other buffers also as a secondary option?

UPDATE: tried out dabbrev and it seems to be what sublime does. I sense that the step to move on towards more dynamic completions isn't that far away but I will leave it for now. I bound M-RET to M-/ with:

(global-set-key (kbd "M-RET") 'dabbrev-expand)

(Why I don't like M-/? Because on a swedish keyboard it comes with a Shift. / is Shift-7.....)

  • 2
    As an aside, company-mode and auto-complete may also do what you want. (They're far more powerful than anything built-into emacs) – PythonNut May 24 '15 at 2:26
  • Good to know. Will look into it later. dabbrev is good enough to start with. – froderik May 24 '15 at 12:05

Try using dabbrev with M-/, it expands strings from the same and other buffers inline.

A more powerful alternative you can customize with your own functions is hippie-expand.

| improve this answer | |
  • Nice. Exactly what I need now. Will try dabbrev for a while and look at hippie-expand and dynamic completion mode as suggested below further on. – froderik May 24 '15 at 12:05

@wasamusa provided the usual (and good) answer: use dabbrev.

Another answer is to use dynamic completion mode, provided by library completion.el. This is a very old, but still useful, library that is (still) included as part of Emacs. The only doc for it is in the file commentary.

More information about dynamic completion mode (similar Q&A, from StackOverflow):

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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