Type less with abbreviations

3.8
(296)

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.

How useful was this tip?

Average rating 3.8 / 5. Vote count: 296

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

81 Posts

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

Leave a reply

Your email address will not be published. Required fields are marked *