Emacs for Vim users
Notes for Vim users trying to use Emacs:
- read the manual. really. Emacs has one of the best documentation systems I’ve seen (better than Vim)
- while reading the manual, keep track of any important key bindings, put them in Anki, and learn them.
- get helm. it helps a lot with interactivity and discoverability. if you want something more modern, swiper+counsel+ivy. but I found helm easier to start with.
- in Vim, the paradigm shift is that you’re editing with a sort of language, made of operators, motions, and text objects. a similar paradigm shift in Emacs is that everything is a function. there are no ‘inherent’ key bindings. in Vim, you can
nnoremap l j
, but :normal! l
still moves your cursor right. in Emacs, C-f just calls forward-char
, and you can bind it in the global map to call whatever you want. every editing command is a function. even pressing the letter a
is a function: self-insert-command
. C-a
calls beginning-of-line
, C-e
calls end-of-line
. And so on.
- since everything is a function, if you forget a keybinding, type M-x and look it up by name (e.g. if I don’t know how to move by line, I start typing ‘line’)
- a lot of the keybindings are the same as in the shell, like C-a and C-e (and some that you didn’t even know about work in the shell, like undo)
- if you don’t know something, don’t search the web, but search Info
- skip terminal emacs, get the GUI version. emacs is a GUI program and its full advantages can only be seen in the GUI. honestly you won’t be able to tell the difference since you’ll run everything in Emacs anyways.
- install vterm in Emacs for the best terminal emulator
- embrace org mode for your config. describe in text every addition or change to your configuration, it’ll help your understanding.
- You can run Elisp from anywhere. Just type it in and hit C-x C-e. I set this up in Vim with vim-visualrun
- where vim has autocommands, Emacs has hooks. Use them everywhere. Setting major modes for example. You can even go further:
advice-add
lets you replace functions, run a custom function before/after something, or wrap a function.
- coming from Vim, regexes in Emacs might seem complicated, especially the escaping rules. my advice: ignore them, and reach for the
rx
macro instead. it lets you write regex in a lisp-style syntax. for example, a regex for one-line C-style TODO/FIXME comments can be created with (rx bol (* blank) "//" (? space) (or "TODO" "FIXME") (? ":") (* any) eol)
. Evaluating that gives you a regex string. I actually love this, so much more readable than normal regex. I’m considering implementing something like this for Vim regexes.
- different maps for different modes, kind of similar