Type less with abbreviations


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.

Put these abbreviation definitions in your .vimrc for access automatically.

How useful was this tip?

Average rating 3.9 / 5. Vote count: 411

No votes so far! Be the first to rate this tip.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?

Written by

Colin Bartlett

105 Posts

Vim enthusiast and software developer for more than 20 years.
View all posts