Document directory
- Preface
- Tag command
- Window command
- Others
- Move on screen
- Bookmarks
- Mark text
- Actions on tags
Preface
Vim is a super editor designed for programmers. It is incredibly powerful.
. However, the learning curve is steep. I found a small chart on the internet two days ago, which is comprehensive. If I learned the commands listed in the table, it would be enough to process the daily text, so post it for your reference.
Vim's cool-B is not about its wide range of functions, but not about its steep learning curve, but about how many of these commands can be combined.
,
For example, the "9yy" command indicates copying 9 lines of content, the "9" command indicates the number of lines to be copied, and the "100dd" command indicates deleting 100 lines. When the numbers and commands work together, the command is more powerful than the command, similarly, the C command
W indicates the word, CW indicates the word, c5w indicates the deletion of five words, and so on. By combining these simple commands, you can make full use of the unimaginable power.
Yes, and make your editing work fun.
Macro command (macros)
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 your edits to the text will be recorded. If you enter Q again, the record mode will be exited, then input @ X to record the previous record
Run the following command to repeat. The command can be followed by a number to indicate the number of times to repeat. For example, @ x20 can be repeated 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 |
Load the file to the new buffer. |
: Bn |
Jump to the next Buffer |
: BD |
Delete a buffer (close a file) |
: SP FN |
Split the window and load FN to the new window. |
Exit Editor
: W |
Write the buffer to a file to save the modification. |
: WQ |
Save changes and exit |
|
Save changes and exit |
: Q |
Exit. 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 |
Delete the row where the cursor is located |
DW |
Delete a word) |
X |
Delete current character |
X |
Delete the previous character |
D |
Delete to the end of a 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. |
YW |
Copy a word |
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 be fast
In the text.
H, J, K, L |
Top, bottom, left, right |
CTRL-F |
Flip one page |
CTRL-B |
Next Page |
% |
Jump to the brackets that match the current brackets. If the current value is {, jump to the matching value }. |
W |
Jump to the next beginning and separate it by punctuation or word |
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 |
Jump to the previous word, Long Jump |
0 |
Jump 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 end of line |
Gg |
Jump 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. For example, if 0g is used, it is equivalent to Gg, and 100th G is the first line. |
FX |
Find x characters in the current row and jump |
; |
Repeat the previous F command without repeating the input of FX |
TX |
Similar to Fx, but only jumps to the first character of X. |
FX |
Opposite to FX |
),( |
Jump to the previous or next statement |
* |
Find the word at the cursor and look down |
# |
Find the word at the cursor and search up |
'. |
Jump to the previous edit location |
Move on screen
H |
Move the cursor to the top line of 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 |
Save the current location as tag |
'A |
Jump to tag |
Edit
R |
Replace one character |
J |
Connect the next row to the current row |
CC |
Delete the current row and enter the editing mode |
CW |
Delete the current word and enter the editing mode. |
C $ |
Erase the content from the current location 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 edit mode |
XP |
Exchange 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 the left of a unit (one Tab character) |
= |
Auto indent current row |
Insert mode
I |
Enter insert mode from current cursor |
I |
Enter the insert mode and move the cursor to 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 |
Mark text in visual mode
V |
Enter the visual mode, Single Character Mode |
V |
Enter the visual mode, Line Mode |
CTRL + V |
Enter 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 block endpoint |
Aw |
Select a word |
AB |
Select all the content in the brackets, including the brackets themselves. |
AB |
Select all content in brackets {} |
IB |
Select the content in the brackets, excluding the brackets. |
IB |
Content selected in {}, 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 |
Well, this short table is mentioned here. Of course it covers a limited range, but as the title suggests, VIM is powerful in that these commands can be used together, so as to reflect its powerful
Edit. This document I found on the Internet is also posted by the way. You can refer to it at the same time. If there is a chance, I try to find some examples to illustrate the usage of these commands in practice so that they can be used better,
Improve our work efficiency.
Article from: http://abruzzi.javaeye.com/blog/416049