Vim Tips 2

Source: Internet
Author: User

Vim Tips Summary-Find

1. Find commands
1.1 Performing a search
In normal mode, the lookup prompt is called, and if the VIM scan to the end of the document still does not find the target, it will prompt "search hit BOTTOM, continuing at TOP". This means that the document will wrap around to the beginning to continue looking.
If you want to turn off document wrapping lookups, you can turn off the ' wrapscan ' option:
: Set Nowrapscan
1.2 Specifying the lookup direction
/Key lookup, perform a forward scan, when the key is found, perform a reverse scan.
1.3 Repeating last Lookup
n is used to jump to the next match, N to jump to the last match.
1.4 Finding before backtracking
/or? After the Find prompt appears, you can browse through the previous find command through the <Up> key.

2. Highlight matching to the find
By default, VIM does not display all matching displays, and 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 to the first match based on the find character. Each time you enter a character, the preview content is updated instantly.
: Set Incsearch
3.1 Checking for matches
If you just want to confirm that the word exists, you can match it exactly, then <esc> it, and immediately end the search and return it.
3.2 Auto-completion of lookup fields based on preview results
<C-r><C-w> can automatically complete the current matching results.

4. Count the number of current pattern matches
:%S/<PATTERN>//GN
The substitute command is actually called, and the flag bit n suppresses the normal substitution operation, and the replacement domain is not valid for any reason.

5. Offset the cursor to the end of the find match
Each time a Find command is executed, the cursor is always set to match the first letter, and the cursor can be positioned at the end of the find match by using the offset function.
The Search-offset option controls this operation.
You can type/<pattern>/e<cr> while you are looking, that is, you can place the cursor at the end of a find match.

6. Work with full lookup matches
The VIM Lookup command allows us to quickly adjust between all matches, but it is also necessary to operate on a complete match.
If you want to convert all of the RB and Ruby characters in the document to uppercase,
/\VR (U)? by (y)? \c<cr> ' = ' meta-character \c enforces case sensitivity
This will light up all the matching words eigenstates, and then
gu//e<cr> =//<cr> =. =//<cr>.

7. Iterate through complex patterns with search history
Sample file 1. txt:
My name is ' caoqing '.
My dog is ' pipi '.
I love ' Pipi '.
Matches all the contents in single quotes.
7.1 Rough Matches
/\v '. + ' \c/
Need to be aware that such a situation would

Vim Tips 2

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.