Vim commands in linux

Source: Internet
Author: User
Tags switch case

Some advanced editors will contain macro functions, which are certainly not missing in vim. It is very convenient to use Macros in vim:

: Qx
Start recording macros and store the results into Register x
Q exit record mode
@ X
Macro commands for playing records in register x
After you enter qx in normal mode, all the edits to the text will be recorded. If you enter q again, the record mode will be exited.
And then input @ x to repeat the recorded command. This command can be followed by a number to indicate the number of times to repeat. For example, @ x20 can be repeat 20 times. This is very useful in text batch processing.
Edit multiple files at the same time
Among the many vim plug-ins, there is a plug-in called minibuffer, which is called the tab function below. You can edit multiple files at the same time.
Tag command

: Tabe
Fn edit the file fn in a new tab
Gt switch to the next tab
GT switch to the previous Tab
: Tabr
Switch to the first tab
: Tabl switch to the last tab
: Tabm [N]
Move the current tab to the nth tab
Yes, as you think, it is similar to eclipse, ue, and other tabs!
Window command
Ctrl + w s
Horizontal Split Window
Ctrl + w switch window
Ctrl + w q
Exit the current window (because there are multiple files at the same time, this command will not affect other Windows)
Ctrl + w v
Vertical Split Window
Others
Vim does not make actual changes to the file before saving, but only loads the file into the buffer. The editing of the file is actually the editing of the buffer. It will not be saved to the physical file until: w.

: E
File: loads the file into the new buffer.
: Bn jump to the next Buffer
: Bd Delete buffer (close file)
: Sp
Fn splits the window and loads fn into a new window.
Exit Editor

: W write the buffer to a file, that is, save the modification.
: Wq
Save changes and exit
Save changes and exit
: Q exits. If the buffer is modified, a message is displayed.
: Q!
Force exit, discard Modification
Search and replace
/Pattern: returns the string pattern.
? Pattern
Search for the forward String pattern
N: Next match (If yes/search, it is the next one ,? Search to the next one)
N
Previous match (same as above)
: % S/old/new/g search the entire file and replace all old with new
: % S/old/new/gc
Search the entire file and replace all old with new. You need to confirm whether to replace
Copy and paste
Dd deletes the row where the cursor is located.
Dw
Delete a word)
X Delete the current character
X Delete the previous character
D. Delete it to the end of the row.
Yy
Copy a row. The command can be followed by a number to identify multiple rows. For example, 6yy indicates that six rows are copied from the current row.
Copy one word from yw
Y $ copy to the end of the row
P
Paste the clipboard content to the current row
P paste the clipboard content to the current row
] P
If you paste the Code with indentation, vim automatically adjusts the code indent.
"
Put the content into/into register a, and support multi-stick Board
Note: for example, a commonly used register is a system register with the name +. Therefore, the "+ p" command is pasted from the system clipboard to vim. Note that the "+" operator is not represented here, 21 registers.
Move cursor
In vim, the moving cursor is very different from other editors, but once learned, it will quickly move in the text.

H, j, k, l
Top, bottom, left, right
Ctrl-f.
Ctrl-B
%
Jump to the brackets that match the current brackets. If the current value is {, jump to the matching value }.
W jumps to the next beginning and is separated by punctuation or words.
W
Jump to the beginning of the next word, long jump, such as end-of-line is considered a word
E. Jump to the end of the next word.
E. Jump to the end of the next character, Long Jump
B
Jump to the previous word
B jumps to the previous word, Long Jump
Jump from 0 to the beginning of the line, whether indented or not, that is, jump to 0th characters
^
Jump to the first character of the line
$ Jump to the end of a row
Gg jumps to the first line of the file
Gd
Jump to the declaration of the variable where the current cursor is located
[N] G jump to the nth line, such as 0G, is equivalent to gg, 100th G is rows
Fx
Find x characters in the current row and jump
; Repeat the previous f command, instead of repeatedly inputting fx
Tx
Similar to fx, but only jumps to the first character of x.
Fx and fx are in the opposite direction
), (Jump to the previous or next statement
*
Find the word at the cursor and look down
# Search for words at the cursor and search up
'.
Jump to the previous edit location
Move on screen

H move the cursor to the top line on the current screen
M
Move the cursor to the middle line of the current screen
L move the cursor to the bottom line of the current screen
Bookmarks
Ma stores the current position as tag
'A
Jump to tag
Edit
R to replace one character
J. Connect the next row to the current row.
Cc
Delete the current row and enter the editing mode
Cw deletes the current word and enters the editing mode.
C $ erase the content from the current position to the end of the row and enter the editing mode
S
Delete the current character and enter the editing mode
S. Delete the row where the cursor is located and enter the editing mode.
Xp exchanges the current and next characters
U
Undo
Ctrl + r redo
. Repeat the previous edit command.
~ Switch case sensitivity, current character
G ~ Iw
Switch the case sensitivity of the current word
GUiw converts the current word to uppercase
Guiw converts the current word to lowercase
>
Shifts the current row to the right of a unit.
<Shifts the current row to one unit (one tab character) to the left)
=
Auto indent current row

Insert mode
I enter insert mode from the current cursor
I enters the insert mode, and the cursor is placed at the beginning of the line.
A
Append mode, after the current cursor
A append mode, with the cursor placed at the end of the row
O Add a new row under the current row and enter the insert mode.
O
Add a new row to the current row and enter the insert mode.
Esc exit insert mode
Visual Mode
Mark text
V
Enter the visual mode, Single Character Mode
V enters the visual mode, and the row Mode
Ctrl + v enter the visual mode, column mode, similar to the column mode of UE
O
Jump cursor to another endpoint of the selected block
U converts the content in the selected block to uppercase
O jump cursor to another endpoint of the block
Aw
Select a word
AB Selects all the content in the brackets, including the brackets themselves.
All content in brackets selected by AB
Ib
Select the content in the brackets, excluding the brackets.
Content in {} selected by iB, excluding {}

Actions on tags
> Block shifted to the right
<
Move left
Y copy Block
D. delete a block.
~ Change the case sensitivity of block content

Http://www.cnblogs.com/zhanglong0426/archive/2010/10/07/1845268.html

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.