Thursday, January 6, 2011

Vim abbreviation not working - solution

Abbreviations in vi editor are the shortcuts for strings. For example, if you frequently need to write the text "Change review not needed", you can have a shortcut like "crn" for this. So every-time you require to type "Change review not needed", you type crn (then a space) and your abbreviation will be expanded (in insert mode).

With my vi editor version:

VIM - Vi IMproved 7.1 (2007 May 12, compiled Jan 8 2009 02:24:14)

I created an abbreviation on my .vimrc:

$ tail -4 ~/.vimrc
:se shiftwidth=4
:se ts=4
:se paste
:ab crn Change review not needed

This abbreviation ("crn") was not working as expected and later I came to know its because of the "set paste" option set on my .vimrc. Vi abbreviations are disabled if the 'paste' option is on. I removed the ":se paste" from my .vimrc and the above abbreviation worked.

Another alternative to set an abbreviation in vim

:inoremap crn Change review not needed

This also require the 'paste' option to be unset/not set.

To unset an abbreviation in vi editor, type in ex mode:

:una crn

To see what all abbreviations are already set, type in ex mode:


For help on vi abbreviation type, type in ex mode:

:h iab
:h ab


Sergio said...

Your tip helped me a lot because my abbreviations in vim only worked in "gvim" and did not know why the thing failed in the terminal.

Anonymous said...

i too faced the same problem,,, had to do a lot of trial and error comment/uncommenting to figure it out....

Gerard said...

Thanks! I wasted an hour trying to find the problem.

© Jadu Saikia