Monday, June 1, 2009

Easier Command Line Editing

Assuming you're using the bash shell, the following can be helpful when composing long command lines.

Start typing on the command line and then type Ctrl-x Ctrl-e, it should drop you into your system's default editor (hopefully Vim) and allow you to edit the command line from there. Once finished, save the command line, and bash will run the command.

10 comments:

Josh Berry said...

If you are using bash and you like vim, you should likely consider just using vi mode. Use "set -o vi" and then you can press escape and start editing the line in place using vi commands.

d said...

Also, once you have 'set -o vi', you can hit the 'v' key in command mode to edit the command line in $EDITOR.

Anonymous said...

Like the first poster said, use 'set -o vi' ... it also works in zsh.

Unknown said...

Oooooh!

Thank you!

> Also, once you have 'set -o vi', you can hit the 'v'

Hmm interesting

9-year HC Vim user here, I'll RSS your stuff!

;)

Mike Pountney said...

... and on the 'set -o vi' front, if you find that you do like using vi editing mode (and what's not to love about it :), add 'set editing-mode vi' to your .inputrc, and vi mode will work in any readline based client, eg psql, irb, ...

Unknown said...
This comment has been removed by the author.
Unknown said...

Question: is there a way to get bash to NOT run the command when the editor exits?

Anonymous said...

David, just clear the buffer and there will be no command to run when you are returned to the command line.

Raffi said...

@David, to leave vim without running the command, type :q!<Enter>; to run the command, type ZZ.

Anonymous said...

@David: to leave without running the command, do ":cq". This exits vim with an error code so that bash ignores it.