VimTrick: Type less with abbreviations
Use Vim's built in abbreviation mapping system to save time typing
You may not know that Vim has a built-in system for expanding text abbreviations into longer strings. This has numerous applications for all types of Vim users. You might be writing prose and often have long, difficult-to-type names. Or if you’re writing code, you might have common snippets you want to insert by typing just a short abbreviation. Here’s how to save time by storing abbreviation mappings in Vim:
Add the mapping to Vim’s abbreviation registry:
:ab short_string Longer Description
Then, whenever you type
short_string in insert mode, it will auto-expand to
Long Description upon pressing space or enter. Here’s a quick demo:
In the screencast, I first define the new abbreviation. In this case, I want
spacex to expand to
Space Exploration Technologies Corp. automatically. I define it like so:
:ab spacex Space Exploration Technologies Corp.
Then, back in insert mode I simply type
spacex and when I press space, it auto expands.
Was this useful? Help us improve!
With your feedback, we can improve VimTricks. Click a link to vote: