when I type commands on a terminal, I usually find myself trying to use it like a text editor, I know this is not how it is supposed to be used, but I recently was watching a talk on youtube and the presenter did something interesting at 17:25 https://youtu.be/f5phsX4VUOU?t=17m25s. It seems like a mini text editor popped out --> he edited the text --> closed it and the changes were reflected back on terminal. How do I do that? is it some sort of plugin or a shortcut?
If you want to edit a command from your history, the
fc command can help.
First, set the editor to one of your choice via the
FCEDIT variable. To use TextEdit.app, do this:
$ FCEDIT='open -nW'
Then run some commands:
$ echo "this command neets editing"
TextEdit should open up, with
echo "this command neets editing" in a new window. Change "neets" to "needs" then save the file and quit the editor. Once the editor quits, the modified command will run, displaying the corrected text.
If you want to edit the active command, invoke
edit-and-execute-command. In my shell, this is bound to
Ctrl-x Ctrl-e. It depends on the value of the
EDITOR environment variable.
Find the key binding in your shell:
$ bind -q edit-and-execute-command edit-and-execute-command can be invoked via "\C-x\C-e".
Ctrl-x Ctrl-e. Set the EDITOR to something you like. I use
emacs, but let's use TextEdit again since this is OS X.
$ EDITOR='open -nW' $ echo "this command neets editing" #now type ctrl-x then ctrl-e
Your editor will open up. Edit the command and save the file. When you close your editor the new command will run.
For more information about
help fc. For more information about
man readline. For more information on