Search for characters
Command F is used to search forward within the row. For example, FX searches for the forward letter X. The command F searches backward (backward. For example, FX searches backward for the letter X. Similar to F and F, they are T and T commands. The T command is similar to the f forward SEARCH Command. The difference is that t does not stop the cursor on the target character, but on the first character of the target character. In the search process, we can use ESC to exit the search and start a new job.
For the above four search commands, We can repeat these operations. The command is to continue searching in the previous direction. If you want to search in the opposite direction, you can use the command. However, these searches are performed only within the row and will not move the cursor to other rows.
Search for strings
We can use the/string command to forward (forward) to find the string. Press enter to jump the cursor to the correct place. In this command, the/character is the character we want to search for, and the Return key indicates the end of the command.
Sometimes the content you want to search for is not only in one place. You can search for the content in the entire article: // you can continue the search operation just now. We can also use the N command to continue the search command just now. Both commands can achieve the same effect.
In general, the search is always forward. Can we also use? Command (backward. N is also a reverse lookup command, which can implement reverse lookup immediately.
To stop this search, run Ctrl + c. If it is in windows, run Ctrl + break.
Vi can record the search command history, so you do not need to enter the search command again. For example, the Three searches you have just done are:/One,/Two,/three. Now enter/, and then press the arrow key to go up or down to see that the content you just searched is displayed below VI. Then, you only need to press enter to find the desired content.
Position of the cursor
By default, VIM places the cursor at the beginning of the first matching result. We can also specify the position of the cursor after the search is complete. For the forward SEARCH Command, we can use a number after the diagonal line to specify the position of the cursor, for example, the/set/2 command will place the cursor at the beginning of the second line after the first set string after the search is complete. The number in the command can be positive or negative. If it is only a simple number, the cursor is placed at the beginning of the row specified by the first matching string or the previous number. It is backward, and the negative value is forward. If the slash is followed by a number and B, after the search, the cursor will be placed at the beginning of the first matching string, and then move n characters to the left or right, here, n is the number specified by the number. If it is a positive number, it is shifted to the right. If it is a negative number, it is shifted to the left. For example,/set/B2. This Command places the cursor at the beginning of the first matching character after the search, and then moves the cursor two characters to the right, that is to say, the cursor will be at the T position in the first matching string. Changing B to s also achieves the same effect. The parameter E places the cursor at the end of the first matching string. Similarly, we can use numbers to specify the number of characters to move the cursor to the right or to the left. For example, the/set/e command will place the cursor at the end of the first matching character. If the command is changed to/set/E2, the cursor is placed at the end of the first matching string, and 2 characters are moved to the right. If the number is positive, it is shifted to the right. If the number is negative, it is shifted to the left.
The command/set/e + 2 is to place the cursor at the end of the first matching string after the search for the set string is complete, and then move the two characters to the right. Here we call this number an offset. If you want to repeat the previous search but need different offsets, you can run the // 5 command. If no offset is used, you can specify an empty offset, for example, // command. /Command to repeat the previous search and use the same offset.
SEARCH Command? You can also implement similar functions. For example? Set? The B5 Command places the cursor at the beginning of the last matched string, and then moves 5 characters to the right .?? -2 command, the previous search command is continued, but the new offset is used .?? Command to continue the previous search command, but the offset is not used.
Search string immediately
If you want to quickly find the string under the current cursor, you can run the * command to find the exact matching string with the characters under the current cursor. The command # is used to search for strings exactly matching the characters under the current cursor. If the string under the current cursor is word, it does not match the word when the * command is executed. Similar to the current search command, it is the G * command. He does not perform strict matching. If you use this command to find the word, it may match the word. The G # command is the same as the command, except that it matches the search in the opposite direction.
Set search options
We can select the text to be highlighted and displayed. The command is: Set hlsearch, and the command to disable the highlighted display is: Set nohlsearch. To disable the highlighted result, run the: nohlsearch command.
Use the: Set incsearch command to enable the matching search option. The matching process is displayed during the search. For example, the content you want to search for is include. After this option is enabled, when you enter/I, the cursor is positioned on I, and then the input n cursor is positioned on in, so until the requested content is queried. The command to disable this option is: Set noincsearch.
By default, VIM is case sensitive. If a file contains the following strings: Include, include, include. When we use the command/include to search for strings, only the include characters are highlighted. However, if we use the: Set ignorecase command to enable the ignorecase option, all similar characters will be highlighted. If this search result is not what we want, you can use: Set
Disable the noignorecase command.
If the ignorecase option is set, we want to find the string word, which may be word, word, or word. If we want to search for the string word, the matching result is the same. However, if set ignorecase and set smartcase are set, the execution result will be different: If we enter lower-case characters, We will match various possible combinations, in this case, it is the same as setting ignorecase, but if we have an uppercase character in the input, then it becomes an exact search, which is the same as setting noignorecase.
When executing the SEARCH Command, we can also use modifiers to control case sensitivity. Adding the modifier/C to the Command will tell Vim to execute case-sensitive queries, such? The/cword command only matches the word. If the modifier/C is added to the command, the case-insensitive query is executed.
By default, we enter the string to be searched. Vim searches forward from the current cursor until the end of the file. If not, then, the search starts from the beginning of the file until the cursor is located. We can use the: Set nowrapscan command to disable this method of loop search. If the bottom of the file is found, an error message is displayed at the bottom. If you want to return to the normal state, you can use the: Set wrapscan command.
F |
Search forward and hover the cursor over the target character |
F |
Search backward and hover the cursor over the target character |
; |
Repeat the search. |
, |
Repeat the previous search in reverse order |
T |
Search forward and hover the cursor over the first character of the target character |
T |
Search backward and hover the cursor over the next character of the target character |
/ |
Forward lookup |
? |
Backward Search |
N |
Continue searching |
N |
Reverse Lookup |
* |
Looks forward for strings exactly matching the characters under the current cursor |
# |
Returns the exact string matching the characters under the current cursor. |
: Set hlsearch |
Open the highlighted Search Text |
: Set nohlsearch |
Close the highlighted Search Text |
: Nohlsearch |
Disable the highlighted result |
: Set incsearch |
Show the matching process |
: Set noincsearch |
Disable show matching process |
: Set ignorecase |
Case Insensitive |
: Set noignorecase |
Exact match case |
: Set nowrapscan |
Disable loop search |
: Set wrapscan |
Enable loop search |