Home  >  Article  >  php教程  >  Memorize common Vim commands and get twice the result with half the effort in Linux programming

Memorize common Vim commands and get twice the result with half the effort in Linux programming

高洛峰
高洛峰Original
2016-11-23 11:33:531389browse

People who want to program in Linux must use vim. Vim is the most commonly used editor in Linux today, so... If you memorize Vim's common commands, Linux programming will get twice the result with half the effort. The common commands of vim are listed below:


i → Insert mode, press ESC to return to Normal mode.
x → Delete a character where the current cursor is.
:wq → Save + exit (:w save, :q exit) (Chen Hao’s note: :w can be followed by the file name)
dd → delete the current line and save the deleted line to the clipboard
d (delete )
v (visual selection)
gU (change to uppercase)
gu (change to lowercase)
a → insert after the cursor
o → insert a new line after the current line
O → insert a new line before the current line
cw → Replace the characters from the cursor position to the end of a word

2dd → ​​Delete 2 lines
3p → Paste the text 3 times

NG → Go to the Nth line (Chen Hao's note: Note that the G in the command is capitalized, In addition, I usually use: N to the Nth line, such as: 137 to the 137th line)
gg → to the first line. (Chen Hao's note: equivalent to 1G, or :1)
G → Go to the last line.
Move by word:
w → to the beginning of the next word.
e → to the end of the next word.
> If you think words are written by default, use lowercase e and w. By default, a word consists of letters, numbers and underscores

Move the cursor on the current line: 0 ^ $ f F t T , ;
0 → to the beginning of the line
^ → to the first non-blank character of the line
$ → to the end of the line
g_ → to the last position of the line that is not a blank character.
fa → Go to the next character of a, you can also fs to the next character of s.
t, → to the first character before the comma. Commas can be changed to other characters.
3fa → Find the third occurrence of a in the current line.
F and T → are the same as f and t, but in opposite directions.

0 → Go to the beginning of the line first
y → Start copying from here
$ → Copy to the last character of this line
You can enter ye to copy from the current position to the last character of this word.

You can also enter y2/foo to copy the string between 2 "foo".

There are still many times where you don’t necessarily have to press y to copy. The following command will also be copied:

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn