← All lessons

10. Make Vim Your Own With Maps

Step 1 of 6

Vim is extensible

You’re not limited to just the functionality that Vim gives you. It’s really easy to tweak existing features and even create your own! By doing this, you can fix things that you find annoying about Vim, and generally “make it yours”. For some people, this is a massive selling point: the editor is infinitely customisable and you can change it however you like.

What’s more is that you don’t have to do the work of extending Vim yourself. There are already tonnes of plugins out there that add useful features to Vim without compromising on its core philosophies. Tim Pope’s plugins are exemplary in this regard: they feel like they should be built-in parts of the editor. Pope’s vim-surround plugin, for example, adds new features for working with surrounding characters like () and "" by extending Vim’s command language with a new surround operator.

One of the easiest ways that we can enhance our editing experience is by introducing custom keymaps. Vim supports this out-of-the-box. You can use map commands to change what an existing keymap does, or create an entirely new one. Vim lets you create new keymaps for all the major modes, meaning that you can extend Vim’s functionality wherever you see fit.

Let’s start by adding a simple keymap to see what’s possible. We’re going to build a new mapping for insert mode that automatically completes single quotes for us. So, when we type ', our mapping is going to automatically complete the closing quote and place our cursor in between them. This is something that modern editors have by default, so we should prove that it’s possible in Vim, right?

Here’s the command you need:

:inoremap ' ''<left>

Try that in the editor, then in insert mode, try typing a single quote and watch what happens!

Loading editor…