vim command summary

Original: http://www.open-open.com/lib/view/open1401178243433.html

 

1. Find the command
1.1 Perform a lookup
In normal mode, / will call the search prompt. If vim scans to the end of the document and still does not find the target, it will prompt "search hit BOTTOM, continuing at TOP". This means that the document wraps around to the beginning to continue looking.
If you want to turn off document wrapping, you can turn off the 'wrapscan' option:
:set nowrapscan
1.2 Specify the search direction
When the / key is searched, the forward scan is performed, and when the ? key is searched, the reverse scan is performed.
1.3 Repeat the last search
n is used to jump to the next match, and N is used to jump to the previous match.
1.4 Backtracking to previous lookups
/ or ? After the search prompt appears, you can use the <Up> key to browse through the previous search commands.

2. Highlight matched searches
By default, vim does not display all matches displayed. By enabling the 'hlsearch' option, all matches can be highlighted.
Disable this mode:
set nohlsearch (se nohls, se hls!)

3. Preview the first match
The 'incsearch' option causes vim to preview the first match based on the search character. Every time you enter a character, the preview content is instantly updated.
:set incsearch
3.1 Check for a match
If you just want to confirm that the word exists, you can match it exactly, then <Esc>, immediately end the search and return to the original place.
3.2 Auto-completion of search fields based on preview results
<Cr><Cw> can automatically complete the current matching result.

4. Count the number of times the current pattern matches
:%s/<pattern>//gn
In fact, the substitute command is called, and the flag bit n will suppress the normal substitution operation, and the substitution field will not take effect no matter what.

5. Offset the cursor to the end of the search match
Each time a search command is executed, the cursor is always set to the first letter of the match, and the offset function can be used to position the cursor at the end of the search match.
The search-offset option controls this.
You can type /<pattern>/e<CR> while searching to place the cursor at the end of the search match.

6. Operate on complete lookup matches
The Vim find command allows us to quickly adjust between all matches, but it is also necessary to operate on complete matches.
If you want to convert all rb and ruby ​​characters in the document to uppercase,
/\vr(u)?by(y)? \C<CR> => metacharacter \C enforces case sensitivity
This will highlight all matching characters, then
gU//e<CR>    =>    //<CR>    =>    .    =>    //<CR>.

7. Use lookup history to iterate through complex patterns
Example file 1.txt:
My name is 'CaoQing'.
My dog is 'PiPi'.
I love 'PiPi'.
Matches everything inside single quotes.
7.1 Rough match
/\v'.+'\C/
It should be noted that in this case

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326614134&siteId=291194637