Useful Vim Mappings

A few mappings to help boost your Vim workflow.

Rotate through different line numbering settings

Switch between absolute line numbers (normal), relative numbers (based on distance from your cursor) and no numbers at all using CTRL-n:

Easier git blame

Ever wonder who wrote the line of code you’re looking at? With this mapping, select a line or group of lines in Visual mode, then use “g” to run git blame on them.

Credit to Thoughtbot

Display tabs and unncessary white spaces

Hate those ugly looking Git files full of unnecessary white spaces and tabs? This mapping toggles a specified group of “listchars,” ordinarily invisible characters that you sometimes want to see:

To just leave this on, you can use:

Select all text in a buffer

Surprisingly, there’s no native mapping for this, but it’s simple enough:

Move lines up and down (à la Sublime Text)

These mappings move the current line up or down.

Toggle active buffers

To toggle quickly between active buffers, I use this mapping:

Indent in Visual mode

Use Tab and Shift-Tab to indent and unindent lines in Visual mode:

Search using normal regular expressions

By default, Vim uses its own regular expression syntax. If you want to search using PCRE (Perl-compatible regular expressions, the kind used in Ruby, Python, etc.), you can enable “very magic mode” with \v. Very magic mode isn’t exactly the same as PCRE, but is quite close. To default to very magic mode, I use the following mappings, suggested by Steve Losh:

Copy and Paste with CTRL-c and CTRL-v>

Contributions by Federico Ramirez and Kevin Litchfield
// ]]>

Leave a Reply