The article directories

  • Vi and vim
  • model
    • General pattern
    • Edit mode
    • Command mode
  • shortcuts

Vi and vim


ViIs the Unix/Linux operating system in the most classic text editor, can only edit characters, font, paragraph typesetting; It can either create a file or edit a file; It has no menus, only commands, and many commands, VI is suitable for text editing.

VimIt is a text editor developed from Vi, which can be regarded as an enhanced version of Vi. It can actively identify the correctness of syntax by font color, and has rich programming functions such as convenient code completion, compilation and error jump for program design. Vim is suitable for coding.

model


Vi/VIm has three modes: general mode, edit mode, and command mode. The conversion relationship is as follows:

General pattern

In general mode, you can use the shortcut keys (listed at the end of the article) : not a demo

Input ordervim filenameEnter general mode:



Edit mode

Enter the following shortcut keys in normal mode to enter the edit mode for text editing:

shortcuts role
i Enter from the current cursor location (The commonly used)
I Start typing at the first non-space character on the current line
a Enter from the next character where the cursor is currently located
A Enter from the last character on the line where the cursor is
o Enter a new line next to the current cursor
O Enter a new line on the line above the current cursor location
r Replaces the cursor character only once
R Replaces the text at the cursor until ESC is pressed



Address of the blogger CSDN: wzlodq.blog.csdn.net/

Command mode

Common commands role
:w Writes the edited data to a disk file
:w! If the file property is Read-only, the file is forcibly written to
:q Exit vi
:q! If you have modified the file and do not want to save it, use it! Do not store files for forced leave.
:wq Save the configuration and exit. If :wq! To force save and exit (The commonly used)
:w [filename] Save the edited data into another file (similar to saving a new file)
:r [filename] In the edited data, read another file’s data and append it to the row after the cursor
:! command Temporarily leave vi and run command in command line mode
:! ls /home You can view the file information output as ls under /home in vi





shortcuts


shortcuts role
H or please The cursor moves one character “left”
J or left The cursor moves one character to “down”
K or write The cursor moves up by one character
L or – The cursor moves one character to the right
Ctrl + f The screen moves down one page
Ctrl + b The screen moves up a page
Ctrl + d The screen moves half a page “down”
Ctrl + u The screen moves half a page “up”
+ The cursor moves to the next line that is not a space character
The cursor moves to the line above the non-space character
0 or [Home] Move to the first character on the line
$ 或 [End] Move to the last character on the line
H The cursor moves to the first character in the top line of the screen
M The cursor moves to the first character of the line in the center of the screen
L The cursor moves to the first character in the bottom line of the screen
G Move to the last line of the file
gg Move to the first line of this file
n The cursor moves back n character distances
n Move the cursor down n lines
/word Look under the cursor for a string named word.
? word Look for a string named word above the cursor
n Represents the action of repeating the previous search
N The opposite of n, the previous search action is performed for “reverse”
x Delete one character backwards (equivalent to [del])
X To remove a character forward (equivalent to [backspace])
nx Delete n consecutive backward characters
dd Delete the entire row where the cursor is located (The commonly used)
ndd Deletes n rows down from the cursor position
d1G Deletes all data up to the first row where the cursor is located
dG Deletes all data up to the last line where the cursor is
d$ Delete the cursor to the last character of the line
d0 Deletes the cursor to the first character on the line
yy Copy the row where the cursor is (The commonly used)
nyy Copy the cursor n rows down
y1G Copy all data from the cursor row to the first row
yG Copies all data from the cursor row up to the last row
y0 Copy all data from the character where the cursor is located to the beginning of the line
y$ Copy all data from the character where the cursor is located to the end of the line
p Paste the copied data one line below the cursor (The commonly used)
P Paste the copied data one line below the cursor
J Combine the cursor row with the data on the next row
c Multiple data was deleted. Procedure
u Undo previous action (The commonly used)
[Ctrl]+r Redo the previous action (The commonly used)
. Repeat the previous action (The commonly used)

Original is not easy, please do not reprint (this is not rich visitors to add to the problem) blogger homepage: wzlodq.blog.csdn.net/ wechat public number: weow lo dong qiang if the article is helpful to you, remember a key three connect ❤