loading...

Three Vim Features

louy2 profile image Yufan Lou ・1 min read

To split a line at pattern:

 :5s/pattern/<c-v><cr>/g

<c-v>, or Ctrl-v, in terminal waits for the next character, and inserts it as a literal (verbatim). So upon pressing <cr> (carriage return a.k.a enter key), instead of executing the command, the literal carriage return character (would be shown as ^M) is inserted at the cursor, which is then replaced into the file.

^M is the caret notation of carriage return. Other control characters can be similarly inserted with their corresponding key in the caret notation. For example, cancel is ^Z, so to insert it type

<c-v><c-z>

To copy the whole file into clipboard:

:%y+<cr>

To insert the content of a register, for example, clipboard:

<c-r>+

Discussion

pic
Editor guide