Vim Tips Wiki

Quickly insert a single word

1,624pages on
this wiki
Add New Page
Talk0 Share
Tip 348 Printable Monobook Previous Next

created 2002 · complexity basic · author spudnic · version 5.7

These two mappings make it quick and easy to insert a word.

nmap <buffer> <silent> ,w :exec ":imap \<space\> \<space\>\<esc\>,BB"<CR>i
nmap <buffer> <silent> ,BB :exec ":iunmap \<space\>"<CR>

Given the sentence:

The quick fox.

To add the word "brown" you would put your cursor on the f in fox and type ",w" (or whatever you decide is a good mapping). Type the word brown. As soon as you hit space you are out of insert mode.


Unless I missed something, this doesn't save any keystrokes. Without this, I would use two keystrokes "i" to enter insert mode and ESC to exit. Here I still would still need two keystokes "," and "w".

Size isn't everything! This seems easier. Finding the ESC is harder than , . and with this you're entering ,w together rather than a key before your word and another key at the end. So you start this with 2 characters, but it ends itself automatically, which seems easier and more fluid to me.

I get a lot of mileage out of cw which is change word and dw which is delete word.

Try them out!

Ad blocker interference detected!

Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.

Also on Fandom

Random Wiki