Home  >  Article  >  Operation and Maintenance  >  vim fast movement and block selection

vim fast movement and block selection

齐天大圣
齐天大圣Original
2020-06-10 09:09:172850browse

Developers who may have used vim for several years still use the up, down, left and right keys instead of h/j/k/l when moving the cursor. Indeed, hjkl is a bit anti-human and difficult to adapt to. I was completely uncomfortable at the beginning. But if you master and form muscle memory, your speed will be greatly improved.

Cursor movement

To move the cursor in normal mode, please use hjkl instead of the up, down, left and right arrow keys. Here is a good way to play games, haha, this is how I practiced. The online game address is as follows:

https://vim-adventures.com/

The first level is completed using hjkl.

Move between words

Because moving between words is more efficient than cursor movement, moving between words is a daily routine It is used more frequently in China. Here are some keys and instructions for moving between words:

  • wMove to the beginning of the next word

  • WMove to the next The whitespace character

  • e in the word is moved to the end of the word (note the difference between it and w)

  • b is the opposite of w

  • B is the opposite of W

The learning method is the same as above, play vim games.

Search and move between lines

In fact, the fastest way to move within a line is to search for a specified character and then quickly move to above the character. Here are some related keys and instructions:

  • f{char} Search backwards for the character char and move the cursor to the character.

  • F{char} Search forward for the character char and move the cursor to the character.

  • #t{char} Search for the character char and move the cursor to the character before the character.

  • ; The location of the next character

  • , The location of the previous character

##Move the beginning and end of the line

The interline search mentioned above can only search the characters behind the cursor. If you search forward, you cannot complete the requirement. At this time, you need to use F to search forward or move the cursor to the beginning of the line first, and then search again.

  • 0 The number 0 moves the cursor to the beginning of the line

  • $ Moves the cursor to the end of the line

Here is a little trick. You can use 0 w to move to the non-blank character at the beginning of the line, and use $b to move to the end of the last character.

Page move

  • gg Move to the first line

  • G Move to the last row

  • nG Move to the specified row

  • H/M/L View top/middle/bottom

  • ctrl u Page up

  • ctrl f Page down

  • zz Center the cursor

Block selection

#We know that when using the vim editor, the mouse has no effect, and you cannot use the mouse to select a character. Next we will introduce block selection. With it, combined with cursor movement, you can complete the selection of a paragraph of characters.

  • v Select multiple characters

  • V Select lines

  • ctrl v Block selection

  • y Copy

  • d Delete

  • p Paste

The above is the detailed content of vim fast movement and block selection. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn