← All lessons

10. Make Vim Your Own With Maps

Step 5 of 6

Leader isn’t the only option

The usual advice is to use <leader> for custom-defined mappings, but it’s not the only option. There are lots of key combinations that are not bound to any built-in functionality, and you’re free to attach your mappings to any of these.

The Z key

The Z key is massively underutilised, making it a great place to make your custom maps. The only two built-in maps you need to be aware of are:

Every other key combination starting with Z is unused, so you can use Z as another prefix for your custom maps.

Tucking your maps behind an operator

In a previous lesson, we talked about Vim’s command language — recall that the general structure of a normal mode command is:

[count]{operator}{text object/motion}

Something that we didn’t mention earlier is that hitting the {operator} key (for example, d, c, or y) actually puts Vim into a special mode called operator pending mode. In this mode, Vim waits for you to input a text object or a motion (like a", ip, etc).

If the keys that you press in operator pending mode don’t correspond to a valid text object or motion, Vim simply does nothing. So, there are hundreds of empty unused maps hiding behind the operator keys!

For example: yp, du, cx, and da. are all unmapped — and there are hundreds more. You can use any of these maps without worrying about overriding built-in Vim functionality.

Loading editor…