vim-like ctrl+v enter in Emacs

Date: 2012-12-17 (updated: 2022-09-21)

Tags: tools

Suppose you have a list like this

foo, bar, baz, quux

in your Emacs buffer, but you’d rather have one element per line like this

foo
bar
baz
quux

What to do? In vim this is easy:

:%s/,/^M/g

where ^M is inserted using

Ctrl+v

But what to do in Emacs? Turns out it’s just as easy but different (who would have thought ...): You can insert the newline character in your replace-string or something other using the keyboard command

C-q C-j

C-q is somewhat like Ctrl-v in vim and C-j is Enter. Easy as pi, yeah!

See also the page Newline Representations ^M ^J ^L about related issues with newline in Emacs.

social