Wikia

Vim Tips Wiki

Quickly insert a single word

Talk0
1,613pages on
this wiki
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.

CommentsEdit

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!


Around Wikia's network

Random Wiki