Usage of GNU Emacs by non-programmers ...... Shell mode 6th set command line abbreviations

Source: Internet
Author: User

It is a good thing. In many places of life, people like to use abbreviations, which saves time and effort. Bash also has its own abbreviation, alias,
Alias always has a lot to do. Why not? As mentioned above, we often talk about a large number of machines, complex systems, and a large number of profiles.
We will not repeat such problems any more. After the explanations in the previous articles, I believe everyone should be familiar with them. Now I am going to talk about some practical problems for most people, even in my own
Work on the machine.

When I have not used Emacs in large quantities, I have always been very depressed. What is it? That is, you have defined an alias
After that, every time you run this command, you only need to enter the alias name, and then press enter, the command will be Bash
Explain and run. When I saw this, did anyone think of what I was talking about? Didn't you think of it? You have no chance to replace or increase or decrease parameters! After definition, it will be dead! In the previous article, I
As I have said many times, many commands are similar in actual work. If you want to define
Alias is a problem if you can keep them in mind. This situation is too bad...

Let's go back to the shell-mode of Emacs for two days. Haha.

Open
A joke. In Shell-mode of Emacs, we do not use Bash alias for command abbreviations, but use Emacs's own
Abbrev function, which defines common commands as abbreviation. These abbreviation operations are available in the shell-Buffer
When a command is input, it will be expanded to the command content we need just like the text editing in other buffer. Because this process occurs completely in Emacs
In Shell-buffer, press enter to send this command to shell.
We can make any modifications. Let's take a look at the actual example. Below is a very common abbreviation in my work, called strma. After this abbreviation is extended, it is a command like this.

Bin/itmcmd agent start

Value
Note that this is not a complete command. It is just a command snippet. At this time, you cannot directly press enter to execute the command. This is exactly Emacs abbrev and bash.
Alias
The most obvious difference. Usually when I use this abbreviation, my goal is to add different parameters on the basis of this fragment, and finally become a specific command suitable for specific needs. Next
Let's take a look at what kind of commands the abbreviation will eventually expand.

Bin/itmcmd agent start MC

Bin/itmcmd agent-O qma, qmb, QMC start MQ

Bin/itmcmd agent start LZ Sy hd cq Qi

Correspondingly, there is also a very common command abbreviation, stpma, which is extended to such a command

Bin/itmcmd agent stop

This is also a command snippet. In actual use, this segment will be filled with such commands

Bin/itmcmd agent stop MC

Bin/itmcmd agent-O qma, qmb, QMC stop MQ

Bin/itmcmd agent stop LZ Sy hd cq Qi

How
? Good, right? You only need to remember a few abbreviations to easily handle different commands, which is completely impossible for Bash alias. And in Emacs
You can also define the abbreviations of these commands as available only in Shell-mode, so that the same abbreviations can be used in other modes.
It is expanded into other content. After all, although there are many letters, there are not many combinations of good-Remembered Images. Right?

So does abbev have its own problems? In fact, there are also. After the abbrev extension, it is very easy to add bricks and tiles behind her, but if the middle part needs to be replaced, it will be very troublesome. It is also depressing to extend a command countless times every day and move, move, and move the cursor forward.

To solve this problem, emacs also provides a skeleton function. Skeleton itself is a very powerful function. Here we only use the simplest part, that is, defining an abbrev and customizing the position of the cursor after the extension.

For example, there is such a command

Bin/itmcmd support-T
Tivvm273-s new Sy hd lz ux nt M6 MQ MC
Qi

In daily use, the tivvm273
The host names are identical in other places. After such a command is simply extended as abbrev, the cursor will be migrated from the end of Qi to-t.
Later, it is not troublesome. At this time, you can define a skeleton. After the extension is completed, the cursor is positioned behind-T, so that you can directly enter the host name.
. Is that comfortable?

Have you noticed this? The underline position in the code above is the position of the cursor after expansion. Is it very visual? In this way, each time you enter addappsupport, you can extend the command to automatically move the cursor to the end of the-t parameter.

Bin/itmcmd support-t-s new Sy hd lz ux nt M6 MQ Mc Qi

Finally, I would like to recall that when I checked alias online some time ago, it seems that the bash document mentioned that we recommend using function instead.
Alias function. Think too. The limitation of Alias definition is too large. But what about switching to a function? Although more flexible
It is much more complicated to define quickly and efficiently.

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.