Or, how to grok vi.
The depth and breadth of functionality in Vim (or evil-mode in Emacs) can be daunting at first glance, but breaking normal mode edit commands down into orthogonal, composable elements (movements, operators, text objects, and counts) reveals a simple and intuitive syntax structure. ex
functionality in command-line mode (i.e. :
commands) represents a whole other world that isn't covered here.
These lists are by no means exhaustive, but when taken together they can provide very efficient (if not the most efficient) means of achieving frequently-required functionality.
gg
End of document - G
T
M
Bottom (__L__ow) of screen - L
a
The beginning of the line containing the mark named 'a' - 'a
0
h
l
Last character on the line - $
k
Next line - j
Next beginning of word - w
...word | ...sentence | ...paragraph | |
---|---|---|---|
Previous beginning of... | b |
( |
{ |
Next end of... | e |
) |
} |
Fs
Next in-line search hit for character 's' - Fs
Ts
Character before next in-line search hit for character 's' - Ts
?searchterm
Next in-document search hit for "searchterm" - \searchterm
Most operators need something to operate on: either the space between the cursor and the destination of a movement (see above), or a text object (see below).
Action | Operator symbol |
---|---|
Change (delete + insert something new) | c |
Delete (cut to register) | d |
Yank (copy to register) | y |
Put (paste from register) | p |
Indent | > |
Reverse Indent | < |
A text object represents the innermost meaningful grouping of document text that contains the cursor, pre-qualified with either a
("a...", "all the...") or i
("__i__nside"):
select a... | select __i__nside a... | |
---|---|---|
__w__ord | aw |
iw |
__s__entence | as |
is |
__p__aragraph | ap |
ip |
HTML/XML __t__ag | at |
it |
(...) | a( , a) |
i( , i) |
[...] | a[ , a] |
i[ , i] |
{...} | a{ , a} |
i{ , i} |
<...> | a< , a> |
i< , i> |
"..." | a" |
i" |
'...' | a' |
i' |
`...` | a` |
i` |
Operators, text objects, and many movements can be prefixed by integers to indicate that the operation/movement should occur a certain number of times, or the n-th smallest surrounding text object should be selected.
Apply an operator between the cursor and a movement destination: {operator}{movement}
For example:
dk
ce
(cw
does this as a special case too)yfq
d3l
Apply an operator to a text object: {operator}{textobject}
For example:
daw
yas
>ap
y3i(