sponsor Vim development Vim logo Vim Book Ad

basic Tip #270: Insert a single character

 tip karma   Rating 37/33, Viewed by 2170 

created:   June 29, 2002 5:38      complexity:   basic
author:   Mikko Pulkkinen      as of Vim:   5.7

Using Insert mode to insert a single character feels clumsy (you need
3 keypresses for one character), so here's a slightly easier way:

:nmap <space> i_<esc>r

Now, when in Normal mode, just press space followed by what
it is you want to insert.

BUG: Repeating the insertion with . doesn't work.

 rate this tip  Life Changing Helpful Unfulfilling 

<<Syntax highlighting is "out of sync", seems to correct itself with refresh ?? | easy (un)commenting out of source code >>

Additional Notes

manfred.strubegger at irm.at, July 23, 2002 2:59
Very good tip, but I prefer <C-I> as a {lhs}.  It is unused and fits better to the insert logic of VIM, although it saves less key strokes.
reiss_david AT yahoo DOT com, July 29, 2002 10:30
I use
:map gt i$<esc>r
:map gb a$<esc>r
These macros were derived from one I found in a Vi FAQ.
Anonymous, May 20, 2003 10:44
yeah, both comments get to the point, but the author was looking for a way to save a keystroke. both solutions are 3 keystrokes long.
If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to [email protected] after searching the archive. Help Bram help Uganda.
Sponsored by Web Concept Group Inc. SourceForge Logo