Vim Learning Notes (ii)

Source: Internet
Author: User

Vim Learning Note the second, because the need to collate documents and work, and do not achieve a daily study and publish an article, but diligent record is good ~

2. Find
The find command is "/string", note,. *[]^%/\? " $ has a special meaning, find them need to precede with a "\", use "n" to find the next, find a third match, use "3n", "n" to repeat the previous lookup.
"?" Similar to "/", but reverse lookup, function is the opposite.
-------------------------------------------------------
Ignore Case
: Set ignorecase
if you want to distinguish between case
: Set Noignorecase
-------------------------------------------------------
-- Find a word in the text--
Suppose you see a very long word in the text, such as "Thelongfunctionname", and you want to find the next same word, but are afraid of typing the error, there is a simple way to move the cursor over the word

Using the "*" command,
Vim takes the word on the cursor and takes it as the string to be looked up, and "#" completes the same function in reverse.
--Find the whole word--
For example, if you enter "/the", you may also find "there". To find the word ending with "the", You can use: "/the\>". " \> "is a special notation that matches only the end of a word.
Similarly, "\<" matches only the beginning of the word, so that to match a complete word "the", simply: "/\<the\>". Note that "*" and "#" are also used to match the whole word with the word head and the suffix. (To department match ,

Using "g*" and "g#")

--Highlight match--

When you want to highlight the word you are looking for, one way to do this is to move the cursor to the word you are looking for using the "*" command, and the other way is to enter this command:

: Set Hlsearch

To turn off this feature:

: Set Nohlsearch

Then you need to switch back again at the next search. If you just want to remove the highlighted item, use the following

Command:
: Nohlsearch
This does not reset the Hlsearch option. It just turns off highlighting. When you perform the next lookup, the highlight feature
will be activated again. The same is true when using the "n" and "n" commands.

--Adjust the search method--

There are options to change how the Find command works. A few of them are the most basic:

: Set Incsearch

This command causes Vim to display the matching points as you enter the string. Use this to check if the right place has been found. Then enter <Enter> jump to that place. Or continue to enter more

The character changes the string to be looked up.

: Set Nowrapscan

This option stops searching after the end of the file is found. Or when you look back at the beginning of the file, stop looking. By default the status of ' Wrapscan ' is ' on '. So when the end of the file is found, it will be self

Moving back.


--Episode--

If you like the previous options, and each time you use Vim to set it, you can write these commands to
Vim in the startup file.
Edit VIMRC, and then add a line to the text to set these options as if you were typing in Vim, for example:

Go:set hlsearch<esc>

"G" moves to the end of the file, "O" starts a new line, and you enter the ": Set" command there.
Finally you end the insertion mode with <Esc>. Then use the "ZZ" command to save the disk.
Now if you restart Vim, the ' hlsearch ' option is already set.
--Using tags--
When you jump to another place with the "G" command, Vim remembers where you jumped from. This position becomes a
Mark, to return to the original place, use the following command:

``

' Use single quotation marks ' is also possible.
If you execute this command again you will jump back to the original place, because ' remember the position before you jump.
Usually, every time you execute a command that moves the cursor outside of the bank, this movement is called a "jump".
This includes finding the command "/" and "N" (regardless of how far to jump). But does not include "FX" and "TX" These
the inline Find command, or the words "w" and "E", move the command.
In addition, "J" and "K" will not be considered as a "jump", even if you precede the prefix with the number is no exception.
the command can be skipped in two locations. The Ctrl-o command jumps to an "older" place (hint: O
represents older). Ctrl-i jumps to a "newer" place (hint: I is close to O on the keyboard).
-- marked with a name--
Vim allows you to place a custom tag in the text. The command "Ma" marks the current cursor position with a. You can be in
26 tags (A to Z) are used in the text. These tags are not visible, just a location that is remembered by Vim.
To jump to a tag you have defined, you can use the command ' {mark} ', where {mark} is the definition tag
the letter. So, the command to move to mark A is:

' A

The command ' mark ' (single quote plus a marker) moves to the beginning of the line where the marker is located. This is different from the ' Mark ' command,
The latter is the column that is marked on the row where the marker is located.

Tagging is useful when you need to work with a file in two related places. Assuming you're dealing with the end of the text, you need
To view some of the text, first move to the beginning of the line, set a Mark S (start):

Ms

Then move to the place where you need to handle it and set a tag e (end):

Me

Now you can move around, and when you need to look at the beginning, you can use this command to move there:

' s

Then use "Jump back." Or use ' e ' to jump to the end of the text you're working on.
Here the use of S and e as tag names have no special meaning, just to remember.

You can get a list of all the tags with the following command:

: Marks

You will notice some special markings, including:

' Pre-jump position
"Last edited location
[The beginning of the last modified position
] The end of the last modified position

Learn a little every day, slowly familiar with the VIM function, unconsciously become powerful.

Vim Learning Notes (ii)

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.