August 19, 2018

Edit the zsh buffer with your $EDITOR of choice

If you spend a lot of time in the shell you also probably edit a lot of commands, which at times can be tedious when they’re getting a bit to long and complex. Being able to easily fire up your $EDITOR of choice when needed can therefore be a real blessing.

To make it work you need to add these lines to your configuration file ~/.zshrc:

autoload -U edit-command-line
zle -N edit-command-line
bindkey '^I' edit-command-line

And don’t forget to set the $EDITOR variable as well:

export EDITOR="vim"

I have it bound to Ctrl+I to be consistent with how I open the $EDITOR in qutebrowser, but you’re free to bind it to whatever makes sense for you. And if you use the Vi-mode in zsh like me it’s probably a good idea to bind a key for it in the normal mode as well:

bindkey -M vicmd '^I' edit-command-line

Save your changes and source your configuration with the command source ~/.zshrc or just restart the shell for it to take effect.

Comments

I'm looking into a good way of implementing comments on my blog that works without JavaScript, respects the users privacy and is reasonably user friendly. If you have any ideas or just want to give me some feedback on this blog post or if you just want to say hello, feel free to do so either via e-mail, XMPP or Mastodon.