Externally Edit Your Command Line
Most people know you can change the readline settings to either vi or emacs style key-bindings, but far less people know you can actually open the current, or a previous, command line in your editor of choice using ‘fc’.
If you type ‘fc’ on the command line then the previous command will be open in the defined editor; if you want to select a further back command you can use ‘fc pattern’. When editing is complete the edited commands are echoed and executed.
The actual editor to be opened can be defined in a number of ways, you can pass the ‘-e’ option to ‘fc’ to set the editor; but you don’t want to do this. If no ‘-e’ is given, the value of the FCEDIT variable is used, and the value of EDITOR if FCEDIT is not set. If neither variable is set, vi is used (which is fine by me :)).
This isn’t functionality you’ll use on a daily basis, occasionally however it makes some very awkward command line tweaks a lot easier. For full details see “man bash”, the “SHELL BUILTIN COMMANDS” section.