Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

In bash, if you set $EDITOR to your favorite text editor, you can send the current line to $EDITOR with ctrl-x ctrl-e. After editing the command you can save and exit for the command to execute.


You can also just press 'v' if you're using vi mode in ksh like hardened old unixbeards like me :}


fc builtin does the same thing. No ctrl-key sequences required.

Just type "fc"

With previous commands, one can also specify a particular editor instead of default $EDITOR

For example, to edit the previous command with ed when EDITOR=vi

  fc -e ed
A quick way to make shell scripts from command line history in vi mode (where 15th entry in history is the desired command line):

  fc 15
  w1.sh
  %d
  wq


And for the fish folk, it's Alt-e


I love these shortcuts but sadly I never remember them when I do need them


I use this with copilot.vim in Neovim and EDITOR=nvim to get AI shell autocomplete. It's pretty good!

Got it from here https://twitter.com/arjie/status/1575201117595926530?s=46&t=...


Or even just bind it to ctrl-e in bash:

bind '\C-e: edit-and-execute-command'


that sounds horrific. every time you tried to go to the end of the line you'd get interrupted by launching an editor!


I always just use the home and end buttons for that kind of thing.


i don't even know where they are without looking at the keyboard. then when i try to press them half the time i accidentally press insert or print-screen instead


When I have this problem I remap the key I needed to a location that does work for me.


now you have two problems


I have `set -o vi` so, `esc` and `$` takes me to the end of the line. `ctrl-e` is unused for me unless I bind it to something I think is useful.




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: