Vim _ Common shortcut keys

Source: Internet
Author: User
Tags save file

Command cursor movement
H or ^h moves one character to the left
J or ^j or ^n move down one line
K or ^p move up one line
L or space move one character to the right
G move to the last line of the file
NG moves to the nth row of the file
W moves to the beginning of the next word
W moves to the beginning of the next word, ignoring punctuation
b move to the beginning of the previous word
B move to the beginning of the previous word, ignoring punctuation
L move to the last line of the screen
M moves to the middle line of the screen
H moves to the first line of the screen
E moves to the end of the next word
E moves to the end of the next word, ignoring punctuation
(move to the beginning of the sentence
Move to the end of the sentence
{Move to the beginning of a paragraph
Move to the beginning of the next paragraph
0 or | Move to the first column of the current row
n| Move to nth column of the current row
^ Move to the first non-null character of the current line
$ move to the last character of the current line
+ or return moves to the first character of the next line
-Move to the first non-empty character of the previous line

Add text in VI
Command Insert Action
A inserts text after the cursor
A inserts text in the current line
I insert text before the cursor
I insert text before the current line
o Insert a new row below the current line
O Insert a new row at the top of the current row
: R file reads the file contents and inserts it into the current line
: Nr file reads files into document contents, and then inserts on Nth line
Escape back to Command mode
^v Char when inserted ignores the specified meaning of char, this is to insert special characters

Delete text in VI
Command Delete operation
X Delete the character at the cursor and add the number of characters you want to delete before X
NX removes n characters from the current cursor
x Delete the character before the cursor, plus the number of characters to be deleted before X
NX removes n characters forward from the current cursor
DW Delete to the beginning of the next word
NDW Delete n characters from the current cursor
DG deletes the line until the end of the file
DD Delete entire row
NDD is removed from the current line
DB Delete the word in front of the cursor
NDB delete n words from the current line
: N,MD Delete n rows from line m
D or d$ Remove from cursor to end of line
Dcursor_command deleted to the cursor command, such as DG will be removed from when the liner line to the end of the file
^h or BACKSPACE when inserting, remove the preceding character
^w when inserting, delete the preceding word

Modify VI Text
The number in front of each command indicates the number of times the command was repeated
Command substitution operations
Rchar replacing the current character with Char
R text Escape replaces the current character with text until the ESC key is replaced
Stext Escape uses text instead of the current character
s or Cctext escape with text instead of whole line
Cwtext Escape Change the current word to text
Ctext escape changes the remainder of the current line to text
CG escape modified to the end of the file
Ccursor_cmd text escape changes from the current position to the cursor command position to text

Find and Replace in VI
Command Lookup and replace operations
/text finding text forward in a file
? text looks backwards in the file for text
N repeated lookups in the same direction
N repeated lookups in the opposite direction
Ftext find text in current line forward
Ftext find text backward in current line
Ttext finds text in the current line and positions the cursor in the first character of text
Ttext the text in the current row, and positions the cursor in the first character of text
: Ignore case when set IC lookup
: Set Noic is case sensitive when looking for
: S/oldtext/newtext replace OldText with NewText
: M,ns/oldtext/newtext in M line through N, replace with NewText OldText
& Repeat Last: s command
: G/text1/s/text2/text3 Find rows containing Text1, replace with Text3 Text2
: G/text/command command to run on all lines that contain text
: V/text/command command to run on all lines that do not contain text

copy text in VI
command     copy operation
yy     puts the contents of the current row into a temporary buffer
nyy    the contents of n rows into a temporary buffer
p    the text in the temporary buffer into the cursor
p    puts the text in the temporary buffer before the cursor
"(A-Z) nyy   copy n rows into a named buffer with the name parentheses, omitting n means the current line
" (A-Z) ndd   Delete n rows into a named buffer with the name parentheses, omit N to indicate the current line

in VI undo and repeat
command     undo operation
< Span style= "padding:0px;margin:0px;text-decoration:underline;" >u    undo the last modification of
.    repeats the last modification of
,    repeats the preceding F, F, t, or T Lookup command in the opposite direction
;    repeats the preceding F, F, t, or T Lookup command
n    repeat the previous/or? Find command
n    repeat the previous/or command in the opposite direction

Save text and Exit VI
Command save and/or exit operations
: w save file but do not exit VI
: W file saves the modification in file but does not exit VI
: Wq or ZZ or: x save file and Exit VI
: q! Do not save file, Exit VI
: e! Discard all changes and edit from the last time the file was saved

Options in VI
Option action
: Set all to print all options
: Set nooption turn option option off
: Set Nu prints line number before each line
: Set Showmode Whether the display is an input mode or a replacement mode
: Set Noic ignore case when finding
: Set list display tabs (^i) and end-of-line symbols
: Set ts=8 sets tab for text input stops
: Set Window=n sets the text window to display n rows

vi status
options     effects
:.=     prints the line number of the current line
:=    the number of lines in the print file
^g    Displays the file name, the current line number, the total number of rows in the file, and the percentage of the file location
:l    using the letter "L "To display many special characters, such as tabs and line breaks

position paragraphs and place tags in text
options     effects
{     Insert {In the first column to define a paragraph
]]    moves forward to the beginning of the next paragraph
m (A-Z)     marks the current position with a letter, As with MZ, Mark Z
"(A-Z)     move the cursor to the specified marker, such as ' Z ' to move to Z

Connecting Rows in VI
Option action
J connect the next line to the end of the current line
NJ Connection back N rows

Cursor Placement and screen adjustment
Option action
H move the cursor to the top row of the screen
NH moves the cursor to line n on the top row of the screen
M moves the cursor to the middle of the screen
L move the cursor to the bottom row of the screen
NL moves the cursor to the nth line on the bottom line of the screen
^e (Ctrl+e) Scrolls the screen up one line
^y rolling the screen down one line
^u Roll the screen up half a page
^D Roll the screen down half a page
^B Roll the screen up one page
^F Roll the screen down one page
^l Redraw the screen
Z-return the current row to the top row of the screen
Nz-return Place the nth row below the current row as the top row of the screen
Z. Place the current row as the center of the screen
nz. Place the nth row on the current line as the center of the screen
Z to place the current row as the bottom row of the screen
nz-to place the nth row on the current line as the bottom row of the screen

Shell Escape command in VI
Option action
:!command executes command commands for the shell, such as:!ls
:!! Execute the previous shell command
: R!command reads the input and insertion of command commands, such as: R!ls executes LS first and then reads the contents
: W!command the currently edited file as the standard input for the command command, and executes command commands, such as: W!grep all
: CD directory changes the current working directory to the directory represented by directory
: SH will start a child shell and use ^d (ctrl+d) to return VI
: So file reads and executes commands in Shell program file

vi
options     effects
:map key Command_ SEQ defines a key to run command_seq, such as: Map e ea, whenever you can move E to the end of a word to append text
:map     Show all defined macros in the status line
:umap key   Delete the macro for the key
:ab string1 string2 defines an abbreviation that allows string1 to be replaced when string2 is inserted. When you want to insert text, type string1 and press ESC, the system inserts STRING2
:ab    Show all abbreviations
:una string   cancels the abbreviation for string

indent text in VI
options     effects
^i (Ctrl +i) or tab   when inserting text, insert moving width, moving width is predefined
:set ai    turn Auto Indent
:set sw=n   Set the move width to n characters
n<<    to move n rows to the left by one width
n>>    Moves n rows to the right by one width, for example 3>> moves the next three rows to the right by one move width

%s/^m/\r/g Replace all ^m as line breaks
^m: Enter Ctrl + V and press ENTER


This article is from the "lake and Laughter" blog, please make sure to keep this source http://hashlinux.blog.51cto.com/9647696/1751764

Vim _ Common shortcut keys

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.