DEV Community

Yufan Lou
Yufan Lou

Posted on

Three Vim Features

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>+

Top comments (0)