Common vim commands

Source: Internet
Author: User
1. move and redirect: n jumps to n rows, and n indicates that the row number nG jumps to n rows, n indicates the row number CTRL-] jump to the subject CTRL-O corresponding to the current cursor back to the previous position h left j down k l right W move one wordb forward move one word backward $ command move cursor move the cursor to the end of the current line ^ 1. move and redirect:
: N jumps to n rows, and n indicates the row number.
NG jumps to n rows. n indicates the row number.
CTRL-] jump to the topic corresponding to the word with the current cursor
CTRL-O back to previous location
H left
J lower
K
L right
W move a word Forward
B. move a word backward.
$ Move the cursor to the end of the current line
^ Move the cursor to the first non-blank character in the current line
The 0 command always moves the cursor to the first character of the current line.
Fx finds the next character x on the current row
% Jump to matching brackets
The gf command is used to conveniently jump to the file represented by the file name under the cursor.
'. Jump to the last modified location
"Jump to the position where the cursor is located recently
M {mark} marks the position name under the current cursor as {mark}. a total of 26 custom tags can be used from a to z.
'{Mark} jumps to a {mark} tag you have defined.
50% mF to the middle of the file ("50%") to set a global tag named F
G cursor positioned on the last line
Gg cursor positioned on the first line
50% cursor positioned in the middle of the file
H. the cursor is positioned on the first line of the display.
M cursor positioned in the middle of the display
L position the cursor on the last line of the display screen
CTRL-U command causes text to scroll down half screen
CTRL-D command move window down half screen
The CTRL-F command will scroll forward a whole screen (actually two rows for the whole screen)
The CTRL-B command will scroll back a whole screen (actually two rows for the whole screen)
The zz command sets the current line to the center of the screen (the z word takes its pictogram meaning to simulate the folding and deformation position reset of a piece of paper)
The zt command places the current line at the top of the screen (t indicates top)
The zb command places the current line at the bottom of the screen (B indicates bottom)
: Jumps lists the locations you have jumped to. the last one is marked with a "> ".
: Marks: lists custom tags, including the VIM internal custom tags.
2. search
/Command can be used to search for a string. you can also use the arrow keys and delete keys to move and modify the string.
? The command and "/" work the same, but the search direction is opposite.
N continue searching for the next string
The N command works the same as the "n" command, but the search direction is the opposite.
* Completely match words under the cursor
# Match words with the cursor up and down
G. match the words under the cursor in the lower part.
Ctrl-P: Search for matching words and complete them.
Ctrl-N search backward for matching words and complete them
: Set ignorecase settings ignore case sensitivity
: Set hlsearch highlight search results
: In set incsearch, Vim starts searching when you type the target string.
: Set nowrapscan will stop the search process at the end of the file
3. edit (add, delete, move, and copy)
X indicates dl (delete the characters under the current cursor)
X indicates dh (delete the character on the left of the current cursor)
D represents d $ (content deleted to the end of the row)
C stands for c $ (content modified to the end of the line)
S stands for cl (modify one character)
S stands for cc (modify a whole line)
Diw deletes the word with the current cursor (excluding blank characters), meaning Delete Inner Word
Daw deletes the word (including blank characters) where the current cursor is located, meaning Delete A Word
DG deletes content from the current row to the end of the file
Dgg deletes contents from the current row to the file header
Change Inner Sentence
R enables Vim to enter the replace mode. In this mode, each character entered replaces the character under the current cursor.
P: used to retrieve the deleted content. you can use the command count (put in Vim)
P retrieves the deleted content like p, but it places the retrieved content before the cursor.
Yw copies a word and can also use the command count. c indicates change instead of copy.
Yy copies a whole row
Y $ copy the current cursor to the end of the row
~ Change the case sensitivity of characters under the current cursor
3. replace the string in vi:
: S/vivian/sky/replace the first vivian in the current row with sky
: S/vivian/sky/g replace all vivian in the current row with sky, and g indicates global
: N, $ s/vivian/sky/replace the first vivian from row n to row n as sky and n as numbers
: N, $ s/vivian/sky/g replace all vivian values from row n to row n
:., $ S/vivian/sky/g replace all the vivian values from the current row to the last row
: % S/vivian/sky/(equivalent to: g/vivian/s // sky/) replace the first vivian of each row with sky, and % indicates all rows.
: % S/vivian/sky/g (equivalent to: g/vivian/s // sky/g) replace all
: S # vivian/# sky/# replace the first vivian/in the current line with sky/. you can use # as the separator. The/in the middle will not be used as the separator.
: 3, $ s/^/some string/insert some string before the beginning of the first line to the last line of the file
: % S/$/some string/g add some string at the end of each row of the entire file
: % S/s + $ // remove spaces at the end of all rows. "s" indicates blank characters (spaces and tabs ), "+" matches the previous character once or multiple times (the more the better), and "$" matches the end of the line ("$" indicates a simple "$" character)
: % S/(s * n) +/r/remove all blank rows. "(" and ")" groups expressions, this makes it an integral whole.
: % S! S *//.*!! Remove all "//" comments
: % S! S */* _. {-} */s *!! G remove all "" comments
3. file processing
: W/tmp/1 since the disk cannot be saved, do not want to discard all the modifications, first temporarily save to/tmp/1.
: 20th/tmp/1 or simply store the content between and 59 rows into the file/tmp/1.
: X file encryption. a prompt is displayed for entering the password.
The newly edited vim-x exam.txt file is encrypted. a message is displayed, prompting you to enter the password.
Open the file in the vim-R file read-only mode.
Vimdiff main. c ~ Main. c shows the differences between the two files
: Args display file list
: N switch to file 2 (n = next ).
: N switch back to File 1.
: Scriptnames: displays vimrc loaded by VIM.
Fixed mode of VIM commands: operator commands + displacement commands
: Version: displays VIM version information, including features, compilation methods, and configuration file directories.
: Map: lists the currently defined mappings.
: Help E37
5. common shortcuts:
".": Repeat the last modification command
"Ctrl-X Ctrl-L": Searches for matching rows and completes
"Ctrl-X Ctrl-F": Searches for matching file names and completes
"Ctrl-G": displays the file name, the row number of the current cursor, the total number of rows, and the percentage in the file where the current row is located and the information of the column where the current cursor is located.
"ZQ": Exit unconditionally
"ZZ": (save disk and quit)
"Ga": displays the internal code of the character under the cursor under the currently used encoding.
"Guw": the words under the cursor become lowercase.
"GUw": the words under the cursor are capitalized.
"Xp": the two-character position at the left and right sides of the cursor
"Ddp": the position of the two rows at the cursor is switched up and down. The p command gets it back (put in Vim)
"J": the two rows are merged into one row, that is, the line break between the two rows is deleted.
"U": undo the last command
"Ctrl + R": redo the last command
"O": start another row under the current row and convert the current mode to Insert mode.
6. execute external commands:
":! Command ": an external command can be executed in Vim.
": R !" : The command can insert the execution result of an external command to the currently edited buffer.
": %! Nl: Number of all rows that contain empty rows
":! Echo $ VIMRUNTIME "shows the VIM Directory (/usr/share/vim/vim63)
"Vimtutor" shows the VIM 30-minute tutorial
7. set options:
: Set list to View tabs. now, each tab is displayed as ^ I. At the same time, each row has a $ character at the end.
: Set key = remove file encryption.
: Syntax enable color
: Set number? Display the value of number
: Set number & default recovery options
: Set autoindent: enable Vim to indent the above row when starting a new row.
: Set showcmd: in the lower right corner of the Vim window, a complete command completed section is displayed.
: Set autowrite to set automatic disk storage
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.