Vim operation study notes

01 Four modes

  • Normal-mode: Esc or ctrl+[
  • Insert-mode: i
  • Command-mode : : or /
  • Visual-mode: v or V or ctrl+v

02 Open the file

vim file
open multiple files at the same time
vim file1 file2

The screen displays the first file by default, which is file1, how to switch between files? In the normal mode of VIM (refer to the description of the normal mode above), press the colon on the keyboard: a colon will appear at the bottom of the display: (enter the command mode of VIM), and then enter ls, the screen will appear The sequence numbers and file names of all the files that are opened, we continue to enter the colon: , and then enter bn (the n here needs an explanation, not the n on the keyboard, but the file sequence number, such as b1 means switching to on the display screen the first file, b2 represents switching to the second file on the display).

vim split screen

Split screen left and right as follows:

vim -On file1 file2 ... filen
The n here (n is the number of specific files to be opened: 1,2,3...) means that there are several files that need to be split-screen, and n files are displayed in sequence from left to right.

The upper and lower split screens are operated as follows:
vim -on file1 file2 … filen

The difference between this command and the previous command is that the parameter -on (n is the number of specific files to be opened: 1,2,3...) in o is lowercase, so that n files will be displayed up and down in sequence.

edit operation

I Insert at the beginning
of the line A Insert at the end of
the line: set nu Display the line number
: set nonu Cancel the line number
: n1,n2d Delete multiple lines of text: n1 and n2 refer to the start line number and end line number, d is the delete keyword

cursor operation

Several important shortcut keys

Please remember these shortcut keys h, j, k, l These keys are mainly used to move the cursor quickly, h is to move the cursor to the left, l is to move the cursor to the right, j is to move the cursor down, k It is to move the cursor up, h , j , k , l can completely replace the functions of ↑ , ↓ , ← , → on the keyboard in the main keyboard area.

move the cursor on the current line

0 moves to the beginning of the line

^ move to the first non-blank character on the line

$ move to end of line

g_ Move to the last position of the line that is not a blank character

w cursor moves to the beginning of the next word

e cursor moves to the end of the next word

fa moves to the next character of a in this line, fb moves to the next character of b

nfa Move to the place where the nth character starting from the cursor in this line is a (n is 1, 2, 3, 4 ... numbers)

Fa is the same as fa, the cursor moves in the opposite direction to fa

nFa is similar to nfa, and the cursor moves in the opposite direction to nfa

ta moves the cursor to the previous character of a character

nta move to the character before the second a character

Ta moves the cursor in the opposite direction to ta

nTa moves the cursor in the opposite direction to nta

; and, when using f, F, t, T, keywords to specify character jumps, use ; to quickly jump to the next specified character, , is to jump to the previous specified character

References:
https://zhuanlan.zhihu.com/p/68111471

Guess you like

Origin blog.csdn.net/NGUever15/article/details/132337215