VIM series: Search

Source: Internet
Author: User

VIM series: when reading the project source code in VIM, the search function will frequently jump to and search for variables, type definitions, and functions, the jump function can be implemented by using the ctag and cssag tools described earlier. However, for some string searches, you can only rely on VIM's search function. VIM itself has powerful search support functions. In addition, it also supports the use of external grep search tools. Here, we only briefly introduce VIM's internal search functions, it is mainly its own use experience. For forward search:/{pattern} or quick search key *, you can select either of the following two methods to search forward in the current file: In Normal mode, run the command:/{pattern} on the command line, where {pattern} is the string to be searched. In Normal mode, move the cursor to any position of the string to be searched, and press the * Key (shift + 8 ). Obviously, the second method is more efficient and faster, and the first method requires you to manually enter a search string. I have been searching in the first method for some time. Later I learned the second method, and I feel relieved. However, in some cases, you can only search using the/command method. * The command cannot be implemented, that is, when the string you want to search contains blank characters. Because * The search mode of the command is automatically determined, only non-blank words under the current cursor will be selected, and the/command search mode is manually specified, it can contain blank characters, it will still be searched as a whole. Search backward :? {Pattern} or quick search key # There are two methods, the same as the forward search, one is the command line :? {Pattern}; one is the shortcut key # (shift + 3). The conditions and methods used are consistent with those used for the forward search. Continue the last search: The cursor jumps to the first matching mode in the corresponding direction after the previous search command is executed for forward n and backward N, if you want to continue searching for the next matching mode, you can press n or N. N: continue the next search. N: continue the next search. When you find the bottom or top of a file, vim automatically performs a cyclic search. Therefore, it is very convenient and you do not need to worry too much about the search direction. The internal SEARCH Command: vimgrep can be abbreviated as vimvimgrep to search all files in the project in the specified mode, which is consistent with the function of the grep tool. To use the vimgrep command, you must specify two parameters: search mode and search file target. The search mode uses vim's pattern rules, which are common. In addition to specifying a specific file name, you can also use wildcard rules. This is useful. You can use * to match any string or ** to match the folder tree, for example, 1: vimgrep/main/gj **/*. c # Recursively search all the files in the current working directory. c source file 2: vimgrep/main/gj. /*. c # Only search. the vimgrep command of the c source file also has two search options, as shown in the preceding example, g and j. Option g indicates that each matching result is displayed, that is, global. If this option is not added, multiple matching results in one row are only displayed in the search list once. Option j indicates whether to jump to the position of the first matching result after the search is completed, that is, the meaning of jump. If option j is not added, the jump is automatically made without this option, only update the search list. The quick fix List window is displayed in the search result list of vimgrep. the quick fix function has been introduced in previous articles in the series. After using the vimgrep command, if the quickfix window is opened before, the window content is automatically updated to the search result list. If it is not opened, the quickfix list is also updated, but it is not displayed. You need to manually open the quickfix window and then you can see the search result. The redirection in the search result list is consistent with that in the quickfix list. You can set whether to highlight the search results by adding or removing the set hlsearch configuration statement in the vimrc configuration file. View the online help manual related to search: help/: help?: Help vimgrep: help *: help #

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.