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.
Showing posts with label digraph. Show all posts
Showing posts with label digraph. Show all posts
Wednesday, October 21, 2009
Friday, November 16, 2007
Diagraphs
Sometimes during a text-editing session, you may need to substitute binary characters like the infamous ^M out of your file. Or alternatively, you may just want to insert an internationalized character like ΓΌ. Vim makes this easy to do. During an editing session, typing :digraph will give you a list of available special characters. Pick the desired character from the list, go into insert mode, and press ctrl-k followed by the character code listed in the digraph table. To insert the umlauted u mentioned above I did ctrl-k u:. Note that this works when typing in ex commands too such as substitutions. A final bonus is you type a macro in insert mode, insert control characters as needed, such as ctrl-w k to jump up a window, yank the macro into a register, and execute as needed.
Subscribe to:
Posts (Atom)