Summary of common Vim commands

directory

  • 1. Move the cursor
  • 2. Basic editing
  • 3. Find and replace
  • State of 4.

1. Move the cursor

The command function
lorRight Move one character to the right
horLeft Move one character to the left
jorDown Move down one line
korUp Move up one row
0 Moves to the start of the current row
[[ Move to the beginning of the code block
] [ Move to the end of the code block
^ Moves to the first non-null character of the current line
$ Moves to the end of the current line
A Moves to the end of the current line
w Move to the beginning of the next word or punctuation mark
W Move to the beginning of the next word, ignoring punctuation
b Move to the beginning of the previous word or punctuation mark
B Move to the beginning of the previous word, ignoring punctuation
Ctrl-forPgDown Turn the next page
Ctrl-borPgUp Turn the page up
12G Move to line number. For example, 12G moves to line 12 of the file
GG Move to the end of the file
gg Move to the bottom of the file

2. Basic editing

  • Add and undo text
The command function
i Inserts text before the cursor
a Inserts text after the cursor
o Opens a line below the current line
O Opens a line above the current line
u undo
ctrl + r redo
  • Delete the text
The command function
x Delete current character
3x Deletes the current character and the following two characters
dd Delete current row
5dd Deletes the current line and the following four lines of text
dW Delete from cursor position to the beginning of the next word
d$ Deletes lines from cursor position to the end of the current line
do Deletes the start of a line from the cursor position to the current line
d^ The first non-null character from the cursor position to the line of text
dG From current line to end of file
d20G From the current line to line 20 of the file
  • Copy the text
The command function
yy Copy the current row
5yy Copies the current line and the following four lines of text
yW Copy from the current cursor position to the beginning of the next word
y$ Copies from the current cursor position to the end of the current line
y0 Copy from the current cursor position to the beginning of the line
y^ Copies the first non-null character from the current cursor position to the line of text
yG Copy from the current line to the end of the file
y20G Copy from the current line to line 20 of the file
  • Paste the text
The command function
p Paste below the current line
P Paste it above the current line

3. Find and replace

The command function
:%s/Line/line/gc Change the word “Line” to “Line” in the entire file, requiring user confirmation
: The colon character runs an ex command
% Specifies the number of rows to operate on. % indicates from the first line to the last line; And 1,$means from the first line to the last line of the file. If the range of text lines is omitted, the action only applies to the current line
s Specify actions. In this case, replace (find and replace)
/Line/line Find type and alternative text
g Globally, find and replace all matching strings in the text line. If g is omitted, only the first matching string in each line of text is replaced.
c If c is omitted, you can directly replace the command that requires user confirmation

Replace with Line (y/ N/A /q/ L /^E/^Y)? , the user performs further processing

The command function
y Perform a replacement
n Skip the matching instance
a Replace this and all subsequent matching strings
Q or ESC Exit the replacement operation
l Perform this substitution and exit. L is short for “last”
Ctrl-eorCtrl-y Scroll down and up to see the context of the proposed replacement

State of 4.

The command function
ctrl + g Current line information
g + ctrl + g Word count