Latest revision as of 11:48, November 11, 2012

Abbreviations can save typing, and can improve accuracy, when you need to enter the same text throughout your document. You can also create abbreviations to automatically correct common typing errors (such as changing teh to the).

Examples:

:ab rtfm read the fine manual

Whenever you type 'rtfm' followed by punctuation such as a space or comma, the 'rtfm' will be expanded to 'read the fine manual'. This also happens if you type 'rtfm' then press Esc or Enter.

:ab teh the

Whenever you type the word 'teh', it will be replaced with 'the'.

:ab

List all abbreviations. A flag is shown in the first column: 'i' means the abbreviation will be used in insert mode, 'c' for command-line mode, and '!' for both modes.

:una rtfm

:unabbreviate – remove 'rtfm' from the list of abbreviations.

:abc

:abclear – remove all abbreviations.

Note: To avoid expansion in insert mode, type Ctrl-V after the last character of the abbreviation (on Windows, type Ctrl-Q instead of Ctrl-V).

Contents

The 'helpgrep' command is very useful for searching through all the files located in the .vim/doc directory. This command is especially useful if your .vim/doc directory is littered with script documentation as well as language specific documentation such as provided by script#614, script#826 or script#1330.

The following abbreviation provides faster access to 'helpgrep'.

:cnoreabbrev H helpgrep

This allows me to type :H uganda to search for the word 'uganda' in all of the help files.

I have found myself performing a lot of Ctrl-P/Ctr-N commands on the same strings, and when this happens, I generally add an abbreviation, which saves me a keystroke or two. I do a lot of programming in ColdFusion, and I have these lines in my .vimrc:

Copy it in your .vimrc file, and read the comments. Basically, you have to download the file located here and to copy it in the relevant directory. Then, select a word or an expression in visual mode, and push Shift+F8.