VIM series: indent adjustment, automatic completion, collapse, jump

Source: Internet
Author: User
VIM series: indentation adjustment, automatic completion, collapse, jump indent adjustment, automatic completion, collapse, jump to these vim operations are not at the beginning, I will not, familiar with the project development process, this article mainly records the commands for these operations, as well as find help, for sharing is also a memo. Shrink... news & VIM use series: indentation adjustment, automatic completion, collapse, jump indent adjustment, automatic completion, collapse, jump to these vim operations are not at the beginning, I will not, familiar with the project development process, this article mainly records the commands for these operations, as well as find help, for sharing is also a memo. The help search command for indent adjustment: help shift-left-right, or directly help any command for indent adjustment below. The indent adjustment operation is related to the shiftwidth parameter value in vim. in the vimrc configuration file, the shiftwidth has been set to 4, indicating that the width of each indent is 4 spaces long, you can modify it by referring. The following are common indent shortcut operations and commands: the current line is indented once to the right: Operation> or enter the command:> The current line is indented once to the left: Operation <or enter the command: <从第m行起,到第n行止向右缩进一次: 输入命令 :m,n> Equivalent to the command: m> (n-m + 1) indentation from line m to line n at the left: input command: m, n <equivalent to the command: m <(n-m + 1) indent n rows from line m to the right once: input command: m> n is equivalent to command: m, m + n-1> a total of n lines are indented to the left from line m: enter the command: m auto-completion when the SourceInsight tool is used in windows to edit the code, the auto-completion function of functions and variables is very powerful and popular and can greatly improve work efficiency. The same functions are also available in vim, which may not be so convenient. some buttons need to be added slightly (you may need to make some complicated settings yourself to enable the automatic pop-up of SourceInsight ), but it is enough. Auto-completion can be divided into two parts: automatic completion of words and automatic completion of symbols and functions in program code. in essence, auto-completion is based on words, however, the completion in the code has its own particularity, mainly because of the completion of structure members. Therefore, the Operation Commands of the two are slightly different. Automatic word completion: In inset mode, press the following key combination, ctrl + x ctrl + n or ctrl + x ctrl + p, or press ctrl + n or ctrl + p, the former will list the words that match the conditions in the current buffer, and the latter will also include the words that match the conditions in the dictionary. View help details: help ^ x ^ n code auto-completion: In inset mode, press the following key combinations, ctrl + x ctrl + o, and view the help details :: the automatic completion environment of help ^ x ^ o code requires a little more complexity. First, it uses the Completion method Omni Completion, which involves the omnifunc setting of the vim variable, which further involves the identification and Association of file types. Therefore, the first step is to enable the file type automatic detection in vim, which has been set in the previous vimrc configuration file: filetype on. By default, vim can recognize many file types, such as C source files, java program files, and html program files. in this way, omnifunc values are automatically set based on the file type. Second, omni completion requires the use of information in the tags file, and preferably the tags file generated by the Exuberant Ctags tool. Therefore, the second step is to install the tool and use it to generate the tags file of the project. Finally, omni is supplemented by information in tags. Therefore, it can only complete global variables, global types, functions, structure members, and class members in the code, the partial variables in the code cannot be supplemented. the partial variables are completed using the above word completion method. Supplement: many C-standard functions and system calls are used in project development. header files containing these functions are not included in the tags file, so automatic completion is not prompted, to improve efficiency and achieve more comprehensive automatic completion, you can add the tags of standard functions and system functions to vim by creating the tags file of the system header file first, then add it to the vimrc configuration file, as follows: 1 ctags-R-f ~ /. Vim/cmdags/usr/include/usr/local/include and set tags + = ~ /. Vim/cmdags settings are added to the. vimrc configuration file in the second article. In this way, not only the completion is more efficient, but also the jump is more comprehensive. Select from the completion list, move down: ctrl + n, move up: ctrl + p, and then press any key to end the completion. Note that this key will still be input, so the good choice is to press the space key. Code Folding allows you to easily control the main logic of the program and facilitate code reading and searching. To use folding, you must first set the folding mode, that is, to set the value of fdm (abbreviation of foldmethod) in vim. in the configuration file of the second series, you have set the teacher to indent, that is, the code is automatically folded based on the indentation. Vim can be set in six ways: help fold. Common fold-on and-off operations are as follows: fold code: shortcut key zc recursive fold code: shortcut key zC cancel code fold: shortcut key zo recursive cancel collapse code: press the shortcut key zO to collapse all the code in the file: Press the shortcut key zM to cancel the collapse of all the code in the file: Press the shortcut key zR to fold line m to line n: Open the fold, run the command :: m, nfoldopen, close folding, use the command: m, nfoldclose to move up and down in the folding code: in the folding: [z] z in the folding: to jump to a function in SourceInsight, you just need to press and hold the shift key, and then click the left mouse button. in vim, it is also very simple and fast, press ctrl _]. of course, the prerequisite is that the tags file has been generated and configured. View the help details: help ^]. Jump to the function, global structure, global variables, and other tags: key combination ctrl _] return the jump position from the tag: key combination ctrl_t jump to the global variable: the shortcut key gD jump to the local variable: the shortcut key gd returns to the previous operation position (the last cursor position): the combination key ctrl_o returns to the next operation position (the updated cursor position ): the combination key ctrl_ I was originally intended to put the quick fix operation in this article, but it took nearly an hour to write this article. let's write it in the next article in the series, quick fix is also a small part of vim that has little to do with text editing and code editing. it mainly involves code compilation and debugging, greatly improving the efficiency of the compilation-correction-compilation process, it is also a major feature of vim. I have always felt that it is a great pity that we cannot directly compile in SourceInsight. this regret has been compensated by vim, haha.
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.