当前位置:网站首页>Gvim/vim tips

Gvim/vim tips

2022-07-23 19:08:00 qq_ forty-four million nine hundred and eighty-five thousand si

Blog overview
stay Linux The most commonly used editor in is VIM, however VIM Use and Linux The use of is basically the same , Are based on command line operations , because VIM There are only commands without menus . that , If you want to use VIM You must remember some common commands , It's convenient for us to use VIM To the point of doing what you want . This article will summarize what we often use VIM Mode of operation , For students to learn and convenient for bloggers to review in the future .

VIM Working mode
VIM There are three working modes , Command mode , Insertion mode , Edit mode , Among them, the insertion mode is the same as that we commonly use txt There is little difference in the preparation of documents , But both command mode and edit mode are for us to be faster 、 Better documentation provides .
VIM Common commands
In command mode u Indicates to undo the latest operation .

VIM Several ways of changing from command mode to insert mode

command effect
a Insert... After the character of the cursor
A Insert... At the end of the line where the cursor is
i
I Insert... At the beginning of the line where the cursor is
o Insert a new line under the cursor
O Inserts a new line on the cursor

The above table is in VIM Several ways of changing from command mode to insert mode .

Locate the command

command effect
:set nuVIM The editor displays the line number
:set nonuVIM Cancel the display line number
gg To the first line
G To the last row
nG To the first n That's ok
:n To the first n That's ok
$ Move to the end of the line
0 Move to the beginning of the line

The delete command

command effect
x Delete cursor character
nx After deleting where the cursor is n Characters
dd Deletes the line where the cursor is located
ndd Delete the cursor and the n That's ok
dgg Delete all lines before the line where the cursor is located
dG Delete all lines after the line where the cursor is located
D Delete the cursor line to the end of the line
:n1,n2d Deletes the row of the specified range

Copy and cut commands

command effect
yy Copy the current row
nyy Copy below the current line n That's ok
dd Cut the current line
ndd Cut below the current line n That's ok
p,P Paste under or on the line where the current cursor is located

Replace and cancel commands

command effect
r Replaces the character where the cursor is
R Replace the character from where the cursor is , Press Esc end
u Cancel the previous operation

Find and replace commands

command effect
/string Search for the specified string
set ic Ignore case when searching
n Specify the next occurrence position of the string when searching
:%s/old/new/g Full text replacement string ,gc It means that each string needs to be manually judged by yourself, which is the most commonly used
:n1,n2s/old/new/g Replace strings within a certain range

Save command

command effect
:w Save changes
:w new_filename Save as the specified file
:wq Save the changes and exit
ZZ Shortcut key , Save the changes and exit
:q! Exit without modification
:wq! Save the changes and exit

VIM Using skills
Import all the contents of another file into the current file

 command : Enter... In edit mode :r+ The file name of the import file 
 Example ::r test.txt

Don't quit VIM Under the premise of , perform Linux command , And print the executed results to the current file

 command : Enter... In edit mode :r ! command 
 Example ::r !ls

stay VIM Define shortcuts in the editor

 command :map  Shortcut key   Trigger a command 
 Example :map ^p I# <ESC>

The whole replacement of words

 command : ab
 Example :ab always always @(posedge sclk or negedge)

How to save the current VIM Set the shortcut keys and replace them as a whole
Create a folder under the current user .vimrc The file of , Write the created shortcut key to the file

 Example :vim root/.vimrc
原网站

版权声明
本文为[qq_ forty-four million nine hundred and eighty-five thousand si]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/204/202207231641422567.html