Showing posts with label binary. Show all posts
Showing posts with label binary. Show all posts

Wednesday, October 21, 2009

CTRL-V for Literal Characters

When typing in insert or ex mode, hiting CTRL-V allows you to enter a literal character. Some examples:

CTRL-V CTRL-M # enters a literal carriage-return \r
CTRL-V 10 <enter> # enters a null character

After entering the CTRL-V, you can either enter the character explicitly or type in its decimal code. A list of decimal codes is available through the :digraph ex command. If you're curious why this might be useful, I've used it on a number of occasions in conjunction with a substitution to remove binary characters from a file. An example might be:

:%s/CTRL-V CTRL-M//g # remove erroneous CTRL-M from the current file

You can find out the code for any character by putting it under the cursor and hitting "ga" in normal mode. For entering digraphs, you can also hit CTRL-K from insert mode and type the two letter character code preceeding the desired character.