Linux VI (VIM) Common command Summary

Source: Internet
Author: User

Objective

First of all, the analysis of a Vim VI is a very common text editor under the Unix/linux, most of the machines have a variety of VI, on different machines commonly used in different variants of software, which vim more useful also used more widely. VIM is the abbreviation for VI improved, which means better VI. This article to say some more useful, more commonly used commands, if you can skillfully use these commands, then you will find the editing file is very helpful, especially as a developer, can quickly improve the development efficiency.

Description

 In the following example, xxx means enter XXX in command mode and return

In the following example: XXX means enter XXX in extended mode and return

Commands in parentheses represent similar commands

Commands entered in edit mode or Visual mode will also indicate

1 find

/xxx (?  XXX) means searching the entire document for a string matching xxx,/means looking down,? indicates an upward lookup, where xxx can be a regular expression, and there is not much to say about regular expressions. Generally case-sensitive, to be case-insensitive, you must first enter: Set ignorecase Find later, enter N to find the next match, enter n reverse direction lookup *(#) when the cursor rests on a word, enter this command to find the next (top) word that matches the word, and then enter N to find the next match, Input N reverse Direction find G*(g#) This command is similar to the previous command except that it does not exactly match the word at the cursor, but rather matches all strings containing the word GD This command finds words that match the word that the cursor is in. and place the cursor in the non-comment segment of the document where the first occurrence of the word appears , this command looks for an inverse bracket that matches the cursor, including () [] {}f (f) x This command indicates that the cursor is located on the line where the first x character of the right (left) side of the cursor is found: input; continues to look for input, indicating the reverse direction of the lookup

2 Quick Move Cursor

In VI, moving the cursor and editing is two things, because of the separation, so it is convenient to do cursor positioning and editing, so it is very useful to move the cursor a little faster.

 w (e) Move the cursor to the next word b to move the cursor to the previous word  0   move cursor to the beginning of the line  ^ moving Light Mark to the beginning of the line. Move cursor to end of bank h move cursor to first row of screen m move cursor to Middle line of screen l move cursor to end of screen g G Move the cursor to the first line of the document G move the cursor to the end line of the document C -f (that is, the CTRL key and the F key This command is page downc -b (that is, the CTRL key is pressed together with the B key) This command is page up   '   '  This command is useful, it moves the cursor to the previous marker, such as with GD, * etc. After you find a word, enter this command back to where you last stopped    This command is pretty good. So that it moves the cursor to the last modified line   "This command is quite powerful, it moves the cursor to the last modification point  

3 Copy, delete and paste

In vi, y means copy, d means delete, p means paste, where copy and delete are combined with cursor movement commands, see a few examples to understand.

YW represents a copy of the content from the current cursor to the end of the word at the cursor. The DW represents the deletion of the content from the current cursor to the end of the word at the cursor y0 means that the copy is from the current cursor            to the            beginning of the cursor d0 the content            from the current cursor to the end of the cursor y$            represents the copy from the current cursor to the end of the line at the cursor d$ means to delete the content            from the current cursor to the end of the cursor line YfA           represents the contents of the copy from the current cursor to the first a character following the cursor DFA           Represents the deletion of the contents from the current cursor to the first a character following the cursor

In particular:

YY            means that the copy cursor line DD            means the deletion of the cursor row D             means the deletion from the current cursor to the end of the cursor line of content

The complex usage of copying, deleting, and pasting is related to registers and can be queried on your own.

4 Numbers with commands

In VI, the combination of numbers and commands often means repeating this command, and if it appears at the beginning of the extension mode, it indicates the line number positioning, such as:

5fx               represents the 5th x character after the lookup cursor 5w (e)  moves the cursor to the next five words 5yy               means the copy cursor below 5 lines 5dd            means delete the cursor below 5 lines Y2FA              Represents the contents of a copy from the current cursor to the second a character following the cursor:  24y        represents the contents of the copy between lines 12th through 24th:y            Represents the contents of the copy 12th line to the line of the cursor: 24y            means that the contents of the copy cursor line to line 24th are    deleted similar to the same

5 Fast Input characters

In VI, do not require you to enter every character, there are many ways to quickly enter some characters, using Linux/unix students must have an experience, in the command line Input command when the first few characters and then press TAB, the system will automatically fill the remaining characters, if there are many matches will be printed out, This is the well-known command to complement, VI has a lot of string command, very convenient.

C-p (c-N) in edit mode, enter a few characters and then enter this command then VI begins to search for the word that matches the beginning of the start (bottom) and fill it out, and continuously enter this command to loop through this command to match C-x-in all files opened in this VIM programl< c2/> in edit mode, this command quickly complements the contents of the line, but only matches in the document that appears in this window C-x-f    in edit mode, this command indicates the file name as input:/usr/local/tom and then enter this command automatically matches the following:/ usr/local/tomcat/abbr is     abbreviated this is a macro operation, you can use an abbreviation in the editing mode instead of another string such as writing Java files often input systemoutprintln, which is very troublesome, So you should use abbreviations to reduce the typing can do:: abbr sprt systemoutprintln after the input sprt and then enter other non-letter symbols, it will automatically expand to Systemoutprintln

6 replacement

Replacement is the strong point of VI because you can use regular expressions to match strings, and here are a few examples.

: s/aa/bb/G replaces all AA-containing strings in the line where the cursor appears with bb:s/\/bb/G replaces  all AA occurrences of the cursor with BB, replacing only the word AA: %s/aa/bb/g replace AA in all occurrences of the documentwith AA with BB: 23s/aa/bb/G will all occurrences of a string containing AA from 12 rows to 23 rows        AA in Replace with BB:23s/^/#/ will add the # character from Line 12 to line 23:%s= *$==    Delete all lines at the end of the line: G       /^\s*$/d Remove all empty lines that do not contain characters (spaces are not included)

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.