Advanced Vim Functions

Source: Internet
Author: User
1. Recording
Sometimes, we need to do the same work for each line. For example, when writing a script, to test the program, we sometimes need to comment out many lines, but obviously, if a line adds a # comment to the header, it is obviously intolerable. This allows you to use the recording function.
In command mode, press the Q key, and then press a 0-9
A-z key. This letter or number represents the name of the record. Then start the operation on a row. After the operation is complete, press the Q key. Completion record
Usage record: Enter the number of repetitions @ name.
2. Custom shortcut keys
In command mode, enter
: Map shortcut
For example, input: Map <F2>
I # <ESC> J can be inserted at the beginning of the line # And the cursor moves down one line. If you use the 10 + <F2> key, it will be executed 10 times, the same effect as above
Cancel the shortcut key definition. In command mode, enter the unmap shortcut key.

Note: The shortcut key for this setting is only valid for the current vim, and is invalid after exiting! You can set the shortcut key in. vimrc.
3. Comment out some rows
: 1, 10 s/^/#/g
The above commands are in the range of 1 ~ Add a # before 10 rows and comment out it. Note that ^ indicates the beginning of the line, and $ indicates the end of the line. Sure enough!
Similarly, the C language must be escaped.
: 1, 10 s/^/\/g
4. Magic AB commands
We have seen how to use map to define shortcuts, but it is hard to remember when there are too many definitions. This is the "AB" command.
: AB abbreviation instead of abbreviated text
For example, we enter: AB email leisure512@gamil.com
In the future, every time we input an email in the text, press the space and so on, the email will automatically become a leisure512@gmail.com, But the use is still a little difficult, because we have to predict in advance.
5. Use shell commands in VIM
Format: $! Command.
6. Import other file content to the current text
: R filename
Import the file content to the current cursor!
7. Use the import and shell commands together
Sometimes we want to import the results of shell commands, such as inserting the current system time.
Format: R! Command

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.