Vim cursor Positioning

Source: Internet
Author: User
* Locate the specified row n:

Enter "nG"

Or enter "ngg"

Or enter ": n"

Here, n is the row number of the specified row. Note that sometimes G = gg

* Jump to the top of the screen:

Enter "H"

This is the first non-empty character. Adding a number N indicates the number of rows (such as the N row of the 'nh 'positive number) from the top of the window)

* Jump to the bottom of the screen:

Enter "L"

This is the first non-empty character. Add a number to indicate the number of rows at the bottom of the window (for example, the nth row at the bottom of 'nl)

* Jump to the center of the screen:

Enter "M"

Here, it is parked on the first non-null character

* Jump to the beginning of the file:

Enter "gg"

* Jump to the end of the file:

Enter "G"

* Move the cursor to the end of a sentence:

Enter ")"

* Move the cursor to the beginning of the sentence:

Enter "("

* Move the cursor to the beginning of the paragraph:

Enter "}"

* Move the cursor to the end of the paragraph:

Enter "{"

* Jump to the end of the row:

Enter "$"

* Jump to the beginning of the line:

Enter "^"

Or enter "0"

Here, '^' is the first non-blank character to be moved to the beginning.

* Backward jump to the end of the word nearest to the entire file:

Enter "e"

* Forward to the header of the word nearest to the entire file:

Enter "B"

* Jump to the next word header of the entire file:

Enter "w"

** Intra-row Movement

You can add the number N prefix to indicate that the number is moved N times (for example, '3fc 'indicates that the 'fc' is executed three times .)

* Move to the back of the first character c on the right of the cursor:

Enter "fc"

* Move to the front of the first character c on the right of the cursor:

Enter "tc"

* Move to the front of the first character c on the left of the cursor:

Enter "Fc"

* Move to the end of the first character c on the left of the cursor:

Enter "Tc"

* Repeat the previous f, t, F, and T commands:

Enter ";"

For example, if it is 'fc ', input'; 'is equivalent to 'fc '.

* The previous f, t, F, and T commands are repeated in the opposite direction:

Enter ","

For example, it was just 'fc ', input', and 'equivalent to 'fc '.

**

 

** Moving in a long row:

Here is a small convention: if a long line occupies multiple rows on the screen, we call this line "long rows" and a line on the screen "screen rows ". Therefore, for a 'long line', you need to have multiple 'screen line' to display.

* Move to the next "screen line" in "long line ":

Enter "gj"

* Move a long line to the previous screen line ":

Enter "gk"

* Move to the beginning of the current screen line in "long line:

Enter "g ^"

* Move to the end of the current "long line" screen line:

Enter "g $"

Here, if a row exceeds the screen width, it is displayed in multiple rows on the screen. Although multiple rows are displayed, it is actually one row, when the input is moved up or down, although it is in the last or next line, it is usually displayed in the screen to skip n rows. G $, g ^, gj, and gk are useful when the length is exceeded. J and k move a line in the text. When the length of a line exceeds the line on the screen, j and k may move multiple lines on the screen. At this time, you can use gj and gk to move a line of the screen instead of a line of text. Similarly, g ^ and g $ are the beginning and end of the line on the screen, rather than the end of the line on the text.

**

* Jump to the 50% object by percentage:

Enter 50%"

Here, % is used to redirect by percentage. If you want to jump to 75%, enter "75% ".

** Page flip

It can be a multiple of execution with the numeric prefix N. You can use [PageUP]/[PageDown] to flip pages.

* Flip down:

Enter "[Ctrl] f"

* Page up:

Enter "[Ctrl] B"

* Flip down half page:

Enter "[Ctrl] d"

* Half page up:

Enter "[Ctrl] u"

**

** Page flip relative to the cursor

The result is that the row is rolling in the corresponding direction, and the cursor is still in the original row, as if to drag the text.

* Move the cursor to the top of the window in the row:

Enter "zt"

* Move the cursor in the middle of the window in the row:

Enter "zz"

* Move the cursor to the bottom of the window in the row:

Enter "zb"

* Roll row n to the top of the screen:

Enter "nzt"

* Roll row n to the bottom of the screen:

Enter "nzb"

* Roll row n to the center of the screen:

Enter "nzz"

**

* Set bookmarks:

Enter "ma"

In this way, a bookmark is marked at the current cursor position and its name is. Only lowercase letters are allowed. You can't see the existence of bookmarks, but it is already there. Only bookmarks in the current file can be recorded. The bookmarks will not be retained when you exit vim again. The bookmarks are only a location in the current file. However, after the bookmarks are set, save the file and save the bookmarks.

* To bookmarks:

Enter "'a"

Note: This is not a single quotation mark. It is generally located on the left side of 1 of most keyboards.

* To the row where bookmarks a are located:

Enter "'a"

The single quotes are used to jump to the row where the bookmarks are located.

* To the last file Edited:

Enter "'."

This command is useful, and you do not need to mark it yourself. Note that the quotation marks are entered here, which is accurate to the point.

* To the row where the last edited file is located:

Enter "'."

Note that the rows are accurate and the quotation marks are entered '.

* Return to the position returned by the last insert status:

Enter "'^"

Or enter "'^"

Here '. accurate to the row,'. accurate to the point (row + column ).

* View the list of all current bookmarks:

Enter ": marks"

** Search:* Search for a string:

Enter "/string"

Here, "string" is the string to be searched and will automatically jump to the first "string" behind the cursor.

* Forward search based on the last search:

Enter "N"

* Backward Search Based on the last search:

Enter "n"

* Reverse search for a string:

Enter "?" String"

Here, "string" is the string to be searched and will automatically jump to the first "string" before the cursor. The ": n" and ": N" commands used later are in the opposite direction.

* List the search history records:

Enter "q /"

Or enter "q? "

This will open a new window at the bottom of the vim window to list your search history records.

* Match exactly the words under the current cursor downward:

Enter "*"

Then, you can press 'n' to continue searching.

* Completely match the words under the current cursor up:

Enter "#"

Then, you can press 'n' to continue the search.

* Match the string containing the current cursor word downward:

Enter "g *"

* Match the string containing the current cursor word upwards:

Enter "g #"

**

* Jump to the matching half of the brackets:

Enter "%"

In this way, you can find matching parentheses, that is,),], and}.

* Open the file under the current cursor word:

Enter "gf"

Here, we assume that the current cursor is above the corresponding file name, such as "main. c.

* Switch to the last opened file:

Enter "[Ctrl] ^"

Here, for example, if we enter gf to enter a file, you can enter [Ctrl] ^ to return to the file just now. This command can only switch between the current file and the previous file, but cannot move back multiple steps.

* Move back to a previously viewed location:

Enter "[Ctrl] o"

Popular text editors usually have the forward and backward functions, which can move back and forth between locations that have been browsed in files. Enter "[Ctrl] o" multiple times in vim to run the command back.

* Move forward to a previously viewed position:

Enter "[Ctrl] I"

Or enter "[Tab]"

In this way, if the execution is backward, input "[Ctrl] o" multiple times in vim to execute forward.

Related Article

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.