Source

Using Vim abbreviations

Guilherme Quental
Dev Ticks

--

Recently I’ve discovered a really great feature of VIM that allows us to use abbreviations in our text.

What does that mean indeed? It’s like a text expand functionality within Vim. A function that we could leverage for a lot of things.

There are two ways that we could use it, first, by using a command like this one: :iabbrev tets test

If we open Vim, execute this line and start typing in edit mode the following text: This is a tets, the last word will be replaced by the one that we configured in the command previously, so tets will now be test.

By leveraging that feature, we could do a lot of things in our configuration, such as the creation of our snippets. Let us imagine that we wanted to create an abbreviation where we would write r@@ and Vim would transform it into a text with our name and mail information, how we would do that? We need to add the code below to our .vimrc file in the first place.

As you can imagine, this config will make Vim replace r@@ every time with the text:

My name is Guilherme Quental
You can email me here: guilherme@quent.al

Please notice the <cr> within the text. This is a special identifier that will be replaced by a Carriage Return (Enter), which will render a new line.

I can see many uses for it in my workflow; I hope this could also be useful to you.

If you liked this article, please click on ❤ to share it, so more people will be able to see it on Medium. Thanks!

--

--