Advanced usage of vim

Advanced vim usage

vim is one of the two most popular text editors in the world

#vim file ##Write file content
directly
# vim #:wq file
#:wq! file Force exit to save
Insert picture description here

#vim mode:
command mode (browsing mode)##This mode can only browse the content of the file
##Set the working mode of vim
##Cannot modify the file content
Insert mode## Modify the file content mode
Insert picture description here

Exit mode##End the instructions used by the vim program
Press to enter the exit mode
Insert picture description here

vimtutor ##vim Manual
##vim command to open the vim program and enter in the program: help

###二.vim working basic configuration### #How
to change vim working mode in command mode
Method: ##Temporary setting
: set nu
#Display line number : set nonu #Do not display line number
: set mouse= a
#The mouse is available : set cursorline #Display the route of the cursor line
Method: ##Permanent setting
vim /etc/vimrc ##vim configuration file for all user
Insert picture description here
wq exit and save
Insert picture description here

vim ~/.vimrc ##for user only

###三. Search###

/Keywords##Highlight keywords
: noh ##Cancel highlight
n ##Down matching keywords
N ##Up matching keywords
Insert picture description here
Insert picture description here

###四.Character management in vim ###
#copy#
y ##copy shortcut
yl ##copy a letter
y3l ##copy three letters
yw ##copy a word
y3w ##copy three words
yy #
#Copy row y3y ##Copy three rows

#Delete#
d ##delete shortcut key
dl|x ##delete a letter
d3l ##delete three letters
dw ##delete a word
d3w ##delete three words
dd ##delete one line
d3d ##delete three lines

Cut # #
C shear ##
cl ## cut a letter
c3l ## cut three-letter
cw ## cut a word
c3w ## Cut three words
cc ## to cut a line
c3c ## Cut 3 rows

"Note: After the cut operation is completed, it will enter the insert mode.
" If you want to paste, you need to press to exit the insert mode.

# Paste#
p ## In command mode p means paste

#Restore#
u ##Restore

#Cancel#

+ ##Cancel
Demonstration operation: d3d (input in command mode)
Insert picture description here
Insert picture description here
Note: In addition to the pasting of the above commands, other commands need to be performed in input mode

###五.vim Visualization Mode###
+ ##Enter the visualization mode and exit the visualization mode.
Add characters in batches:
1.+Select the column where the inserted character is located
2. Press uppercase to enter the insert mode
3. Insert the character to be written
4. Exit insert mode
Note: The result of the entire insert can only be viewed after Esc exits
eg: Demo
Insert picture description here
Insert picture description here
Insert picture description here

###六.Batch modification of characters ###
: %s/original character/replacement character/g ##% line of the full text, g column 1,
5s/ of the full text : /##/g ##1, 5 lines : Replace
/lp/ with ## , /halt/s/: /##/g ##lp to halt lp character to halt character
in the search process can not omit s
Insert picture description here

###七.vim's split screen function###

Synchronous split screen
+ ##Up and down split screen
+ ##Left and right split screen
+ <Up|Down|Left|Right> ##Cursor movement
+ ##Cancel split screen

Insert picture description here

Different without split screen
: sp file name##Enter in the command interface of vim: sp file name to open this file

vim -o file1 file2 #u|d up and down split screen
vim -p file1 file2 #l|r :tabn —next tabp:—prev
## left and right split screen

###八.wim中 quickly locate the cursor###
gg #Move the cursor to the beginning of a line in the file
G ##Move the cursor to the last line
: Number##Move the cursor to the last line
Note: The above commands must be in vim command mode get on

###九.Quickly locate the cursor in vim##
i ##Insert
I at the cursor position ##Insert
A at the beginning of the line
where the cursor is ## Insert the end of the line where the cursor is a ## Insert the next character of the character where the cursor is
o ##Insert the next line of the line
where the cursor is O ## Insert the previous line of the line
where the cursor is s ##Delete the character where the cursor is and insert
S ##Delete the line where the cursor is and insert

##十. vim exit mode###
:wq ##Save and exit
: wq! ##Forced to save and exit, only the file is available to you or root user
: q ##Exit
: q! ##Forced to exit without saving

##########
##test####
##########
Find a character
in the file /usr/share/xml/iso-codes/iso_639_3.xml Find all that contains Line of character ng

When shielding the output, import the file information to /dev/null (#Empty device file, equivalent to a write-only file)

Guess you like

Origin blog.csdn.net/Antonhu/article/details/112852128