How to use Macvim
1. Outside the Insert mode
Basically, you should stay in the insertion mode as little as possible, because VIM is like a "dumb" editor in insert mode. Many novices will always stay in the insert mode because it is easy to use. But the power of VIM is in his command-line mode! You'll find that after you get to know VIM more and more, you'll spend less time using insert mode.
2. Using H, J, K, L
The first step in using VIM for efficient editing is to give up using the arrow keys. With VIM, you don't have to move between the arrow keys and the letter keys frequently, which can save you a lot of time. When you are in command mode, you can use H, J, K, l to achieve the function of the left, bottom, upper and right arrows respectively. You may need to get used to it at first, but once you get used to it, you'll find the efficiency of this operation.
When you edit your e-mail or other text that has paragraphs, you may find that using the arrow keys is not the same as the effect you expect, and sometimes you may skip a lot of lines at a time. This is because your paragraph in VIM appears to be a large long line. You can then type a G before pressing H, J, K, or L so that VIM moves as you wish on the line above the screen.
3. Move the cursor effectively within the current line
Many editors only provide simple commands to control the movement of the cursor (e.g. left, top, right, bottom, to the beginning of the line/tail, etc.). VIM provides a number of powerful commands to satisfy your desire to control the cursor. When the cursor moves from one point to another, the text between these two points (including these two points) is called "Crossing", and the command here is called motion. (briefly, this important concept will be used later)
4. Some common commands (motion):
FX: Moves the cursor to the next X at the current line. Obviously, X can be any one letter, and you can use it; To repeat your last F command.
TX: Similar to the above command, but moves to the left of X. (This is really useful.)
FX: Like FX, it's just looking backwards.
W: The cursor moves forward one word.
B: The cursor moves backwards by one word.
0: Move the cursor to the beginning of the current line.
^: Moves the cursor to the first letter position of the current line.
$: Moves the cursor to the end of the line.
): Move the cursor to the next sentence.
(: Move the cursor to the previous sentence.)
5. Effectively move the cursor throughout the file
VIM has a lot of commands that you can use to get to where you want to go in the file. Here are some commands to move inside a file:
<C-F>: Move down one screen.
<c-b>: Move up one screen.
G: To end of file
NUMG: Moves the cursor to the specified line (num). (e.g. 10G is to line 10th)
GG: To the top of the file
H: Move the cursor to the top of the screen
M: Move the cursor to the middle of the screen
L: Move the cursor to the bottom of the screen
*: Reads the string at the cursor and moves the cursor to where it appears again.
#: Similar to the above, but looking in the opposite direction.
/text: Searches for the string text from the current cursor and reaches the text where it appears. You must use carriage return to start this search command. If you want to repeat the last search, press N.
? Text: Similar to the above, but in the opposite direction.
MA: Marks a bookmark at the position of the current cursor, named A. The book signature can only be lowercase letters. You can't see the existence of a bookmark, but it's already there.
' A: Go to bookmark A. Note that this is not a single quote, it is generally on the left side of 1 of most keyboards.
'.: To the place where you last edited the file. This command is useful, and you don't have to tag it yourself.
high-efficiency input 1. Automatic Completion using keywords
VIM has a very beautiful keyword auto-complete system. This means that you can enter a part of a long word, then click on a key, and then VIM will complete the input of the long word for you. For example: You have a variable named Iamalongandawkwardvarname somewhere in the code you write. Maybe you don't want to enter it every time you go through a letter.
With the Keyword AutoComplete feature, you only need to enter a few letters (such as Iamal), then press <C-N> (Hold down CTRL, press N), or <C-P>. If Vim doesn't give you the word you want, continue to press until you're satisfied, and Vim will loop through the matching string it finds.
2, smart into the insertion mode
Many beginners go into insert mode with just I. This, of course, can go into insert mode, but it is usually not so appropriate because VIM provides a lot of commands to enter the insert mode. Here are some of the most common:
I: Insert on the left of the current character
I: Inserting at the beginning of the current line
A: Insert to the right of the current character
A: Insert at the end of the current line
o: Insert a new row below the current line
O: Insert a new row above the current line
C{motion}: Removes the characters that the motion command crosses and enters insert mode. For example: C $, which removes the character from the cursor position to the end of the line and enters insert mode. Ct! , which removes from the cursor position to the next exclamation mark (but not included) and then into insert mode. The deleted characters are present in the Clipboard and can be pasted again.
D{motion}: Same as above, but not into insert mode.
3. Effectively move large segments of text
Use visual selection (visual selections) and the appropriate selection mode
Unlike the original Vi,vim allows you to highlight (select) some text and do the work. There are three types of visual selection modes:
V: Select by character. Often use the pattern, so try it out for yourself.
V: Select by row. This is especially useful when you want to copy or move a lot of lines of text.
<c-v>: Select by block. Very powerful, only in a few editors have such a function. You can select a rectangular block, and the text inside the rectangle will be highlighted.
Use the arrow keys and commands (motion) described above when selecting the mode. For example, VWWW will highlight the three words in front of the cursor. VJJ will highlight the current row and the following two lines.
4. Cut and copy in Visual selection mode
Once you highlight the selection, you might want to do something like this:
D: Clip the selected content to the Clipboard.
Y: Copies the selected content to the Clipboard.
C: Clip the selected contents to the Clipboard and enter insert mode.
Cut and copy in non-visual selection mode
If you know exactly what you want to copy or cut, you don't need to enter the visual selection mode at all. This will also save time:
D{motion}: Cut the character spanned by the motion command to the Clipboard. For example, DW cuts a word and dfS cuts the character from the current cursor to the next S to the Clipboard.
Y{motion}: Similar to the above, but a copy.
C{motion}: Similar to D{motion}, but finally into insert mode.
DD: Cuts the current line.
YY: Copies the current line.
CC: Cuts the current line and enters insert mode.
D: Cut from the cursor position to the end of the line to the Clipboard.
Y: Copies the current line.
C: Similar to D, and finally into insert mode.
X: Cuts the current character to the Clipboard.
S: similar to X, but finally into insert mode.
5. Paste
Paste is simple, press p.
6. Using multiple clipboard
Many editors provide only one clipboard. There are many VIM. The Clipboard is called a register (registers) in VIM. You can list all of the current defined register names and their contents, with the command ": Reg". It is best to use lowercase letters as the name of the register, because some of the capitalization is used by VIM.
The command that uses the register is a double quote ".
For example: We want to copy the current line to register K. You should press "Kyy." (You can also use V "Ky. Why is this possible? Now the current line should already exist in register K until you copy something into register K. Now you can use the command "KP" to paste the contents of the register K into the position you want.
7. Avoid duplication
It's amazing. Command
Inside VI, enter. (decimal symbol), the last command you entered will be repeated. For example, your last command is "DW" (delete a word) and VI will then delete a word.
8. Use Digital
Using numbers is also one of the most powerful and time-saving features of VIM. A number can be used before many VIM commands, and this number will tell vim how many times this command needs to be executed. Like what:
3J will move the cursor down three lines.
10DD will delete 10 rows.
Y3″ will copy the contents from the current cursor to the third occurrence of the quotation marks to the Clipboard.
Numbers are a very effective way to extend the scope of motion commands.