https://danielmiessler.com/study/vim/
Verbs are the actions we take, and they can be performed on nouns. Here are some examples:
d
: delete
c
: change
y
: yank (copy)
v
: visually select (V for line vs. character)
Modifiers are used before nouns to describe the way in which you’re going to do something. Some examples:
i
: inside
a
: around
NUM
: number (e.g.: 1, 2, 10)
t
: searches for something and stops before it
f
: searches for that thing and lands on it
/
: find a string (literal or regex)
In English, nouns are objects you do something to. They are objects. With vim it’s the same. Here are some vim nouns:
w
: word
s
: sentence
)
: sentence (another way of doing it)
p
: paragraph
}
: paragraph (another way of doing it)
t
: tag (think HTML/XML)
b
: block (think programming)
/{string}
: search for string
t
: jump up to a character
f
: jump onto a character
*
: search for other instances of the word under your cursor
n
: go to the next instance when you’ve searched for a string
N
: go to the previous instance when you’ve searched for a string
;
: go to the next instance when you’ve jumped to a character
,
: go to the previous instance when you’ve jumped to a character
You can easily move within the line you’re on.
0
: move to the beginning of the line
$
: move to the end of the line
^
: move to the first non-blank character in the line
t"
: jump to right before the next quotes
f"
: jump and land on the next quotes
[ NOTE: , and ; will repeat the previous t and f jumps. ]
You can also move by word:
w
: move forward one word
b
: move back one word
e
: move to the end of your word
When you use uppercase you ignore some delimiters within a string that may break it into two words.
W
: move forward one big word
B
: move back one big word
This uppercasing of a given command having different and more powerful effects is something we’ll see frequently.
j
: move down one line
k
: move up one line
h
: move left one character
l
: move right one character
0
: move to the beginning of the line
$
: move to the end of the line
w
: move forward one word
b
: move back one word
e
: move to the end of your word
)
: move forward one sentence
}
: move forward one paragraph
:line_number
: move to a given line number
H
: move to the top of the screen
M
: move to the middle of the screen
L
: move to the bottom of the screen
^E
: scroll up one line
^Y
: scroll down one line
gg
: go to the top of the file
G
: go to the bottom of the file
^U
: move up half a page
^D
: move down half a page
^F
: move down a page
^B
: move up a page
Ctrl-i
: jump to your previous navigation location
Ctrl-o
: jump back to where you were
[ NOTE: I map my CAPSLOCK to Ctrl so I can use it for these various Ctrl-based movements, among other things. ]
Bang!
Vim also allows you to execute a command directly from the editor, without needing to drop to a shell, by using bang (!) followed by the command to be run. For instance, if you're editing a file in Vim and want to find out how many words are in the file, run
:! wc %
This tells Vim to run the file (%) through the wc utility and report the results. Vim will display the command output at the bottom of the editing window until you press Enter. Note that this command runs the file through the command, and not the contents of the buffer -- so if you haven't saved recently, it won't report your most recent word count.
Bang works best with non-interactive commands. You wouldn't want to run top or another interactive command using :! command, but you could drop to a shell and run such a command with :sh or Ctrl-z.
The bang command can be useful if you're using Vim for programming. If you're writing a PHP script, for example, you could use PHP's syntax check option (-l) to see if your script has any syntax errors:
:! php5 -l %