Vim Spells

Movement

Spacing

Convert tabs to spaces

assumes expandtab is on

:retab

Strip trailing whitespace

:%s/\s\+$//e

Buffers

Close all open buffers

:%bd

Splits

Creating them

:sp (horizontal split)
:vsp (vertical split)

Jumping around them

CTRL-<hjkl> (movement keys)
<LEADER>-<hjkl>

Open a split with a specific file

:sp filename
:vsp filename

Scratch space

Uppercase a word

gUiw

Sort lines

Highlight the lines you want to sort, and then execute :sort

Format text

Vim lets you run any command line tool on a buffer/ selection of text via the following format, where range is the selection of text, and filter is the command to run. The output of the command, when fed the filter, replaces the selection:

:{range}!{filter}

JSON formatting

Requires that the jq command is installed. % references the current buffer.

%!jq

Execute command on range

So, for example, to delete the last character of every line in the buffer, run:

:%normal $x

Execute command on multiple lines

The g command is the "global" command to execute other commands. In this case, you can use it with the norm command to perform a change on lines that match a specific pattern (or all lines).

For example, if you want to add a semicolon to the end of all lines that start with a number, you could do that as follows:

:g/^\d/norm A;

In this case, instead of substituting the line for something else, you are telling Vim to execute the "normal mode" command of moving to the end of the line and entering insert mode (with A), and then adding a semicolon.

This is pretty powerful because you have the ability to perform a motion on all the lines matching a specific pattern.

Visual select and insert

CTRL-v

Once you have selected the block you want, you can edit all of the selected lines at once with:

SHIFT-i (insert whatever you want) <ESC>