Thursday, November 12, 2009

Last Command

Hitting "fc" from a Bash shell invokes your default editor (hopefully Vim) on your last shell command and executes it after Vim exits. This is great for command-line history editing after the fact.

-e ENAME selects which editor to use. Default is FCEDIT, then EDITOR, then vi.


Anonymous said...

nifty! I like this one. One note: trial and error showed me that this is a bash command (I usually use tcsh, which is how I noticed).

poindexter said...

It should be pointed out that this a Bash shell command. Furthermore if you're running Bash shell in vi mode (set -o vi) you can edit the current command by pressing 'v' from command mode.

Here's a cheatsheet of vi-mode commands:

Anonymous said...

You can also edit the *current* command using CTRL-xCTRL-e (in, ahem emacs mode).
Handy if your oneliner becomes unmanageable.
You can the function "edit-and-execute-command" to your fave keypresses in "~/.inputrc".

jgpaiva said...

ctrl-x ctrl-e can also be used with vim, if you set EDITOR to vim: export EDITOR="vim"