Vim highlight search operation
After using Vim for so long, some basic operation commands cannot be kept in mind. When searching for a keyword today, you cannot find the "Next", So google will fix it and paste all the useful information.
SEARCH command:
/Xxx search down
? Xxx upstream
N next
: Set hls to enable highlight
: Set nohls disable highlight
Here is the search replacement, although I have never used this function --
Because there are too many online files, I don't know who the original files are.
1. Simple replacement expression
The replacement command can replace another word with one word in the full text:
: % S/four/4/g
The prefix of "%" indicates that replacement is performed in all rows. The last "g" Mark replaces all matching points in the row. If you only operate on the current row, remove %.
If you have a word like "thirtyfour", the above command will fail. In this case, the word is replaced with "thirty4 ″. To solve this problem, use "\ <" to specify the start of the matching word:
: % S/\ <four/4/g
Obviously, errors will still occur when processing "fourty. Use "\>" to solve this problem:
: % S/\ <four \>/4/g
If you are coding, you may just want to replace the "four" in the comment, but keep the "four" in the code. Since this is difficult to specify, you can add a "c" mark in the replacement command, so that Vim will prompt you before each replacement:
: % S/\ <four \>/4/gc
2. Delete unnecessary spaces.
To delete unnecessary spaces behind each line, run the following command:
: % S/\ s \ + $ //
The command specifies that the range is "%", so this will apply to the entire file ." The matching mode of the substitute command is
\ S \ + $ ". This indicates one or more (\ +) spaces (\ s) before the end of the line ($ ). The "to" part of the replacement command is empty :"//". In this way, the matching spaces are deleted.
3. Matching repetition Mode
The asterisk (*) specifies that the items before it can be repeated at any time. Therefore:
/*
Match "a", "aa", "aaa", and so on. But it also matches "" (Null String), because zero times are also included. The asterisk "*" is only applied to the item next to it. Therefore, "AB *" matches "a", "AB", "abb", and "abbb. To repeat the entire string multiple times, the string must be an item. Add "\ (" and "\)" before the component. Therefore, this command:
/\ (AB \)*
Matching: "AB", "abab", "ababab", and so on. It also matches "".
To avoid matching null strings, use \ + ". This indicates that the previous item can be matched once or multiple times.
/AB \ +
Match "AB", "abb", "abbb", and so on. It does not match "a" that follows "B ".
To match an option, use "\ = ". For example:
/Folders \ =
Matches "folder" and "folders ".
4. specify the number of repetitions
To match a specific number of times of repetition, use the form "\ {n, m. "N" and "m" are numbers. The item before it will be repeated "n" to "m" Times (| aggressive sive | contains "n" and "m "). For example:
/AB \ {3, 5}
Match "abbb", "abbbb", and "abbbbb ".
When "n" is omitted, It is 0 by default. When m is omitted, It is infinitely large by default. When ", m" is omitted, it indicates that the repetition is exactly "n" times. For example:
Number of pattern matches
\ {, 4} 0, 1, 2, 3, or 4
\ {3,} 3, 4, 5, and so on
\ {0, 1} 0 or 1, same as \ =
\ {0,} 0 or more, the same *
\ {1,} 1 or more, same as \ +
\ {3} 3
5. Select one or more matches.
In a search mode, the "or" operator is "\ | ". For example:
/Foo \ | bar
This command matches "foo" or "bar ". More options can be connected to the following:
/One \ | two \ | three
Match "one", "two", or "three ".
To match multiple times, the entire decision structure must be placed between "\ (" and:
/\ (Foo \ | bar \) \ +
This command matches "foo", "foobar", "foofoo", "barfoobar", and so on.
Another example:
/End \ (if \ | while \ | \)
This command matches "endif", "endwhile", and "endfor ".
For more Vim tutorials, see the following:
Build VIM into a simple and practical IDE
Vim Learning Guide
Quick learn Vi Editor
Powerful Vim Editor
Build a Vim Development Environment on CentOS 6.2
Install the highlighted Vim editing tool in CentOS 5.4
Vim tips: C language settings
Set the Vim row number in Ubuntu
Vim editor basic tutorial
This article permanently updates the link address: