The use of linux vim editor

The use of linux vim editor

First of all, we need to understand the three modes of vim commands
1. Edit mode
2. Command mode
3. Last line mode

The use of vim commands: vim file name or file full path name
path:
Insert picture description here if you are in the current directory, you can use it directly : Vim file name
Insert picture description here

If there is the file, open the file.
If not, create a new file. After
entering vim index.html, we can see the contents of the file, but we can’t edit it yet because it’s currently in command line mode.

Insert picture description here
There are the following operations in the command line mode (to be straightforward and often used):

Press the keyboard: Home key: move the cursor to the
beginning of the current line Press the keyboard: End key: move the cursor to the end of the current line
G: move the cursor to the last line of the entire document
gg: move the cursor to the entire document first line
PgUp: page up
PgDn: down
n + enter: n lines move downward
example: in the first row I, I want to move the cursor down line 10;
I: enter the edit mode
esc: Cancel Edit mode
u: undo
v: select text|visual copy| delete (use with the up, down, left, and right keys of the keyboard)

I can press 10 and press Enter to move the cursor down 10 lines

Copy operation

y: copy
yy: copy the current line
n yy: copy n lines down (press 8 and then press yy: copy 8 lines down)

Delete/cut/paste operations

x: delete a character before the cursor
dd: delete the line where the cursor is
p: paste
n dd: delete n lines down (including the current line where the cursor is)
such as: I press 5, and then press dd to delete the five lines under the cursor ( Including the line where the cursor is located)
D: Delete the content after the current line where the cursor is located

Undo/redo operation

u: cancel
ctrl+r: restore
and then edit mode
Insert picture description here

Next is the last line mode. In
English, shift +; key to enter the last line mode is:

w: save the file
save to the specified location: w the path to be saved
wq: save the file and exit
q: exit (do not save the file)
x: save and exit if modified, and exit directly without modification (note lowercase)
if not Be careful to press the uppercase letter (that is to encrypt the file, if you don't understand, it is recommended not to encrypt, otherwise there will be problems in some cases)
q!: Force exit without saving
Execute external command:! External command
Search key content: / Keyword to search

Replace operation in the last line mode Replace
all matched content: %/Content to be replaced/New content/g
Replace the first matched content in the current line: s/Content to be replaced/New content
replace all content in the current line: s/Content to be replaced/New content/gReplace
the first matching content in each line: %s/Content to be replaced/New content

Display line number: set nu
Cancel display line number: set nonu

Alias ​​mechanism:

What is the alias mechanism, which is equivalent to customizing our own commands. For
example, we need to edit the network configuration file, but that command is very long and difficult to input. We can use the alias mechanism to customize a command and edit it directly.
Use: vim ~/.bashrc to enter this
folder. The content of the folder is like this. For
Insert picture description here
Insert picture description hereexample, under windows system, we use cls to clear the screen
. We can’t under linux. We can do this as much as
Insert picture description here
I know, but master With these, there will be no big problems in using the vim editor, and it can basically meet the basic use. If you don’t understand, you can use Baidu or other ways to understand the use of the vim editor.

Guess you like

Origin blog.csdn.net/m0_46188681/article/details/109609300