当前位置:网站首页>Editor use of VI and VIM

Editor use of VI and VIM

2022-07-05 08:58:00 Wanderer001

Reference resources   Editor -vi、vim Use - cloud + Community - Tencent cloud

Catalog

1、vi brief introduction

2、vi Working mode

2.1、 Command mode

2.2、 Edit mode

2.3、 Last row mode

3、vi Basic manipulation

3.1、 Enter edit mode

3.2、 Move the cursor

3.3、 The delete command

3.4、 Revocation order

3.5、 Repeat the order

3.6、 Copy and paste

3.7、 Select text

3.8、 Search and replace


1、vi brief introduction

vi Editor yes Linux and Unix The most basic Text editor , Working in character In mode . Because you don't need a graphical interface ,vi It's a very efficient text editor . Although in Linux There are also many graphical interface editors available on , but vi In the system and Server management The functions in are those Graphic editor Incomparable .

vi Editor It is often referred to as vi, and vi again “Visual interface” For short . It's in Linux Status in the world is like Edit The program is in DOS It's the same . It can perform output 、 Delete 、 lookup 、 Replace 、 Block operations and many other text operations , And users can customize it according to their own needs , This is the other Edit the program Not available .

vi The editor is not a typesetting Program , It is not like Word or WPS That way, it's possible to 、 Format 、 Arrange paragraphs and other attributes , It's just a text editor . No menu , Only the command , And there are many orders .vi Yes 3 Basic working mode : Command line mode 、 Text input mode and last line mode .

Vim yes vi The enhanced , Than vi Easier to use .vi Almost all of your commands can be found in vim Upper use .

2、vi Working mode

vi There are three basic modes of work : Command mode 、 Text input mode 、 Last row mode .

                                                         

                                                                               vi Working mode

2.1、 Command mode

anytime , No matter what mode the user is in , Just press ESC key , Can make Vi Enter command mode ; We are shell Environmental Science ( The prompt is $) Lower input start Vi command , When you enter the editor , Also in this mode . In this mode , Users can enter all kinds of legal Vi command , For managing your own documents . Any character entered from the keyboard is interpreted as an edit command , If the input character is legal Vi command , be Vi After receiving the user's command, complete the corresponding action . But it should be noted that , The command entered is not displayed on the screen . If the input character is not Vi The legal order of ,Vi Will ring the alarm .

2.2、 Edit mode

Enter the insert command in command mode i( Insert current position )、a( Insert at the next position after the current position ) 、o( Insert... In the next line ) You can enter text input mode . In this mode , Any character entered by the user is vi Save it as file content , And show it on the screen . In the process of text input , If you want to go back to command mode , Key ESC that will do .

2.3、 Last row mode

In command mode , User presses “:” Key to enter the last line mode , here Vi In the last line of the display window ( It's usually the last line of the screen ) Display a “:” As a prompt for the last line mode , Wait for the user to enter the command . Most file management commands are executed in this mode ( Write the contents of the edit buffer to a file ). After the last command is executed ,Vi Automatically return to command mode .
If you want to change from command mode to edit mode , You can type commands a perhaps i; If you need to return from text mode , Then press Esc Press the key . Enter... In command mode “:” You can switch to the last line mode , Then type the command .

3、vi Basic manipulation

3.1、 Enter edit mode

command meaning
i and Ii Insert... In front of the cursor ,I Insert at the beginning of line
a and Aa Insert... After the cursor ,A Insert at end of line
o and Oo Insert... On the next line below the line where the cursor is located ,O Insert... On the line where the cursor is located

3.2、 Move the cursor

command meaning
h Move the cursor to the left
j Cursor down
k Move the cursor up
l Move the cursor to the right
H、M、L The cursor moves to the first line of the visible screen (H)、 Middle row (M)、 The last line (L)
^ and $^ Move to beginning of line ,$ Move to the end of the line
G and ggG The last line of the document ,gg The first line of the document
ctrl+f、ctrl+b Flip the screen forward 、 Flip the screen back
ctrl+d、ctrl+u Forward half 、 Half back
{ and }{ Move up a section ,} Move back a bit
w and b Move a word forward , Move a word back

3.3、 The delete command

command meaning
X and xx Delete the character after the cursor ,X Delete the character before the cursor , Contains cursor position characters
dd and n dddd Delete the line ,5 dd Delete the specified number of rows
d0 and Dd0 Delete all the contents of the line before the cursor ,D Delete all the contents of the line after the cursor is deleted , Contains cursor position characters
dw Delete the word where the cursor is located , Contains the characters of the position of the light table

3.4、 Revocation order

command meaning
u Undo step by step
ctrl + r Counter cancellation

3.5、 Repeat the order

command meaning
. Repeat the command of the last operation

3.6、 Copy and paste

command meaning
yy and n yy and y$ y^ yy Copy the current row ,5 yy Copy 5 That's ok
p Paste a new line down at the cursor

3.7、 Select text

command meaning
v and Vv Select a single character ,V Select entire line
<< and >> After selecting the text , Indent left , Indent right

3.8、 Search and replace

command meaning
In command mode ,r and Rr Replace the current character ,R Replace the character after the cursor
In last line mode ,/ + strn Find the next one ,N Find the previous
In last line mode ,%s/abc/123/g Put all the abc Replace with 123
In last line mode ,1, 10s/abc/123/g Put the first line to 10 Between lines abc Replace with 123

 

原网站

版权声明
本文为[Wanderer001]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/186/202207050851134062.html