VI common command set

Source: Internet
Author: User

VI common command set

 

Reprinted from: http://blog.chinaunix.net/uid-20769502-id-112737.html

 

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/removes all blank rows, and "\ (" 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.
Ptions opens a new window. The comment at the beginning of the window contains a list of options.
: 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
: Set backup to set backup. The generated backup file name will be appended to the original file name ~
: Set backupext =. Bak: Set the suffix after the backup file name

Tag
: Tabnew open the new tab.
: Tabe <File> open the file on the new tab.
<Ctrl> + Pageup, Pagedown switch tab.
: Tabnext, tabprev switch tab, Putty can only use this.
File
: E <File> open the file.
: Enew new file.
: W save.
: Wa save all.
: W <File> Save.
: WQ save and exit.
Save and exit.
: Q exit.
: Exit all QA.
: Q! Force exit.
Text
ESC switch command mode (the distance is too far away. use Ctrl + C instead ).
I insert mode.
I insert at the beginning of the current row.
R replacement mode.
A is inserted after the cursor.
A is inserted at the end of the current row.
V visual mode is selected by character.
V visual mode: select by line.
Cursor
H move the cursor left.
J. move the cursor down.
K move the cursor up.
L move the cursor right.
Gg moves the cursor to the file header.
G move the cursor to the end of the file.
# G move the cursor to the specified row #. Example: 5g
Edit
U undo.
. Redo.
Dd deletes the current row.
# Dd delete several rows. Example: 3DD
D ^ Delete to the beginning of the row.
D $ Delete to the end of the row.
: #, & D Delete # To & line. Example: 3, 5d
YY copies the current row to the clipboard.
# YY copy # Row to clipboard.
Y ^ Start copying from the file header.
Y $ copy to the end of the file.
:#, & Y copy # To & line. example: 4, 5y
P paste after the cursor.
P is pasted before the cursor.
increase indentation.
= auto indent.
search and replace
/# search #. example:/printf
? # Reverse lookup #.
N.
N reverse lookup next.
: S/old/new/G does not prompt replacement for the current row.
: % S/old/new/g no replacement prompt.
: % S/old/new/GC confirm replacement.
: #, & S/old/new/g from # To & line No prompt to replace.
jump to bookmarks
: marks to view all bookmarks. Enter ": " to jump.
m defines bookmarks. For example, Ma defines bookmarks named a in the current row.
' jump to a bookmarks. "'" indicates the first key on the keyboard tab.
: jumps to view all jump records. Enter ": " to jump.
+ O returns the previous jump.
+ I and + O reverse rotation.
ctags
:! Ctags-R. generate the ctags file.
+] view function definitions.
+ t return.
SHIFT + K: view the man help information of the function.
Code
GG = g source code format
others
! execute the command.
: r insert file content.
: R! INSERT command output result.
: CD modify default working directory.

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.