IN-Decent

Re-decentralizing internet with free software

Autocomplete in Vim With Abbreviations

Posted at — Jul 15, 2020

In Vim there is a neat feature called abbreviations, which can be used to autocomplete frequently used words and correct most common typo errors.

Abbreviations can be defined as below,

:ab im import

To make abbreviations always available, place abbreviations like below in your ~/.vimrc file.

" Python import statements auto complete
ab im import
iab fim from . import

" Auto complete to fix common typo errors
ab teh the
ab staus status
ab stauts status

Abbreviations defined with :ab will work in both insert and command mode, where as abbreviations defined with :iab and :cab will work only in insert and command mode respectively.

Once abbreviations are added, the whenever short words defined above like im, fim etc is typed and a <space> or <CR> (enter) or <C-j> (ctrl and j) is pressed, words will be autocompleted and typo mistakes defined will be auto corrected.

To avoid auto correction <C-v> (ctrl-v) combination can be used.

Various other commands provided by the abbreviations feature are below,

For full detailed feature set refer Vim help documentation using :help abbreviations.

References:

  1. VIM info pages - :help [name]
  2. Vim Tips Wiki - Using abbreviations
  3. Learn Vimscript the Hard Way - Abbreviations