Common operating commands in VIM

1、复制

1)单行复制
在命令模式下,将光标移动到将要复制的行处,按“yy”进行复制;
2)多行复制 在命令模式下,将光标移动到将要复制的首行处,按“nyy”复制n行;其中n为1、2、3……

[
Yy] Copy the line where the cursor is located [nyy] Copy the downward n line where the cursor is located

2、粘贴
在命令模式下,将光标移动到将要粘贴的行处,按“p”进行粘贴
[P,P] p is to paste the copied data on the line below the cursor; P is to paste the copied data on the line above the cursor

3. Delete
Delete a line: dd
delete a word/the remaining part of the word after the cursor: dw
delete the current character:
the part of the line after the x cursor: d$

Text delete
dd delete a line
d$ delete a line of characters beginning with the current character
ndd delete n lines beginning with the current line
dw delete a word
beginning with the current character ndw delete n words beginning with the current character

4. Search
[/word] Search for a character string with word content in the file (search downward)
[?word] Search for a character string with word content in the file (search upward)
[[n]] Indicates repeated search action, That is to find the next one
[[N]] Find the next one in reverse.
After searching, we opened other files and found that they were also highlighted. How to turn off the highlighting?
In command mode, input: nohlsearch can also be: set nohlsearch; of course, it can be abbreviated, noh or set noh.

5. Set the line number
If you want to display the line number after editing, press the esc key in the same operation, and enter: (colon), enter the set number, and press the enter key, and the line number will be displayed after completion

6. Jump to the specified line

When you know the specific location of the content you are looking for in the file, you can use the following command to directly locate:
Jump to the specified line of the file: For example, jump to line
66 66+G (that is, 66+shift+g)
Of course you can choose another Jump method:
input ": n" from the command line and press Enter
to jump to the first line of the file: gg (two lowercase G)
jump to the last line of the file: shift+g (that is, G)
7. File flip up and down,
page flip can be used directly PgUp and PgDn
to scroll a screen forward: Ctrl + F
backward scrolling a screen: Ctrl + B
roll forward half screen: Ctrl + D (down)
to scroll backward half-screen: Ctrl + U (up)
to Scroll down one line, keep the current cursor still: Ctrl+E
Scroll up one line, keep the current cursor still: Ctrl+Y

Current line scrolling:
Move the current line to the top of the screen and scroll: Z+Enter to
scroll the specified line to the top of the screen: 10Z+Enter (specify the tenth line)
Move the current line to the center of the screen and scroll: Z +.
Move the current line to the bottom of the screen And scroll: Z +
-Current screen operation:
H: uppercase h, move to the first line of the current screen; nH move to the nth line under the first line
M: uppercase m, move to the middle line of the current screen
L: uppercase l, move to The last line of the current screen; nL moves to the nth line above the last line
8. Undo the last operation
[u] Undo the last operation
[[Ctrl] + r] Undo multiple times
[.] This is the decimal point key, repeat the last operation

  Indentation: In
  insert mode, ctrl+shift+d decreases indentation, ctrl+shift+t increases indentation

9. Vim editing
1. Enter insert mode (6 commands)
[i] Insert from the current cursor position
[I] From the current cursor
[a] Insert from the next character of the current cursor
[A] From the line where the cursor is Start inserting
[o] English lowercase letter o at the last character of the cursor, insert a new line and start inserting
[O] English capital letter O, insert a new line above the current cursor line And start inserting

 2. Enter the replacement mode (2 commands)
[r] Only replace the character where the cursor is located once
[R] Will replace the character where the cursor is until the [ESC] key is pressed
[[ESC]] Exit the edit mode and return To normal mode

  3. Switch to the command line mode from the general mode
[:w] Save the file
[:w!] If the file is read-only, force the file to be saved
[:q] Leave vi
[:q!] Force to leave vi without saving
[:wq] Save Exit after
[:wq!] Force save and exit
[:! command] Temporarily leave vi to the command line to execute a command after the display result
[:set nu] Display line number
[:set nonu] Cancel display line number
[:w newfile] Save as
[:set fileencoding] View the current file encoding format
[:set fileencoding=utf-8] Set the current file encoding format to utf-8, or other encoding formats
[:set fileformat] View line breaks in the current file Format (dos\windows, unix or macintosh)
[:set fileformat=unix] Set the line breaking format of the current file to unix format

10. Multi-window function
[:sp [filename]] Open a new window and display the new file. If only input :sp, the same file will be displayed in both windows
[[Ctrl] + w + j] Move the cursor to the lower window
[[ Ctrl] + w + k] Move the cursor to the upper window
[[Ctrl] + w + q] Leave the current window

11. Indent and
batch indent
In the program code interface, press esc to exit the edit mode, go to the command mode, and enter ":" in the English input method to
write the line number to be indented in batches, according to the format: "line number 1. Enter the command line number 2>". If you want to indent 2-9 lines by one tab value, the command will be "2,9>".
After inputting, press Enter to execute, and you can see 2-9 All lines are indented by one tab value. Similarly, if you want to retract a tab value, use the command "line number 1, line number 2<".

The
second method of visual mode indentation is to select the column to be moved in visual mode. The operation is, esc exits from edit mode to command mode, moves the cursor to the beginning of the line to be indented, and then press shift+v, you can see the row has been selected, and the lower left corner prompt for the "visual"
At this point, press the up and down arrow keys on the keyboard, such as here, press the down arrow to select the required quantities of all lines indented
selected after a good , Press shift+> to indent a tab value forward, press shift+< to retract a tab value,

supplement:

1. Completion command: {ctrl+p}
2. Jump command: {Jump in file: gg (jump to the beginning), G (jump to the end), :100 (jump to a fixed line)}
3 . Search command: {*, / character. Use n and N to jump up and down. }
4. Cancel the search highlight text: {:noh}
5. Replace command: {:%s/xx/yy/gc} replace xx with yy
6. Column operation: In command mode, select the interval with the mouse and press ctrl+q, enter text,
              or in command mode, press ctrl+q, use hjkl up, down, left, and right to select the range, and then enter the text.

Guess you like

Origin blog.csdn.net/qq_33231534/article/details/104908693