VIM advanced – move and jump


I believe you already knowhjklIf you don’t know what it means,Look here

hjklIt can also be faster!

Here I (without any inclination) assume that you are using a MacBook, open itSystem Preferences > keyboardTo set the “key repeat” and “delay before repeat” to the fastest.

“Key repetition” determines how fast the system will input a key repeatedly when you press a key for a long time. “Delay before repetition” determines how long after you press a key for a long time, the system will start to input repeatedly. Set both options to the fastest to make the cursor move faster.

However, it is a very elementary, inefficient and avoidable operation to move only by pressing and holding these four keys. If you have decided to use VIM for text editing and still move the cursor in this way, the people will hate you, and your friends and family will laugh at you and spit at you^

What is screen line

If you are using the VIM mode of modern IDE, there should be a line number on the left side of the screen. If you are using VIM in a terminal, you may need to:set numberCommand to open the line number display.

VIM advanced - move and jump

As shown, the cursor is now at the beginning of line 3_N_isiPosition, at this point we pressj, the cursor moves to the fourth line instead of theNisiBelowqui. that is becausejkIt moves according to the actual line, that is, the actual line of text in the document. When the length of a line of text exceeds the width of the window, VIM will fold the line, and a line in the file may be displayed as several lines on the screen.

In VIM, you want to move up and down the screen line (in this case, from the_N_isiMove toqui), can be usedgjandgkOrders.

Move to the beginning and end of the line0and$Commands can also be divided into screen lines and actual lines. You can use theg0g$

Word based mobility

command Move position
w Go to the beginning of the next word – forward / word
b Go to the beginning of the current word and the previous word-backward
e To the end of the current word and the next word
ge Go to the end of the previous word

eaLinked together can realize “move to the end of the current word and insert after it”. Remember it, and use it very frequently.

Find character

f{char}F{char}t{char}T{char}These four commands are the fastest way to find / move in vim and can be remembered asfind、till。

Among them,f{char}Represents to move the cursor to the next line of the current line{char}, andtRepresents to move the cursor to the next line of the current line{char}The character before the. The upper case corresponding to these two commands,F{char}T{char}, respectively.

For example,foRepresents to move the cursor to the next line in the current rowo

Want to find the next one, the second one, the third oneoYou don’t need to press it againfo, VIM provides us with the command to repeat this step:;It means to continue to look down,,Keep looking up.

The use of these commands is not only to move the cursor, but also to cooperate with the userd delete、c change、v visual、yYank is also very easy to use.

For example,dtnDelete from current cursor to next cursornBefore “can be simply remembered as” delete “till n」。ctmDelete from current cursor to next cursornBefore entering the insert mode, that is, changetill m」。vfa, select from current cursor position to next a,yfa, copy from current cursor position to next a.

In practice, in anddcWhen used together, tend to usetTIn other mobile or andvyWhen used together, tend to usefF

But,fFtFThere are also limitations: only one character can be found, and only in the current line.

command Move position
fF{char} Move to up / next{char}
tT{char} Move to up / next{char}First / last character of
, ; Move forward / backward

Cross line text search

It can be used in vim/{char}⏎To carry out multi character, cross line search, similar to pressing CMD + F in IDE and then entering{char}And press enter for the effect.

The previous / next command that matches it isN/nnExt), uppercase forward, lowercase backward.


Sometimes, we may have to jump back and forth between two positions. At this time, the most convenient way is to use “mark”.

m{a-zA-Z}The current cursor position is marked with the letter immediately following the input, such asmaMark current position asa. After marking, when we move to another place, just two keys can jump back.

There are two ways to jump back to the mark just mentionedaFor example,'aJumps to the first non blank character on the line of the tag, and `a It will not only jump to the row of the tag, but also navigate to the exact location of the tag, that is, the column of the tag.

Most of the time, just use it repeatedlymmand `m You can jump back and forth easily.

VIM also provides some default logos for us to jump, as shown in the following table:

command Jump to
` ` The position of the current file before the last jump action
`. Where was last modified
`^ Where was last inserted
`[ The starting position of the last modification or copy
`] End position of the last modification or copy
`< The starting position of the last highlighted selection
`> The end position of the last highlighted selection

Jump and select in brackets

There are often parentheses, angle brackets, square brackets, quotation marks, HTML tags and other contents in the code. VIM also has a series of commands to operate the text related to parentheses. In VIM, we call the contents operated by these commands “text objects”.

A text object consists of two characters, the first of which is alwaysiora. You caniImagineiOr elseiNside, andaImaginearound。 Next, use some examples to explain the specific usage of text objects.

command Selected range
vi] Select the interior enclosed by square brackets
va] Select the content surrounded by square brackets,includesquare brackets
vi" Select the inside enclosed by double quotation marks
va" Select the content enclosed in double quotation marks,includeDouble quotation marks
vat Select a pair of HTML tags
vit Select the HTML tag inside

VIM advanced - move and jump

vi" vs va"

Similarly, text objects can be collocatedd delete、c change、yFor example:da"-Delete a pair of double quotation marks and the contents between themaround “),cit-Modify the content within a pair of HTML tags.

iaYou can also match the above mentionedwUse, for example:diwDelete the current word,diwDelete the current word and the space after itcvyIt’s similar.

Jump between brackets

%The command allows us to jump back and forth between matching brackets. This command does not require us to manually specify the bracket to jump, but automatically jump according to the bracket above the current cursor position.

Recommended Today

[rust] basic data type

This article introduces the built-in data types provided by rust. Boolean type Boolean typeLogical values representing yes and No. It has two values:trueandfalseGenerally used in logical expressions, and, or, and not operations can be performed: fn main() { let x = true; let y: bool = ! x; // False, inverse operation let z = […]