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. 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: <indentation from line m to line n: input command: m, n> equivalent to command: m> (n-m + 1) from line m to line n, indent to left: Enter the command: m, n <equivalent to the command: m <(n-m + 1) from line m, n lines are indented 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.

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.