How do I set up automatic text expansions that trigger as I type in Insert mode?
Answer
:iabbrev {abbr} {expansion}
Explanation
:iabbrev (Insert-mode abbreviation) defines a short trigger that automatically expands into longer text when you type it followed by a space, Enter, or punctuation. It is Vim's built-in text expansion / snippet system — no plugins required.
How it works
:iabbrev teh the
Now typing teh in Insert mode automatically corrects to the .
Common uses
Typo correction:
:iabbrev teh the
:iabbrev recieve receive
:iabbrev dont don't
Code snippets:
:iabbrev ifmain if __name__ == "__main__":
:iabbrev clog console.log();<Left><Left>
Boilerplate:
:iabbrev myemail user@example.com
:iabbrev mysig Best regards,<CR>John Doe
Types of abbreviations
| Command | Mode |
|---|---|
:iabbrev |
Insert mode only |
:cabbrev |
Command-line mode only |
:abbreviate |
Both Insert and Command-line |
Managing abbreviations
:iabbrev(no args) — list all Insert-mode abbreviations:iunabbrev {abbr}— remove an abbreviation:iabclear— remove all Insert-mode abbreviations
Tips
- Abbreviations expand on word boundaries —
tehexpands buttehrandoes not - Use
<C-v>before the trigger character to prevent expansion: typeteh<C-v><Space>to keeptehliteral - For multi-line expansions, use
<CR>in the expansion text :noreabbrevprevents recursive expansion if your abbreviation contains another abbreviation- Put abbreviations in your
~/.vimrcto make them permanent