Vim: Motions

See :help motion.txt for a complete listing of motions that Vim supports.

Operators

Motions can be used for navigating a codebase, but are most powerful when combined with operators that act on motions. The syntax is [count]<operator>[count]<motion>. The canonical example would be to use d2w to delete two words from the current cursor location. Common operators are

Operators can also be applied to text-objects like matching quotes, parentheses, braces, words, sentences, etc. For example, diw deletes the word under the cursor without having to move the cursor to the beginning of the word with bde.

vim-surround also works nicely with text objects and motions. For example, ys2w' surrounds the next two words (from the current cursor) with single quotes.

Motions

Left-right motions

The common motions I use to navigate the current line are

Up-down motions

Word motions

For lowercase word motions, words are defined as a sequence of leters, digits, and underscores. For uppercase WORD motions, words are separated by whitespace.

Text object motions

See text-objects for details. Some text objects can provide motions (paragraphs and sentences)

Some languages have ftplugins that define sections for its particular syntax, so the ]]-style motions can work for non-C-style languages.

I haven't found the ]] motions reliable, but that could be because I haven't used them much.

Various motions

Note that % is a bit funky in HTML. If your cursor is on top of a < or >, it will go to the matching bracket. If the cursor is inside the tag, % will go to the matching tag. For lists, % will cycle through the list items.

Also note that matchit doesn't support Python, because of the language syntax. python_match exists, but I haven't used it.