VIM is a powerful text editor that is often used to process text files. The following are common text processing commands in VIM:
- Insert text:
Press the key in Normal modei
to enter Insert mode, and you can start inserting text at the current cursor position. PressEsc
the key to return to Normal mode. - Save the file:
Press the key in Normal mode:
, then enterwq
. PressEnter
the key to save the file and exit VIM. If you just want to save the file without exiting, you can enterw
. - Undo operation:
Press the key in Normal modeu
to undo the previous operation. - Copy, cut and paste:
Use in Normal modeyy
to copy the current line, usedd
to cut the current line, and use top
paste the copied or cut text at the current cursor position. - Move the cursor:
In Normal mode, useh
,j
,k
andl
to move the cursor left, down, up, and right respectively. You can also use the arrow keys to move. - Find and Replace:
Press in Normal mode/
, then enter the text you want to find, pressEnter
the key to start searching. Use to replace:%s/old/new/g
the entire file with .old
new
- Delete text:
Use in Normal mode tox
delete the character at the cursor position, and use todd
delete the current line. Used
commands that move the cursor (for exampledw
,de
) to delete text from the current position to the specified position. - Visualization mode:
Press the key in Normal modev
to enter visualization mode, where you can select text. PressV
to enter line visualization mode and select an entire line of text. Press againV
to enter block visualization mode and select block text. - Undo and redo:
Press in Normal modeu
to undo the previous operation, pressCtrl+r
to redo the undone operation.
The above are common text processing commands in VIM. VIM has rich functions and commands that can process text files efficiently. For beginners, it may take some time to become familiar with the operation of VIM, but once you are familiar with the basic commands, your text editing efficiency will be greatly improved.