Vim Tips Wiki
Register
Advertisement
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
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.

Comments

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!


Advertisement