sponsor Vim development Vim logo Vim Book Ad

basic Tip #466: Insert one character only

 tip karma   Rating 110/51, Viewed by 2738 

Read and edit this tip on the Vim tip wiki. The wiki may have a more recent version of this tip.

created:   April 30, 2003 10:10      complexity:   basic
author:   johnmaxa      as of Vim:   5.7

I have not yet seen this idea yet.  But early in my use and love of Vim, I got frustrated in command mode when I wanted to insert just one character of text.  So I put this in _vimrc:

"insert one character
noremap <somekey>  i<Space><Esc>r

I think it has been one of the most time saving mappings -- and I have remapped most of my keyboard.

 rate this tip  Life Changing Helpful Unfulfilling 

<< generic xml imap to make an element of any word you type | vim windows displaying output inside vim window >>

Additional Notes

Anonymous, May 23, 2004 23:34
Huhn, I've wanted this feature for years -- and expected it would take source modifications to make it happen. Such a simple little script. Thanks!
Bertram Scharpf, March 22, 2005 6:39
This won't be repeated by the . command.

Therefore I define

nnoremap <somekey>    :exec "normal i".nr2char(getchar())."\e"<cr>
nnoremap <someother>  :exec "normal a".nr2char(getchar())."\e"<cr>

Bertram
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.net Logo