The help entry for the commands used in this section:
In the previous article we introduced some commonly used mobile commands, this article will continue to introduce more commands, so that you in the document free shuttle.
[Using Jump Tables]
In vim, many commands can cause jumps, and vim remembers to record the position of the cursor before the jump to the jump table, and provides some commands to jump to the jump table. To know which commands are causing jumps, see ": Help Jump-motions".
you can return to the last jump by using the command "" "(two single quotes) and" ""(two anti-quotes, one key on the keyboard and "~"). For example, the current cursor is in line 1234th of the file, and then I use the "4321G" command to jump to line No. 4321, and if I press "" "or" ", it jumps back to line 1234.
Because these two commands also belong to the Jump command, the No. 4321 line is also credited to the jump table, and if you use these two commands again, you will find yourself jumping back to line No. 4321 again.
The two commands are a little different, "" isaccurate to the column when jumping, and ""does not go back to the column where the cursor is at the jump, but instead puts the cursor on the first non-whitespace character.
If you want to go back to the older jump position, use the command "Ctrl-o", and it corresponds to "ctrl-i", which jumps to the updated jump location (: Help Ctrl-o and: Help ctrl-i). These two commands can be preceded by numbers to represent multiples.
Use the command ": Jumps" To view the Jump table (: help:jumps).
[Use tags]
Mark (Mark) is the precise positioning technology provided by VIM, which is equivalent to GPS technology, so long as you know the name of the tag, you can use the command to jump directly to the location of the tag.
The tags in Vim have a name, which is represented by a single character. Both uppercase and lowercase letters (a-za-z) can be tagged names, where the positions of the flags can be set by the user, while the number marker 0-9, along with some punctuation marks, is not set by the user and is set by VIM.
We mainly talk about the use of alphabet marks, and for digital markers and punctuation marks, please refer to the Help manual (: mark-motions).
Lowercase letters are limited to buffers, that is, each buffer can define its own lowercase letter tags, and lowercase letters between buffers do not interfere with each other. If I set a tag T in file A, then you can also set a tag T in file B. Then in file A, you can use the "' t" command to jump to the mark T location of file A; in file B, you canjump to the mark T position of File B with the "T" command. If the file is deleted in the buffer list, the lowercase letter mark is lost.
The uppercase tag is global, and it is valid between files. If you define a tag T in file A, when the command "T" is used,it jumps to the mark T position of file A, regardless of which file you are currently in.
Setting a tag is simple, and using the command "m{a-za-z}" is fine. For example, the command "MT" sets the current cursor position to mark T, and the command "MT" sets the current cursor position to mark T. (: Help m)
To jump to the specified tag, use the command "' {a-za-z}" or "{a-za-z}". For example, the command "T"jumps to the Mark T, and the command "T"jumps to the Mark T. ( : Help ')
The difference between single and inverted quotation marks is the same as above, "'" is accurate to the column when jumping, and "'" does not go back to the column where the cursor is at the jump, but instead places the cursor on the first non-whitespace character.
Tags can also be deleted, using the command ":d elmarks" To delete the specified tag. The command ": Marks" lists all the tags.
About tags, there are two very useful plugins, one is Showmarks, the other is called Marks browser.
Showmarks is one of my most used plugins, which uses the sign function provided by VIM and the highlight function to show the location of the marker. Then, after you set a tag, it will display the name of the tag in your Vim window and highlight the line.
Unzip it in your $home/.vim directory and then make a simple setup. In my VIMRC, the Showmarks is configured as follows:
First, enable the Showmarks plug-in, and then define Showmarks to show only all uppercase and lowercase, and highlight both of these tags; the location of the tag is not displayed for files of type Help, Quickfix, and non-modifiable buffers.
You can define your own color to highlight the line where the tag is located, here is my definition, I put it in my own ColorScheme file:
"For Showmarks pluginhi showmarkshll ctermbg=yellow ctermfg=black guibg= #FFDB72 Guifg=blackhi Showmarkshlu ctermbg=magenta ctermfg=black guibg= #FFB3FF
Some shortcut keys have been defined in the Showmarks plugin:
<LEADER>MT -Open/close Showmarks plug-in <leader>mo -Force open Showmarks plug-in <leader>mh - Clears the current line's markup <leader>ma -Clears all markers in the current buffer <leader>mm
I use "<leader>mm" and "<leader>mh" most often, it is very convenient to use. In my VIMRC, I define leader as ","so I use ", MM" and "MH" every timeto set up and remove mark.
In Vim 7.0, if the uppercase tag is defined, then the function line () will return the row number of the tag in any buffer, causing Showmarks to display the uppercase tag in each buffer. So I patched this plugin to fix the problem.
Vim 7.0 can also really delete a mark tag, so also changed the Showmarks plugin's delete tag function. The original function does not actually delete the tag when it is deleted, but it points to the first line of the buffer, and now it actually deletes the tag.
If you want to use my patch for Showmarks, please click here to download the Showmarks patch.
Usage:
- Save the patch to a directory, for example:/tmp/showmarks.vim.patch
- CD to your. Vim directory: CD ~/.vim
- Run command:cat/tmp/showmarks.vim.patch | patch-p0
The Marks browser plugin can display the position of the lowercase tags defined in the current buffer, which is useful when you cannot match the name and location of the tag.
After downloading it to your $home/.vim/plugin directory, I have defined a shortcut key for it:
In this way,you can open the Mark browser window by using ", MK" directly.
Shows the effect of these two plug-ins when they work. I have defined three tokens in the file, one uppercase mark A, two lowercase tags a and t. The topmost window is the Mark browser window, and the certain and sign markers in the main editing window are placed by the Showmarks plugin.
Click to view larger image
[Fold Line]
Moving around a file may be laborious when the file is large. This time, you can according to your own needs to temporarily not access to the text folded up, both to reduce the use of space, movement speed will be much faster.
VIM provides several ways to fold, either manually or by indentation, syntax, or by using an expression.
Program files generally have good structure, so it is a good choice to fold according to the syntax.
To enable folding, first enable the 'foldenable' option, which is a partial-to-window option, so you can define different folds for each window.
Next, set the 'foldmethod' option, for the program, we can choose to collapse according to syntax highlighting. Note that to collapse based on syntax highlighting, you must turn on file type detection and syntax highlighting, see my previous article.
Here is the setting in my VIMRC, which uses automatic commands, and if you find that the file type is C or CPP, enable the collapse feature and collapse by syntax:
Autocmd FileType C,cpp
Note that many of Vim's commands, option names are abbreviated, can be seen in the Help manual, or can be shortened to help, for example, to see the 'foldmethod' option, you can just enter ":" ".
After folding the effect see:
Click to view larger image
The line shown on a black background in the figure is the collapsed row, and vim shows how many rows were folded in the fold and the contents of the starting line. Notice the bottom left of the "__tag_list__" window, there is also a folding in this window, I put macro, typedef, variable a few items folded up, and the function of the folding open. You can also see the difference from the left-most folding bar (: Help Fold-foldcolumn): "+" is displayed before the collapsed text, and "|" is displayed before the folded open.
The folded background color and display text can be modified, see the Help Manual (: Folding).
The following command is used to turn folding on and off:
zo– the collapsed zo– loop under the open cursor opens the fold under the cursor, that is, if there is a multilevel collapse, each level will be opened zc– collapse under the cursor
For more commands, please refer to the manual (: Help folding).
VIM provides a number of commands to move quickly between folds:
[Z – to the beginning of the current open collapse ]z– to the end of the current open collapsed zj– Move down to the beginning of the next collapsed
I usually don't like to fold up the text because I prefer to see all the text at a glance. You can decide whether to enable folding according to your preferences.
To say a little more, manually created folds can be saved in the session file, so the next time you enter Vim can be loaded before the collapse created, see : Help ' sessionoptions '.
[Move in the program]
The author of Vim is a programmer, and it is not difficult to understand why Vim provides numerous commands to move through the program. This includes both the use of tag files and Cscope in our previous articles to jump between tags, as well as numerous commands that move through functions, annotations, preprocessing directives, program segments, and other program elements.
This article no longer describes these commands in detail, as programmers, be sure to familiarize usr_29.txt! These commands can help you move in handy in the program.
Introduce two plugins here, enhance the function of moving in the program, one is A.vim, the other is matchit.
The A.vim function is very simple, it helps you to switch between the source file and the header file, this simple function, but very practical, at least it saves me a lot of time.
After downloading the A.vim, put it in your. Vim/plugin directory.
If you are browsing the C language source file, you want to modify its corresponding header file, just enter ": A" command, switch to the head file (need source files and header files in the same directory). The A.vim plugin also defines some other commands and shortcut keys, see its Help manual.
In Vim, the "%" command jumps to the item that matches the current project. For example, when the cursor position is in "{", press%, the cursor jumps to the corresponding "}" ( : Help%).
However, the% command provided by VIM can only be jumped in parentheses, or at the beginning and end of the C comment (/*/), or C-compile preprocessing instructions. For other program structures, such as the html,% command cannot be from the
The Matchit plugin expands the function of the% command to allow the% command to jump between the start and end tags of other programming languages.
After downloading, put this plugin into your. Vim/plugin directory, you can use% to jump between various start/end tags, currently, it can support Ada, ASP with VBS, Csh, DTD, Essbase, Fortran, HTML, JSP (same as HTML), LaTeX, Lua, Pascal, SGML, Shell, TCSH, Vim, XML and other languages.
[Move in insert mode]
The move commands described above are used in normal mode, and if you want to move in insert mode, read: Help ins-special-special.
Do you really need to move in insert mode? I hardly ever! Usually I press ESC to return to normal mode and then move on, and when you get used to it, you'll find that it's more efficient.
Summary
You will find that the content of this article is very similar to the Usr_03.txt help documentation. Yes, as long as you have learned the commands listed in Usr_03.txt, you have mastered the most common and useful vim movement commands (: Help Usr_03.txt).
If you want to learn more about mobile commands, read the Motion.txt and remember the keys that you are most likely to use. When your fingers are able to use these commands without hesitation, you can do so in vim, moving like a fly.
[Reference Document]
- VIM Handbook
- VIM Chinese Handbook
<< return to VIM using advanced: Directory
Original article, please read the footer of the licensing method, reproduced Please specify: Reproduced from the Easy Water Blog [http://easwy.com/blog/]
This article link address: http://easwy.com/blog/archives/advanced-vim-skills-advanced-move-method/
The footnote information of the article is automatically generated by the WordPress Wp-posturl plugin.
Related articles
- Vi/vim Use advanced: Refers to the random movement, moving flies (a)
- Vi/vim Use advanced: flower-like beauty-syntax highlighting
- Vi/vim Use advanced: Smart Completion
- Vi/vim Use advanced: auto-complete
- Vi/vim Use advanced: Use tag file
- Vi/vim using advanced: Using Sessions and Viminfo
- Vi/vim using advanced: File browsing and buffer browsing
- Vi/vim Use advanced: Use GDB debugging in Vim – use Vimgdb
"Reprint" Vi/vim use advanced: Refers to the random movement, the movement flies (two)