|
|
|
|
|
by dabber
3312 days ago
|
|
Thanks for the second link. I go there every few weeks but never thought to check out the top voted. ...In hindsight, of course... The gem I just plucked out is something I've been curious about for a while but never looked up: CTRL-X e
The shell will take what you've written on the command
line thus far and paste it into the editor specified by
$EDITOR [then run it when saved]
Similar to `fc` except you don't need to run the command before invoking the editor |
|
Run:
set -o vi
once after you log in (for ksh / bash and compatible shells only, maybe, not sure about csh), or (better) put that line in your .bashrc or similar startup file, so it runs each time you log in. (I used to use "ksh -o vi" earlier, before I knew about "set -o vi" or before it existed, but in that case, it has to be the last line in your startup file, otherwise the other lines below will not run until you exit that (sub)shell.)
Then, when typing a command at the command line, just press ESC then v ; it does the same as what you said.
You can also do ESC :q! (in the editor, if it is vi) to quit without running the command you just edited, or save the command to another file for editing later at leisure, then quit without running it right now.
In fact, "set -o vi" also enables limited editing in vi mode right on the command-line, after you press ESC - you can use the command-mode commands of vi (h, l, b, w, f, F, and more) to move around, change characters or words, can also overwrite or append or insert text, etc.
You can even use / and ? and n and N to search backward and forwards in the commmand history to find (by substring) a previous command, to edit it. Once you find the right commmand, just press v.
Great for productivity.