Vi/vim Use advanced: Refers to the random movement, moving flies (a)
<< return to VIM using advanced: Directory
The help entry for the commands used in this section:
Vim offers a plethora of ways to move, but we don't need to master all of these commands, just the ones that are best for you. Because our ultimate goal is not to become a vim master, but to edit the text more efficiently.
The commands we describe below, if not specifically stated, are commands that are used in normal mode.
The help entry for these commands is the name of the ": Helper Command." For example, for the "J" command, see the Help for it, using ": Assist J".
[Up or down]
Let's start with the simplest and most frequently used H, J, K, L.
The movement of H, J, K, L has become one of the hallmarks of vim and is also accepted by more software. If you're still moving up and down the left and right cursor, it means that you don't really accept Vim's philosophy, if you really want to make vim your editing tool, start with H, J, K, L!
H, J, K, l move left, bottom, up, and right respectively. As with many VIM commands, you can add a number to the key before these keys to represent a multiple of the move. For example, "10j" means moving down 10 rows; "10l" means moving the 10 columns to the right.
By default, the H and L commands do not move the cursor out of the current line. If you have reached the beginning of the line, no matter how many times the H key, the cursor always stays at the beginning of the line, the L command is similar. If you want the H and L commands to move out of the current line, change the settings for the ' whichwrap ' option (: Help ' whichwrap ').
The author of Vim, when arranging key functions, can also see the meaning of H, J, K and L in other key bindings.
For example, a command that makes the cursor move up or down between multiple windows is Ctrl-w h/j/k/l (: Help Ctrl-w_h, ...) ;
Again, the command to move the window position up or down, is Ctrl-w h/j/k/l (: Help Ctrl-w_h, ...). Note that here the H, J, K, L are capitalized.
Page
You can also use PageUp and PageDown when you page through VIM, but like using the left and right cursors, your fingers move out of the main keyboard area. Therefore, we usually use ctrl-b and ctrl-f to page pages, which are functionally equivalent to PageUp and PageDown. Ctrl-b and ctrl-f can also be preceded by numbers to indicate how many pages are flipped up or down.
Vim can also be turned up or down half page, the number of rows specified, see the Scroll.txt Help manual page.
[Move in file]
VIM provides a number of commands that can be conveniently moved in a file.
The command "GG" moves to the first line of the file, and the command "G" moves to the last line of the file.
The command "G" can be preceded by a number, here, the meaning of the number is not a multiple, but you intend to jump the line number. For example, if you want to jump to the 1234th line of a file, just enter "1234G".
You can also jump by a percentage, for example, if you want to jump to the right middle of the file, enter "50%", or if you want to jump to 75%, enter "75%". Note that you must first enter a number and then enter "%". If you enter "%" directly, the meaning is completely different. ": Help N%" read more details.
Move in the file, you may lose your place, then use the "ctrl-g" command to check your location. This command displays the location of the cursor and other information. To avoid getting lost, you can open the line number display, and use the ": Set Numbers" command, the travel number will be displayed before each line, can be more convenient to locate the jump (: Help ' number ').
[move to specified character]
All of the above commands are moved between rows (except H, l), that is, moving from the current line to another line. If we want to move quickly within the current line, we can use the F, T, F, t commands.
The "F" command moves to the specified character on the right side of the cursor, for example, "FX", which moves to the first ' X ' character on the right side of the cursor. The "F" command looks in the opposite direction, that is, to the specified character on the left side of the cursor.
Thedifference between the "T" command and the "F" command is that it moves to the right of the cursor before the specified character. For example, "TX" moves to the front of the first ' X ' character to the right of the cursor. The "T" command is a reverse version of the "T" command, which moves to the right of the cursor after the specified character.
These four commands move the cursor only in the current line, and the cursor does not span the carriage return line break.
You can use a number in front of the command to indicate a multiplier. For example, "3fx" means moving to the 3rd ' x ' character on the right side of the cursor.
";" The command repeats the previous input F, T, F, t command, and the "," command repeats the previous input's F, T, F, t command in the opposite direction. You can also use numbers to represent multiples before these two commands.
[Beginning/end of line]
In vim, the command to move to the beginning of the line is very simple, which is "0", which is the number 0, not the capital letter O. The command to move to the end of the line is "$".
There is also a command "^", which can be moved to the first non-whitespace character at the beginning of the line.
In the regular expression we will see that the "^" character represents the beginning of the line, and the "$" character represents the end of the row. Can be seen, the vi/vim of the key arrangement, indeed is the ingenuity.
[Move by Word]
We know that the main body of an English document is a word, which is usually separated by white space characters, including spaces, tabs, and carriage return line feeds. VIM provides a number of commands to move by word.
To move according to words, first separate the text into separate words. When vim separates words, the characters in the 'iskeyword' option are the constituent characters of the word. That is, a word (word) is made up of characters defined in the 'iskeyword' option, which precedes and follows characters that are not in the character defined by the 'iskeyword' option. For example, if we set the 'iskeyword' option to "a-z,a-z,48-57,_", then "foobar_123" is made into a single word, and " FooBar-123"is made into three words:"FooBar","–"and"123". 48-57 in "a-z,a-z,48-57,_" represents the number 0-9 in the ASCII code table.
VIM, move the cursor to the beginning of the next word, use the command "W", move the cursor to the beginning of the previous word, use the command "B", move the cursor to the end of the next word, use the command "e", move the cursor to the end of the previous word, use the command " GE ".
The above commands usethe characters in the 'iskeyword' option to determine the boundaries of the word, as well as a few commands that only take whitespace as the " word ". Of course, the word here is no longer a traditional word, but a string of non-whitespace characters. The command "W" moves the cursor to the beginning of the next string, the command "B" moves to the beginning of the last string, the command "E" moves to the end of the next string, and the command "GE" moves to the end of the last string. Compare it with the above command and find out what the rule is?
[H/M/L]
Note: These commands are capitalized.
Using the h/m/l three keys, you can have the cursor jump to the top, middle, and bottom of the current window, resting on the first non-empty character. The h command and the L command can also be added with a number, but the meaning of the number is no longer multiples, but the number of rows from the top and bottom of the window. For example, "3H" means that the cursor moves to the 3rd row from the top of the window, and "5L" means that the cursor moves to a position 5 rows from the bottom of the window.
[Relative to the cursor roll screen]
When reading the code, sometimes we need to scroll through the position of the cursor and move the top, middle, or bottom of the cursor in the same row, so we can use "zt", "zz" and "ZB". The advantage of this scrolling mode is that you can always use the current cursor position as a reference, without flipping pages, and finding yourself disoriented. ^_^
Find
Find, or you can do it as a fast-moving way.
Find in Vim is very easy, enter "/" directly in normal mode,and then enter the string you want to query, enter, jump to the first matching place. "/" is looked down, and "?" To search in the opposite direction. The command "N" repeats the last Lookup command, and the command "N" repeats the last lookup command, except that it looks in the opposite direction.
Vim saves the history of the search, and you can enter the "/" or "?" , use the UP and down cursor keys (or ctrl-p/ctrl-n) to look over the history, and then perform the lookup again.
Also you can use "q/" and "Q?" command, open a new window at the bottom of the Vim window, this window will list your search history, you can use any vim editing command to edit the contents of this window, and then press ENTER, you will find the contents of the line where the cursor is located.
Click to view larger image
In, I opened the command-line window with the "q/" command, which lists the strings I looked for earlier. Now I want to find the "check_swap", then skip to line No. 399, change "check_tty" to "check_swap" and press ENTER. At this point vim goes to find the location containing "check_swap". This is a simple example, you may think that command-line window is not necessary, but if you are looking for a very long regular expression, you will find it very useful.
There are many options related to finding in vim, the most common being 'incsearch', 'hlsearch', 'ignorecase'.
- 'incsearch' means that when you enter a search, Vim starts to match the content you entered and displays the matching location. Open this option and you can see the results of the search instantly.
- The 'hlsearch' option indicates that all matching items are highlighted.
- The 'ignorecase' option indicates that the case is ignored when searching.
Usually I will open the 'incsearch' and 'hlsearch' options, turn off the 'ignorecase' option.
The next article describes some of the other ways in which vim moves, and these move commands require a higher level of skill.
[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-basic-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, the movement flies (two)
- Vi/vim Use advanced: auto-complete
- Vi/vim Use Advanced: Save project-related configuration
- Vi/vim Use advanced: Smart Completion
- Vi/vim Use advanced: The Programmer's weapon –cscope
- Vi/vim Use advanced: Use tag file
- Vi/vim Use advanced: Use GDB debugging in Vim – use pyclewn
- Vi/vim using advanced: File browsing and buffer browsing
"Reprint" Vi/vim use advanced: Refers to move freely, moving flies (a)