DEV Community

Colin Bartlett
Colin Bartlett

Posted on • Originally published at vimtricks.substack.com

VimTrick: Non-printable Characters

At times we might want to use unprintable or other in characters not accessible on our keyboards. For example, if you’d like a search and replace expression to use a carriage return. To enter characters like this in Vim, type CTRL-v while in insert-mode. Then enter the decimal code. You can also use CTRL-m for newlines.

While in insert mode press CTRL-v and then CTRL-m to insert a newline. Or try CTRL-v and then 162 to get ¢.

Over on our VimTricks post, we have a screencast that captures the following substitution to drop each item onto an individual line:

%s/, /,^M  /g
Enter fullscreen mode Exit fullscreen mode

Note that the ^M is a single character inserted by using CTRL-v followed by CTRL-m.

Other characters can be inserted using their encoding number, CTRL-V 13 in the case of carriage return or CTRL-v 9 can be used to insert a horizontal tab. Here are some other characters you can insert, by typing their number after you’ve pressed CTRL-v in insert mode:

  • ¢ 162
  • £ 163
  • © 169
  • ® 174

Here’s a handy list for your reference. Just remember to go into Insert mode, then type CTRL-v, then type the decimal number.

Anyone here using this on a regular basis already? What kind of characters do you need to enter?

Top comments (0)