Table of contents
1. The basic operation of gvim
1. The basic operation of gvim
The following operations are all carried out in command mode, and a colon is required to enter the last line mode during the operation, which is generally used to edit the content of the entire document or the document. Entering certain commands (for example: i, a, o) can enter the mode of editing the document, called insert mode.
1. Insert character
Order | result |
i(I) | Enter insert mode, the cursor appears before the character (beginning of the paragraph) |
a(A) | Enter insert mode, the cursor appears after the character (end of paragraph) |
the(the) | Enter insert mode, start a new line below (above) the cursor position |
The difference between i and a:
Memory: OP, paragraph, paragraph. add is added at the back, insert is the opposite of add, and added at the front
Supplement: If the code has been aligned according to the format, then you need to insert characters in the middle of the line when modifying. At this time, you can use R, capital R to replace, and then enter the character, so that the following characters will not move. Press esc to exit after the input, so as to prevent the aligned text from being moved.
2. Move cursor or page
Order | result | memory |
move a character | ||
h/j/k/l | Move one character position to the left/down/up/right of the cursor | h, l are in the left and right positions respectively, so it is left and right, h and j together record the lower left corner, j and k together record the upper right corner, so j and k are respectively down and up |
move a word | ||
w(W) | Cursor moves to the beginning of the next word | word |
and and) |
Cursor moves to the end of the next word | word end |
b(B) | Move the cursor to the beginning of the previous word | back to the previous word |
move a line (paragraph) | ||
shift + ^ | move the cursor to the beginning of the line | |
shift + $ | move the cursor to the end of the line | |
{( } ) | Move the cursor to the previous paragraph (next paragraph) (Blank paragraphs with blank lines, see blockquotes) |
|
gg( [[ ) | Move the cursor to the first line of the document | |
G( ]] ) | Move the cursor to the last line of the document | |
Move pages (turn pages) | ||
crtl+F/f |
page down | spelling of fan |
ctrl+B/b | page up | back back to the previous page |
Movement of paragraphs in gvim:
Gvim considers the part separated by blank lines as a paragraph
3. Find content
Order | result |
:/abc | Find abc in the document, use n/N to jump the cursor to the next/previous searched object |
shift+* | Directly search for the word at the position of the cursor, and use n/N to jump the cursor to the next/previous searched object |
:noh | Unhighlight the highlighted search results |
4. replace
Order | result |
r(R) | Replacement of the character where the cursor is located (enter the replacement mode for continuous replacement, Esc to exit) |
:%s/a/b/g | Replace global a with b |
:%s/a/b/gc | Replace the global a with b, each replacement needs to be confirmed |
:1,30s/a/b/g | Replace a in lines 1 to 30 with b |
:,30s/a/b/g | Replace a from the cursor position to line 30 with b |
5. Delete text
Order | result |
x(X) | Delete the character at the cursor position (delete the character before the cursor) |
s(S) | Delete the character at the position of the cursor (delete the entire content of the line and keep the line), and enter the insert mode |
d(D) | d is generally used in combination with other keys (delete the entire content of the line and keep the line, but do not enter the insert mode) |
dd | Delete row, row content and row are all deleted |
dw | delete the word under the cursor |
The difference between x and X:
Supplement: After completing the alignment of the code, if you need to delete the middle part, you can replace it with r, and then press space, and you can complete the deletion without moving the character position behind.
Note: Any deleted text will be placed on the clipboard, which means that the subsequent operation will continue to p, and the deleted content can be pasted.
6. Copy and paste
Order | result |
y | copy selected text |
yy | Copy the text of the line where the cursor is |
p(P) | Paste the copied text after the cursor (before the cursor) |
Note: When the text is selected for pasting, it will be pasted at the position of the cursor, and when n lines are selected for pasting, it will be pasted at the position of the cursor for n new lines.
7. Operations on files
Order | result |
File saving and opening | |
:w | keep |
:wq | Quit after saving (q to quit and q! to force quit are generally not used) |
:e myfile | Close the file and open a file named myfile |
:e. | Close the file, open the directory, and press R in the directory window to refresh the directory |
:new | Do not close the file, open a new file in split screen, unnamed |
split screen operation | |
:sp | Open a new window horizontally, split |
:vsp | Open a new window vertically, vertical split |
ctrl+ww | Switch between split screen windows |
Path jump (check path) | |
gf | When the cursor is on the path, jump to the folder (or file) corresponding to the path |
ctrl+o | Return to the file before the jump |
8. Multi-line editing
Multi-line editing is used to delete or insert characters in batches, ctrl+v enters the visual editing mode, select multiple lines through j and k (or arrow keys), press shift+i (or I) to enter insert mode to edit a single line, and then Esc to exit, you can reproduce the edited content in the selected multiple lines.
Note: Validity of multi-line editing
9. Select text
Order | result |
v | Enter the selection mode, often used to select characters |
Visual Editing Selected | Often used to select blocks in selected text |
V | Enter multi-line selection mode, you can select multiple lines |
The difference between visual block selection and pasting and multi-line selection and pasting:
V's line selection mode is often used to select multiple lines, copy and paste multiple lines, and create multiple new lines for pasting;
Multi-line editing of the selected content block will not start a new line, which is often used to paste in the blank space.
10. Combination keys
The key representing the operation can be combined with the key representing the range to realize the combination key operation
key to represent the action | a key representing a range |
d delete | ^ beginning of line |
$ end of line | |
y copy | gg first line |
G last row | |
w word |
|
Example of key combination operation | |
dw | delete word at cursor |
dgg | Delete the entire content from the cursor to the first line |
is | copy word at cursor |
y$ | Copy everything from the cursor to the end of the line |
11. Other operations
Order | result |
:ab ten hours | abstract represents an abbreviation, which can automatically replace it with timer after typing ti in insert mode and typing space (or Esc) |
u | revoke |
shift+r | restore undo |
shift+u | switch case |
ctrl+p(n) | Used in insert mode, enable autocompletion option |
q | Record macro operations (see below for detailed operations) |
subject | Open multiple tabs (see below for detailed operations) |
Open multiple tabs for easy file management
Record macro actions
Update directory: In the colon mode, press N, then type table and type NERDTree to automatically update the directory (in the working environment of the internship company)