[Vim] Summary of the operation scope of the vim command

Source: Internet
Author: User
Tags uppercase letter

 

1. Command operation scope

In fact, many Vim commands are only edited within a text range. A text range can be one character, one word, one line, or another specified character range. You can use the vim command and the text range control key to better complete the editing task. The command format is as follows:

Command + Operation Range

The command can be:

D: delete command. Delete the text of the specified range and save them to the temporary buffer.

Y: Copy (Yank) command. Copy the text within the specified range to the temporary buffer.

P: paste (Put) command. Paste the content of the temporary buffer to the current cursor.

Appendix: The system retains the last nine deleted rows in the buffer zone. Therefore, if you want to restore the last deleted row, use the "1p" command in non-editing state. If you want to restore the last 2nd deleted rows, use the "2 P" command in non-editing status.

C: modify command. It is a combination of the DELETE command and the INSERT command.

The operation scope can be:

E: The last character from the cursor position to the word.

W: The first character from the cursor position to the next word.

B: The first character from the cursor position to the previous word.

 

$: The last character from the cursor position to the row.

0: the first character from the cursor position to the row.

 

(: The first character from the cursor position to the sentence.

): The first character from the cursor position to the next sentence.

 

{: The first character from the cursor position to the paragraph.

}: The last character from the cursor position to the paragraph.

 

GG: Move to the beginning

GG: Move to the end of the article

2. Command case sensitivity

There are also some basic commands, in the upper case, generally the enhanced version of the command or implementing the opposite functions:

I (insert): Insert command, insert text before the cursor.

I (insert): Insert command, but insert text at the beginning of the line where the cursor is located.

A (append): additional command to insert text behind the cursor.

A (append): APPEND Command, but insert text at the end of the line where the cursor is located.

O (open): Open the command, add a new line to the next line of the cursor, and insert text from the beginning of the line.

O (open): Open the command, add a new line to the top line of the cursor, and insert text from the beginning of the line.

 

X: Delete the character at the cursor.

X: Delete the character before the cursor.

D: Delete the cursor in DW. DD: Delete the row where the cursor is located.

D: delete from the cursor to the end of the row.

 

.: Redo the command.

U (UNDO): cancels the changes just executed.

U (UNDO): restores the current row to the status before editing, no matter how many times the row is edited.

 

P: paste the content of the buffer in the next row of the row where the cursor is located.

P: paste the content of the buffer on the top line of the row where the cursor is located.

 

C: CW: delete the word with the cursor and enter the input mode. Cc: Delete the row where the cursor is located and enter the input mode.

 

R: RX uses X to replace the character at the cursor position. X represents a character. Use nrx to replace n characters with X.

R (replace): Enter the replacement mode until "ESC.

 

N (next): Find the next string.

N (next): Find the previous string.

3. Scroll the screen

 

Scroll screen command:

^ F scroll forward one screen

^ B scroll back to a screen

^ D scroll forward half screen

^ U scroll back to the half screen

Move inside the screen

H move to start point ---- the first line of the screen

M moves to the middle line of the screen

L move to the last line of the screen

NH moves to line N below the first line of the screen

Line N at the end of the NL Screen

 

4. search and replace

 

  1. Search in the row.
    1. The F command can be used for intra-row search. Input FX to find the next x character.
    2. The F command can search in the opposite direction, and input FX to find the last x character.
    3. The T command is used for intra-row search, but the cursor stays before the matching characters. Input TX to move the cursor above the next x character.
    4. The T command can search in the reverse direction, but the cursor stays on the next character that meets the condition. Input TX to move the cursor to the character next to X.
    5. % You can search for the matched () [] {}. This function is particularly useful for writing programs.
  2. Full-text search. After you type/, move the cursor to the command line at the bottom of VIM. Then you can enter the/SEARCH Command starting.
    1. The simplest Search. Enter/string to search for the string.
    2. Continue searching. After the first search, enter n to continue the last search. If you enter 3n, the Third matching string is found. The capital N will be searched in the reverse direction, that is, up.
    3. Search up. Input? You can search up. The subsequent n commands will continue to search up, N to search down, and others will be the same.
    4. Matching of case.
      1. Enter set ignorecase in the command line to set the case-insensitive search mode. Input: Set noignorecase can be set to search in case-matching mode. The default value is case-sensitive. This default setting can be modified in. vimrc.
      2. Case sensitivity. Enter the command: Set ignorecase smartcase can be set to the smart case matching mode. In this mode, if the input string contains at least one uppercase letter, it will be searched in uppercase/lowercase sensitive mode. Otherwise, it will be searched in case-insensitive mode.
      3. Specify the case in the search command. In several case-sensitive search modes, a long string of commands is always input for conversion. If you need to continuously convert the mode, it is indeed a little troublesome. Therefore, you can specify the case-sensitive matching mode in the search command. /C Indicates case-insensitive, while/c Indicates case-sensitive.
    5. Search for the current word. A simple method allows you to search for the next word that is the same as the current word. You can press * to search for the next currentword. # Allows you to search up the same word.
    6. Adjust the cursor position after searching.
      1. Use/string/3 to move the cursor to the first row under the line that finds the string. The first row is counted from the row containing the string. You can also use/string/-2 to move the cursor to the first two rows containing the string.
      2. Use/string/E to place the cursor at the end of the string rather than the default first character position. /String/B indicates that it stays at the first character of the string, but this is the default value. We do not need to do anything more. However,/string/B + 2 can place the cursor at the second character of the string. Here is R. + Or-number behind e or B to further adjust the cursor position.
    7. Special characters. In the search command,. * [] ^ % /?~ $ These 10 characters have special meanings. Therefore, you must add a backslash (/) to the front when using these characters /. /E Indicates <ESC>;/T indicates <tab>;/R indicates <CR>;/B Indicates <BS>.
    8. Match line breaks or spaces. Use/N to indicate a line feed, And/s to match the blank space. Note that the blank space is not a space. /_ S indicates matching line breaks or spaces;/_ A indicates matching line breaks or letters. For example,/the/nword searches for the position of the row ending with the word and the next row starting with the word. /The/_ sword searches for spaces or line breaks between the word and the word. /The/_ S/+ word indicates that there can be multiple spaces between the word and the word. The meanings of/+ can be found later.
    9. Limit the beginning or end of a word. /<Only the words starting with the specified string can be found. For example, // <The can be found in the string starting with the, but the string containing the word is ignored. And/> is to limit the words that must end with the specified string.
    10. The beginning and end of a row. Enter/^ string to search for the row starting with string, and the cursor stays at the first character of this string. Enter/string $ to search for the row ending with a string and place the cursor on the first character of the string. In this mode, leading or trailing spaces are not ignored.
    11. Match any character. It can match any character. For example,/t. e can find the, Tae, or Tue.
  3. More complex matching modes. In fact,/search can use very complex matching modes. Some of the complex matching modes are listed below.
    1. Repeated characters.
      1. Use * to indicate that the character before it can be repeated multiple times or zero times. For example,/be * can match B, Be, Bee, beee, and so on. But this will also contain B, because E is null after repeating 0. If you want to match strings such as be, Bebe, and bebebe, you can use/(and/) to include them, such as: // (Be /)*.
      2. Use/+ to limit repetition to at least once to countless times. For example,/be/+ can match be, Bee, and bee.
      3. Repeat 0 times or once. /= You can specify zero or one repetition. /Strings/= indicates matching string or strings. This is particularly useful in searching for the plural form of a word.
      4. The number of repeated times. /{N, m} can be specified to repeat n to m times. For example,/be/{2, 4} matches bee, beee, and beeee. You can also use/{, 4} to match 0 to 4 times./{4,} indicates 4 to countless times./{4} indicates repeated 4 times.
    2. Match one in the list. You can use a/|-separated list to match any item in the list. For example,/One/| two indicates finding one or two;/One/| two/| three indicates finding one, two, or three.
      1. For a complex instance:/end/(if/| while/| for/), you will find endif, endwhile, and endfor.
      2. Character List. [0-9] indicates a character in the range of 0 to 9. For example,/string [1-5] indicates searching string1, string2, string3, string4, string5. Of course, you can also use [A-Z] to represent a character between A and Z.
      3. Special Character Set combination. Use/d to indicate numbers ranging from 0 to 9. This option can be used instead of [0-9]. /D indicates that [^ 0-9] is replaced by a non-number;/X indicates that the hexadecimal number replaces [0-9a-fa-f];/X indicates that the non-hexadecimal number replaces [^ 0-9a-fa-f]; /s indicates that blank characters Replace [] (<tab> and <space>);/s indicates that non-blank characters Replace [^] (except <tab> and <space> ); /L stands for lowercase letters instead of [a-Z];/L stands for non-lowercase letters instead of [^ A-Z];/u stands for uppercase letters instead of [A-Z]; /u table shows non-UPPERCASE letters instead of [^ A-Z]
  4. Search and replace. Enter the [range] S/from/to/[flags] command to search for matched strings and replace them with the specified strings. This is a slightly complex command. [Range] is an option used to specify the range for replacement. [Flags] is also an option used to specify the processing method of search replacement. Therefore, the simple form of this command is: S/from//.
    1. Search for the replacement range. If no range is specified, search for and replace the current row.
      1. Search and replace all rows. The range symbol % indicates that all rows are searched and replaced. : % S/from/to/is to find the from in the full text and replace it with.
      2. Search and replace the specified row. : 1st S/from/to/indicates search and replacement between 50th rows and rows (including 1 and 50 rows. : 45 S/from/to/indicates that only 45th rows are searched and replaced. The range of "1, $" and "%" are equivalent.
    2. Processing Method. The default Vim method I use now does not require confirmation. However, the default Processing Method for different versions is different.
      1. No need to confirm. The method symbol G indicates that the replacement is not required for confirmation. : % S/from/to/G indicates to search for from in the whole text and replace all with.
      2. Print. The processing method symbol P indicates that each changed row is listed during replacement. I am confused by the actual results.
      3. Post-validation. The processing method symbol C indicates that confirmation is required before replacement. In this case, you can select (y/N/A/Q/1/^ e/^ y): Y indicates that you agree to the current replacement; n indicates that you do not agree with the current replacement; a Indicates to replace the current and subsequent items without confirmation. Q indicates to end the replacement operation immediately. 1 indicates to end the replacement operation after the current replacement operation. ^ e: Scroll up ^ y: scroll down, used to help you view the content before and after the operation.
5. Others

 

~ :Case-sensitive conversion. In the non-editing status, move the cursor to a character and use ~ Command, the lower-case letters will be converted to upper-case letters, and the upper-case letters will be changed to lower-case letters.

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.