Take the Tomcat profile Service.xml as an example to record and learn the most common operations of VI.
> What is VI or vim?
Mans VI VIM (1) VIM (1) NAME - Vi Improved, a programmers text editor ...
Yes, the programmer's text editor.
> Open, Mode switch
VI server.xml
There are two modes, command mode, input mode
ESC switches to command mode (if the insert is not displayed at the bottom of the document, it is in command mode; If you are too lazy to see it, press and write ESC to confirm the next chant). In command mode, you can perform a variety of commands, such as copy, paste, move the cursor, etc. i switch to insert mode, I enter the current cursor is filled with the type of text (insert) a switch to insert mode, I enter the text after the current cursor type (ADD)
o Add a blank line below the current line and switch the cursor to the next line
O add a blank line on the current line and switch the cursor to the previous line
> Save, close Documents
:w save document: Q Exit Edit: Wq Save and exit Edit Document: Q! Force exit edit (sometimes the document is changed and you want to quit editing without saving it, use this command)
> Move Cursor
HJKL has four keys on the keyboard that are used to control the left, bottom, top, and right of the cursor. H moves one character to the left. It is located at the far left of the four keys, and moves one character to the right when the control wants to move left. As with H, on the far right, J moves to the following line. There is a wood to see J above a bump bit, there is wood to note that J is located in the best and most convenient location of the keyboard. Moving down is also the most frequent action for editing a document, and of course, the non-J-K moves up one line. Next to J, of course, is responsible for moving up one line.
0 cursor switches to the first character of the current line
$ cursor switches to the last character in the current line
G cursor moves to the end of the document
Ctrl + F Scrolls down one page (Forward)
Ctrl + B Scrolls up one page (back)
> Copy, paste
YY Copy the current line Nyy n lines below the copy cursor (with the row of the cursor) YW Copy the word nyl copy The n letter P, including the cursor , to paste before the cursor (for example, to copy a row, paste the next line under the cursor) P Paste after the cursor (such as copying rows, pasting on one line of the cursor)
> Delete
x Delete current character dd Delete when forward
> Show Line Numbers
: Set Nu
"Linux" VI (VIM) Start learning a little difficult, step by step study