Vim study notes (2)

Source: Internet
Author: User
After introducing the usage of Vim in the previous blog (VIM study notes), this article has reached the historical highest access volume. In the previous article, we introduced the basic usage of VIM, which is basically a summary of unfamiliar commands after I contacted Vimtutor. However, with learning...

After introducing the usage of Vim in the previous blog (VIM study notes), this article has reached the historical highest access volume. In the previous article, we introduced the basic usage of VIM, which is basically a summary of unfamiliar commands after I contacted Vimtutor. However, with the deepening of the study, it is far from enough to master these basic commands. although there are a large number of materials available for download and learning on the Internet, there is no similar entry-level tutorial, therefore, we still hope to have relevant tutorials starting from the most commonly used and basic knowledge. At present, it seems that the article "Learn Vim Progressively" should be a good entry-level teaching material, while cool shell is translated. the URL here is a concise Vim leveling strategy. Here are my study notes:

1. insert:
A: insert after the cursor
O: insert a new row behind the current row.
O: insert a new row before the current row.
Cw: replace the character from the cursor to the end of the last word.

2. Mobile:

0: move to the row header
^: The first character in the row that is not blank. (The blank character is space, tab, line feed, and carriage return)
$: End of the row
G _: to the last position of the line that is not a blank character
/Pattern: string used to search for pattern. (Search multiple instances and press n to return to the next one)

3. copy:

P: copy the content in the buffer before the current position)
P: copy after the current location
Yy: copy the current row. (After a row is used, it is equivalent to copying the row and then to the specified location. use the P command to paste it to the specified location)


4. Undo/Redo

U: undo
Ctrl + r: redo

5. open and save
E : Open a file
W: Save
Saveas : Save as a place
X, wq: Save (x indicates to save only when saving, and wq indicates to save)
ZZ: save without entering the colon. (Unlike the colon + carriage return)
Bn, bp: If you open multiple files at the same time, use this to switch to the previous or next file.

6. better
.: Enter a point number to repeat the previous command.
N : Execute the command multiple times. (For example, 2dd indicates that two rows are deleted, and 3 P indicates that three times are pasted)

7. Stronger
NG: to line N (for example, 3G, indicates to jump to line 3). You can also use 137 to jump to line 137 (more convenient)
Gg: Jump to the first line (equivalent to 1G, or: 1)
G: Jump to the last line
Word Movement:
W: start of the next word
E: to the end of the next word
(If you think that a semicolon is also a word, use E/W)
For example, x = (name_1, vision_3); pay attention to the semicolon next to it.

%: Match the brackets. move the cursor to a bracket and enter % in command mode to jump to the matching brackets.
*: Match the word from the cursor to the current position. (Downward match) (matching means that you know the same word. for example, if you have five words "test" in the current row, you can press * to find and jump to the start point of the next word "test)
#: Match the cursor to the current word (match up)


8. faster
Remember the movement of the cursor.
Eg: 0y $: Jump to the first line, copy it, copy it to the end of the line,
Similarly, ye: start copying and copy it to the last one of the dummies (e is actually the end)
Y2/foo: copy two direct strings of foo (this usage is very strange, not mentioned above)

There is still a lot of time and you may have to press y to copy the file. the following command will also be copied:
D (delete)
V (visual selection)
GU (change to uppercase)
Gu (small write)
And so on.

9. Vim super power
Fa: the next character is. Similarly, fs goes to the next character of s.
T,: the first character before the comma. Similarly, ta is the first character before.
3fa: Search for the third a that appears in the current row
F and T: act the same way as f and t, but in the opposite direction.
Dt ": delete all content. if you know that double quotation marks are encountered, you can replace them with other characters such as dt +.

========================================== The following content is not touched before, important review ==============================
1. select a region
A Or I
Can be any command, such as d (delete), y (copy), v (select the visual mode ).
W represents a word, s represents a sentence, and p represents a paragraph. It can also be special characters such as) and.

For (map (+) ("foo"), the cursor is at the first o position.
Then: vi "---- corresponds to IIn this case, v indicates the mode selection, and I indicates that this special character is not included, so the first o is included in the "symbol.
Others are similar. The difference is that a should include the content.
Vi "→ foo will be selected.
Va "→" foo "will be selected ".
Vi) → Select "foo ".
Va) → Select ("foo ").
V2i) → map (+) ("foo ")
V2a) → Select (map (+) ("foo "))


Block operation
Block operation, typical operation: 0 I -- [ESC]
In Windows, Ctrl + q instead of Ctrl + v is used to start block operations.
The practice is:
1. move the cursor to a certain place first.
2. Ctrl + V start the block operation.
3. select the block range (you can use hjkl, %, or Ctrl + d)
4. I -- Esc (select the corresponding operation, here is insert ii, so now I indicates insert, and then --, but this only works for the first one, to apply to all the blocks, the Esc key is required)

Automatic prompt
The so-called automatic prompt: in fact, it is the result of Vim's statistical memory for the words recently entered by the user. this automatic prompt is displayed when you enter a word recently and then enter it again, if you enter the first word, you can use the shortcut key to match the corresponding word to automatically complete the word.
Enter the following two words:
LaTeX
XeLaText
Then, enter the following, only the first word, and then use the C + n combination, it will be automatically completed.
XeLaText LaTeX

Macro recording:
Qa records your operations in register
Then @ a will repeat the recorded macro
@ Is used to repeat a macro of the current user (to specify a specific macro, @ xx is used, where xx is the name previously saved)

QaYp Q →
Qa starts recording
Yp copies rows.
Add 1.
Q: stop recording.
@ A → write down 2 under 1
→ Write 3 in front of 2
Now, "100 @" will create a new 100 rows and increase the data to 103.


Visual selection of v, V, Ctrl + V (as mentioned above)
The first job is to use this tool to choose either of them.
Then, the module is operated and edited. Yes
J: connect all rows
<Or>: left and right indent
=: Auto Indent is completed (this is the effect in the original animation. after reading it for half a day, I found that the indent has changed)

How can I add a new entry to the end of all selected rows?
Just like the example added above --, first select the module, then jump to the end of $, then add A, and add A is the input string, the part that is applied to all modules is to press Esc.


Split and vsplit
: Split: Create an allocation (vsplit creates a vertical split)
C-w : Direction can be hjkl or Direction key, used for different screen switches
C-w _ or C-w |: used to maximize the size.
C-w + or C-w-: increase the size.

Use of split screen:
1. use the uppercase O parameter to split the screen vertically. Vim-On file1 file2
2. use the lower-case o parameter to split the screen horizontally. Vim-on file1 file2
3. split up and down and open a new file. : Sp filename
4. split the left and right sides and open a new file. : Vsp filename
5. move between screens: Ctrl + W + (h, j, k, l) (different parameters indicate the direction of movement)
For example, Ctrl + W + h indicates moving to the screen on the left.
6. Changes in screen size.
Ctrl + W +: increase the height.
Ctrl + W-: reduce height
Ctrl + w =: make all the screens have the same height
7. For more details, see the help document or http://coolshell.cn/articles/1679.html.
(Note: some commands on the cool shell may have expired due to version reasons, and should be replaced by new shortcuts)

VIM also has more functions to learn. The key is to continuously deepen the exercises in use, as well as powerful extension plug-ins. In addition, it also has corresponding extensions in the browser, which is powerful. We will continue to study in the future, take notes, and summarize the learning income.

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.