[Load] Vim Common commands

Source: Internet
Author: User
Tags alphanumeric characters

1. Search

/XXX (? XXX) indicates searching for strings matching XXX in the entire document,/indicates searching down ,? It indicates that xxx can be a regular expression in the upward search. We will not talk much about the regular expression. Generally, it is case sensitive.

To be case insensitive, enter: Set ignorecaseAfter finding it, enter n to find the next match and enter n to search for it.

* (#) When the cursor stays on a word, enter this command to search for the next (top) word that matches the word, and then enter n to find the next match, search for input N in inverse direction

G * (G #) this command is similar to the previous command, except that it does not fully match the word where the cursor is located, but matches all strings containing the word.

GD this Command finds the word that matches the word where the cursor is located, and places the cursor in the non-comment section of the document where the word appears for the first time.

% This command looks for the parentheses matching the cursor location, including () [] {}

F (f) X: This command searches for the first X character on the right (left) side of the cursor in the row where the cursor is located.
After finding:
Input; indicates to continue searching
Input, indicating Reverse Lookup

2. move the cursor quickly
In VI, moving the cursor and editing are two things. Because they are distinguished, It is very convenient to position and edit the cursor, so it is very useful to move the cursor faster.

W (e) move the cursor to the next word
B. move the cursor to the previous word.

0 move the cursor to the beginning of the line
^ Move the cursor to the starting character of the line
$ Move the cursor to the end of the row

H move the cursor to the first line of the screen
M move the cursor to the middle line of the screen
L move the cursor to the end of the screen
Gg move the cursor to the first line of the document
G move the cursor to the end of the document
C-F (press Ctrl and F together) this command is page down
C-B (that is, press Ctrl and B together, and then the same) this command is page up

''This command is quite useful. It moves the cursor to the previous tag, for example, using Gd, *, and so on to find a word, and then entering this command will return to the position where it was last stayed.

'The command is quite good, it moves the cursor to the last modified line

'The command is quite powerful, it moves the cursor to the last modification point

3. Copy, delete, and paste
In VI, y indicates copying, d Indicates deleting, and P indicates pasting. Copy and delete are combined with the cursor moving command. You can see the following examples.

YW indicates copying the content from the current cursor to the end of the word where the cursor is located
DW indicates deleting the content from the current cursor to the end of the word where the cursor is located
y0 indicates copying from the current content from cursor to the beginning of the row where the cursor is located
D0 indicates deleting content from the current cursor to the beginning of the row where the cursor is located
Y $ indicates copying content from the current cursor to the end of the row where the cursor is located content
d $ indicates deleting the content from the current cursor to the end of the row where the cursor is located
yfa indicates copying the content between the current cursor and the first a character after the cursor
DFA indicates deleting the content from the current cursor to the first a character after the cursor

Specifically:
YY indicates copying the row where the cursor is located
Dd indicates deleting the row where the cursor is located.
D: deletes the content from the current cursor to the end of the row where the cursor is located.

The complex usage of copying, deleting, and pasting is related to registers. You can query them by yourself.

4. Numbers and commands 
In VI, the combination of numbers and commands often indicates repeated execution of this command. If the command appears at the beginning of the extended mode, it indicates that the row number is located, for example:

5fx indicates 5th x characters after the cursor search

5 W (e) move the cursor to the next five words

5yy indicates copying 5 rows below the cursor
5dd indicates deleting 5 rows below the cursor

Y2fa indicates copying the content from the current cursor to the second a character after the cursor

: 12, 24y indicates copying content between 12th rows and 24th rows
: 12, y indicates copying content between the 12th rows and the row where the cursor is located
:, 24y indicates copying the content between the row where the cursor is located and deleting the content between the row 24th is similar

5. Enter characters quickly.
In Vi, you do not need to enter every character. There are many ways to quickly enter some characters. If you use Linux/Unix, you must have an experience. when you enter a command on the command line, you can enter the first few characters and then press TAB. Then, the system will automatically complete the remaining characters, if there are multiple matches, it will be printed out, which is the completion of the famous command. VI has many character string completion commands, which are very convenient.

C-P (c-N) in editing mode, enter a few characters and then enter this command, then VI starts to search for and complete the matching words at the beginning (bottom, if you enter this command repeatedly, this command will be found in all

ProgramIn

In C-X-l editing mode, this command is used to quickly complete the entire line of content, but only matches the content in the document that appears in this window.

In C-X-F editing mode, this command indicates filling up the file name, as shown in the following:
/Usr/local/Tom:
/Usr/local/tomcat/

Abbr stands for a macro operation. You can use an abbreviation in the editing mode to replace another string. For example, if you write a Java file, you often enter systemoutprintln.

To reduce the number of words:: Abbr SPRT systemoutprintlnAfter entering SPRT and other non-alphanumeric characters, it will be automatically extended to systemoutprintln

6 replace
Replacement is the strength of VI, because regular expressions can be used to match strings. Below are several examples:

: S/AA/BB/g replace AA in all strings containing aa that appear in the row where the cursor is located with bb
: S/\ <AA \>/BB/g replace all AA in the row where the cursor is located with BB, and replace only the word AA.
: % S/AA/BB/g replace AA in all strings containing AA in this document with bb
: S/AA/BB/g replace AA in all strings containing aa that appear from row 12 to row 23 with bb
: 12, 23 S/^/#/Add the first line from 12 to 23 characters #
: % S = * $ = Delete unnecessary spaces at the end of all rows
: G/^ \ s * $/D: delete all blank lines that do not contain characters (spaces are not included)

7. Delete more

X  Delete the character under the cursor (abbreviated as "DL)
X  Delete the character before the cursor (abbreviation of "DH)
D  Delete from the current position to the end of the line (abbreviated as "d $)
DW  Delete from current position to start of next word
DB  Delete from the current position to the beginning of the previous word
DIW  Delete words on the cursor (excluding blank characters)
DAW  Delete words on the cursor (including white spaces)
DG  Delete to the end of the file
DGG  Delete to the beginning of a file

"DL"  Delete characters (Abbreviation: "X ")          | DL |
"DIW"  Delete words              * DIW *
"Daw"  Delete a word              * Daw *
"DIW"  Delete the contained string (see | word |)      * DIW *

"Daw" Delete a string (see | word |) * Daw *
"DD" Delete a row | Dd |
"Dis" Delete sentences * Dis *
"Das" Delete a sentence * Das *
"Dib" Delete A block containing '('')' * Dib *
"Dab" Delete A '('')' Block * Dab *
"Dip" Delete included paragraphs * Dip *
"DAP" Delete a paragraph * DAP *
"Dib" Delete large blocks containing '{''}' * Dib *
"Dab" Delete a large block '{''}' * DAB


8. Comment multiple lines

(1) press Ctrl + V to enter the column mode, move the cursor down or up, mark the beginning of the row to be annotated, and press I in uppercase to enter the insert mode. Enter #, press ESC, and all comments will be made.

(2) Use commands

: S/^/# comment the current row

: M, NS/^/# comment m to N rows

:., + 3 S/^/# comment on the three rows following the current row and the current row

: % S/^/# comment all rows

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.