Linux text editor Vim/Vi


Text editor Vim/Vi

1. Introduction to Vim/Vi

(1), Vim/Vi is a powerful full-screen text editor and the most commonly used file editor on Linux/UNIX

(2), Vim/Vi has no menu, only commands

insert image description here

2. Insert command

Order effect
a Append text after cursor
A Append text at the end of this line
i insert text before cursor
I Insert text starting on this line
o Insert a new line under the cursor
O Insert a new line at the cursor

3. Positioning command

Order effect
h or arrow left move left one character
j or down arrow key move down one line
k or up arrow key move up one row
l or right arrow move right one character
$ move to end of line
0 move to beginning of line
H move to top of screen
M move to center of screen
L move to bottom of screen
: set no set line number
: set nine cancel line number
gg to the first line
G to the last line
Mr to line n
: n to line n

4. Delete command

Order effect
x Delete the character where the cursor is
nx Delete n characters after the cursor position
dd Delete the line where the cursor is located, ndd deletes n lines
dG Delete the content from the line where the cursor is to the end
D Delete from the cursor position to the end of the line
:n1,n2d Delete the specified range of rows

5. Copy and cut commands

Order effect
yy or Y copy current line
nyy 或nY Copy the current line for n lines
dd cut current line
n.d Cut n lines below the current line
p or p Paste below or above the line where the cursor is currently located

6. Replace and cancel commands

Order effect
r Replace the character under the cursor
R Replace characters from the cursor position, press Esc to end
u cancel previous operation

7. Search and replace commands

Order effect
/string Search forward for the specified string, ignoring case when searching: set ic
n Searches for the next occurrence of the specified string
:%s/old/new/g Replace the specified string with the full text
:n1,n2s/old/new/g Replace the specified string within a certain range

8. Save and exit commands

Order effect
:w Save changes
:w new_filename Save as specified file
:wq save changes and exit
ZZ Shortcut key, save changes and exit
:q! Exit without saving changes
:wq! Save changes and exit (the file owner can ignore the read-only attribute of the file)

9. Application examples

(1) Import command execution result: r ! command

(2), define shortcut keys: map shortcut keys trigger commands

:map ^P I#<esc>
:map ^B Ox

(3), continuous line comments

:n1,n2s/^/#/g
:n1,n2s/^#//g
:n1,n2s/^/\/\//g

(4), replace

:ab sammail samlee@lampbrother.net

Guess you like

Origin blog.csdn.net/qq_45138120/article/details/126234760