Linux VI Move CURSOR command

Source: Internet
Author: User

Move cursor

On: K NK: Move up n rows 9999k or GG can move to the first line G move to the last row
Under: J NJ: Move Down n rows
Left: H NH: Move n columns to the left
Right: L nl: Move n columns to the right

W: Cursor moves forward with a word NW: the cursor moves forward n the word cursor to the first letter of a word
B: Contrary to W
E: Cursor moves forward with a word ne: the cursor moves forward n the word cursor to the last letter of the word
GE: Contrary to E

$: Move cursor to end of line n$: Move to line end of Nth row
0 (Num): Moves the cursor to the beginning of the line
^: Move the cursor to the first non-empty character at the beginning of the line

F<A>: Moves the cursor to the character a of the current line,nf<a> moves the cursor over the nth a character of the current line
F: On the contrary

%: Move to the parentheses that match the system up (),{},[],<> and so on.

NG: Move to Nth line G: to the last row

Ctrl+g get the current cursor position in the file

Page forward: ctrl+f
Move Down half screen: ctrl+g
Page Backward: ctrl+b

Save:
: q! : Do not save to exit
: e! : Discard modify file contents, reload the file edit
: Wq: Save and exit

DW: Delete A word, you need to move the cursor to the first letter of the word, press DW, if the cursor is anywhere in the word, use the Daw
DNW: delete N words
Dne: can also, just delete to the end of the word
DNL: Delete n letters to the right
DNH: Delete n letters to the Left
DNJ: delete n rows down
DNK: delete n rows up
d$: Delete the letter of the current cursor to the end of the line
DD: Delete a row
Cnw[word]: change n word to Word
cc: Change whole line
C $: Change to end of line

J: Remove line breaks, move the cursor to a row, press Shift+j to delete line breaks at the end of the row, and next line up.
U: Undo the previous operation
Shif+u (U): revokes all operations on the row.

: Set Showmode: Setting display mode of operation

O: Another line below the current line
O (shift+o): Another line above the current line

NK or NJ: The cursor moves up or down n lines, N is a number
an! "ESC": Add n exclamation marks (!) after line
NX: Perform N-times x (delete) operations

ZZ: Save the current document and exit Vim

: Help: View the assistance document, and in this, press CTRL +] to enter the hyperlink and press Ctrl+o to return.
: Help subject: Look at a topic for assistance, ZZ exit Help

: Set Number/set nonumber: Display/Do not display line numbers
: Set Ruler/set Noruler: Show/not show ruler

/pattern searching for a character pattern in the positive direction
? pattern Reverse direction search for a character pattern
Then press N to continue looking down.

Place the cursor over a word and press the X key to find the word.
Find the whole word:/\<word\>

: Set Hlsearch highlight the found word
: Set Nohlsearch Turn off Change function

M[A-Z]: Mark in the text, the mark number can be a A-Z 26 letters, with ' A can be moved to mark a

R: Replace the current character
NR character: Replaces the current n characters

Find Replacements:
Way1:
/Word: Find a Word
CW "Newword": Replace with new word
N: Continue to find
.: Perform a replacement

Way2:
: s/string1/string2/g: Replace string1 with string2,g in a row to indicate that a C is required to confirm
: num1,num2 s/string1/string2/g: Replace string1 with string2 in the middle of line NUM1 to num2
: 1,$ s/string1/string2/g: Replace string1 with string2 in full text


V: Enter visual mode
"ESC" exits
V:shift+v visual mode for entering rows
Ctrl + V: Enter as block operation mode with O and O to change the size of the selected edges.

Paste: P, which is pasted with x or D deleted text
Copy:
YNW: copy n words
YY: Copy one line
YNL: Copy n characters
y$: Copy the current cursor to the end of the line
Nyy: Copy n rows
Finished with P paste

: Split: Split a window
: Split file.c: file.c separate window for another file
: Nsplit file.c: Separate window for another file file.c and specify its number of rows
Ctrl+w switch in the window
: Close: Closes the current window

Insert the same content as include< on all rows, as follows:
Move the cursor to the location where you started the insertion, press CTRL + V to enter visual mode, and then select a good module
Press I (shift+i), insert the text you want to insert, and press [ESC] to finish.

: Read FILE.C Inserts the contents of the file file.c below the current cursor
: 0read file.c Inserts the contents of the file file.c at the beginning of the current file (line No. 0)
: Nread file.c Inserts the contents of the file file.c after the nth line of the current file
: Read!cmd: The output of the external command cmd is inserted below the current cursor

: N1,n2 Write Temp.c writes N1 in this file to N2 line to temp.c this file

Ctrl+l Refresh Screen
SHIFT + < move left one line
SHIFT + > Move right one line

U:undo
Ctrl+r:re-do
J: Merge one row
Ctrl+p Auto-complete function
Ctrl+g view current file full path

Q[a-z] Start recording but before the action is a macro, the name can be "A-Z", and then use Q to stop recording the macro.
Use Reg to display all currently defined macros, using @[a-z] to execute the macro [a-z] at the current cursor.


Movement by screens

CTRL + F-Scrolls forward one screen, the cursor moves to the first line of the next screen

CTRL + B-Scrolls backward one screen and the cursor moves to the last line of the previous screen

CTRL + D-Scrolls forward half-screen and the cursor moves to the middle line of the screen

CTRL + U-Scroll backward half screen, cursor moves to the middle of the screen line

CTRL + E-Scrolls forward one line, the cursor position remains the same

CTRL + Y-Scrolls backward one line, the cursor position remains the same

If you want to scroll the screen but do not want to move the cursor position, you can use the z command.

Zenter-Scroll the screen to move the line of the cursor to the first line of the screen

Z. (dot)-scroll the screen to move the line of the cursor to the middle of the screen

Z (minus)-scrolls the screen so that the cursor line moves to the last line of the screen

Adding the n prefix to the z command means moving the nth row to the appropriate position on the screen, such as 200zENTER, to move the No. 200 line to the first line of the screen.

Sometimes some system messages in the system will affect your editing work, then use the command CTRL + L to make VI refresh the screen.

H-cursor moves to the first line of the current screen

M-cursor moves to the middle row of the current screen

L-cursor moves to the last line of the current screen

NH-the cursor moves to the current screen starting from the first line down the nth line

NL-the cursor moves to the current screen starting from the last line up to the nth row

ENTER, +-Move the cursor to the first character of the next line

-(minus sign)-cursor moves to the first character of the previous line

The above three commands move the cursor to the first position in a row that is not a blank or tab character.

^-the cursor moves to the first non-whitespace character in the line

0-Cursor moves to the first character in a line, including white space

n| -The cursor moves to the nth character of the current line

Movement by text blocks

E-cursor moves to the end of the word

E-cursor moves to the end of the word, ignoring punctuation

(-cursor moves to the beginning of the current sentence

)-The cursor moves to the beginning of the next sentence

{-cursor moves to the beginning of the current paragraph

-Cursor moves to the beginning of the next paragraph

[[-Cursor moves to the beginning of the current section

]]-the cursor moves to the beginning of the next section

Look for the end of the sentence, vi find punctuation:? , . !。 There are two cases where VI is considered to be the end of a sentence, which is followed by more than two spaces, or one of the last non-whitespace characters in a line above the punctuation.

Movement by Searchs

/Pattern -searches for pattern at the end of a file, starting at the cursor position, and if it can be searched, the cursor moves to the first character of pattern

? pattern -searches for pattern from the beginning of the cursor, and if it can be searched, the cursor moves to the first character of pattern

N-Search for the next matching pattern in the same direction

N-Search for the next matching pattern in the opposite direction

/enter-Effect with command n

? ENTER-effect Same as command N

Set option Wrapscan sets whether to loop the search. If the Wrapscan option is turned on, the search continues from the beginning or end of the file after the last pattern is searched, and if the Wrapscan option is turned off, an error message is displayed after the last pattern is searched.

In-line search

The following commands perform a search only on the current line and do not move the cursor to another row. (The X in the following command can be any character)

FX-Find the character x backwards from the cursor and move the cursor over the character X

Fx-finds the character X forward from the cursor and moves the cursor over the character X

TX-Finds the character x backwards from the cursor and moves the cursor to the previous character X

Tx-finds the character X forward from the beginning of the cursor and moves the cursor to a character after X

; -Repeat the previous inline search command in the same direction

,-repeated execution of the previous inline search command in the opposite direction

: Set NU Displays line numbers: Set Nonu does not display line numbers. The command CTRL + G causes VI to display the following information at the bottom of the screen: the current line number, the number of rows in the file, and the percentage of rows currently displayed in the total number of files.

' (anti-quote)-the cursor moves back to the position where the cursor was before the last cursor move. If you do some editing and then use the G command to move the cursor, the cursor will be moved back to the location where you performed the edits, and if you have just performed the search, the cursor will be moved back to the location where you started the search.

' (two single quotes)-the cursor moves back to the first character of the line before the last cursor move

cursor Movement:
Zenter-Scroll the screen to move the line of the cursor to the first line of the screen
Z. (dot)-scroll the screen to move the line of the cursor to the middle of the screen
Z (minus)-scrolls the screen so that the cursor line moves to the last line of the screen

in-line search:
FX-Find the character x backwards from the cursor and move the cursor over the character X
Fx-finds the character X forward from the cursor and moves the cursor over the character X
TX-Finds the character x backwards from the cursor and moves the cursor to the previous character X
Tx-finds the character X forward from the beginning of the cursor and moves the cursor to a character after X
; -Repeat the previous inline search command in the same direction
,-repeated execution of the previous inline search command in the opposite direction

Linux VI Move CURSOR command

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.