How to Invoke an Editor for a Long Command at the CLI

$EDITOR refers to an environment variable that’s set by default to allow you to work with a default editor when called from a command shell. This must always be set to some form of a text editor or another. The editor may be emacs, vi, nano, e3 or any other terminal text editor. Linux and other Unix-like operating systems certainly have plenty of options when it comes to text editors.

Sometimes writing a long command from the terminal could be annoying, and you may wish to use the powerful macros or command structure that comes with one of these pieces of software. You may also start writing a long command and realize that you’d prefer it to be part of a shell script since you’ll be running it more than once and not have any wish to write it out again. There’s a rapid invocation technique for these situations.

Rapidly Invoke an Editor from the CLI

First begin by writing a command that you might consider rather long or complicated. You more than likely won’t realize when such an occassion would arise in a CLI until it does. Any time you are halfway through writing a command and wish instead to move to a more powerful editor environment, hold down CTRL and then press X. Release the X key and then, without releasing CTRL, press the E key. Let go of both of them and you should be in your default editor environment.

picture-a

Edit the command structure you were working with the way that you normally would have. If you save the the file under it’s default name by typing :wq in vi or holding down CTRL and pushing O in nano, then you will actually find the file in question is discarded by the shell. The command you edited in the text editor will be parsed as though you entered it in the CLI.

picture-b

If you instead wish to save it, then you will first need to specify a different file name and save it before closing the editor. In nano this can be accomplished by holding down CTRL and pushing O then writing in a specific file name.

Kevin Arrows
Kevin is a dynamic and self-motivated information technology professional, with a Thorough knowledge of all facets pertaining to network infrastructure design, implementation and administration. Superior record of delivering simultaneous large-scale mission critical projects on time and under budget.

Expert Tip

How to Invoke an Editor for a Long Command at the CLI

If the issue is with your Computer or a Laptop you should try using Restoro which can scan the repositories and replace corrupt and missing files. This works in most cases, where the issue is originated due to a system corruption. You can download Restoro by clicking the Download button below.

Download Now

I'm not interested