Vim's custom shortcut key settings

Source: Internet
Author: User

Because Vim itself is powerful and can use many commands, and can call external commands by executing colleagues, this makes it possible for us to customize tools and operations! Today, I will take Java compilation and execution as an example to briefly describe how Vim can customize shortcuts.

Commands
Vim defines the command map for the shortcut key. The corresponding unmap command cancels the defined shortcut key!
Step 2
How can we compile a file named hello. Java?
Run ESC in command mode and enter :! Javac hello. Java
: The command input prompt indicates that the following command is input by VIM.
! Indicates the operation after this. It is a command other than the editor.
Not to mention javac hello. java.
However, since we want to use this operation as a shortcut key call, the name of the file name must have its wildcard and cannot be too limited!
Here we use the wildcard %
Therefore, the entire command operation process is to press ESC and then input :! Javac % and press ENTER
Next, we can define the shortcut key. I define F12, so its command is
: Map <F12> :! Javac %
In this way, a problem is found... What's the problem... In the first place, if not in command mode... This can only be executed .... So we have to enter ESC first, but when we Press ESC in map, what should we do if the input state is exited? The answer is to replace the operation with the <ESC> character, then the command becomes
: Map <F12> <ESC> :! Javac %
Press enter to confirm and press F12 to display on the screen... But I still want him to execute it directly... Since <ESC> can replace the ESC operation, what can replace the carriage return operation? The answer is <CF> the complete compilation shortcut is completed:
: Map <F12> <ESC> :! Javac % <CF>

Next, define the execution command Ctrl + F12:
: Map <C-F12> <ESC> :! Java % <CF>
We should have already thought of this question. Java execution cannot carry extensions. What's more, the current extension is. java. What can we do to prevent it from having an extension? The answer is % <, % <, indicating a file name without an extension. Then the entire execution statement is:
: Map <C-F12> <ESC> :! Java % <CR>

In this way, the shortcut key can be used... Is it convenient?

Other special symbols are attached:
<Tab> Tab
<EOL> end of line
<BS> return

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.