Vim logo vim online Vim Book Ad

basic Tip #270: Insert a single character

 tip karma   Rating 29/26, Viewed by 1253 

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

[email protected], 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.
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.
SourceForge Logo