Skip to content

Instantly share code, notes, and snippets.

@the-eater
Created February 20, 2019 16:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save the-eater/acaa34333ac3ef4f2831fcc6cbcfb7b8 to your computer and use it in GitHub Desktop.
Save the-eater/acaa34333ac3ef4f2831fcc6cbcfb7b8 to your computer and use it in GitHub Desktop.
Add a shortcut to edit the current buffer in vim
_buffer_edit_() {
# Create tmp file
local tf="$(mktemp /tmp/zshXXXXXXXX)";
# Place current buffer in tmp file
echo $BUFFER > $tf;
# Open tmp file in vim, and if exits with 0, set buffer to tmp file
vim $tf && BUFFER="$(cat $tf)";
# Remove tmp file
rm $tf;
};
# Create a new zle widget for the buffer edit function
zle -N _buffer_edit _buffer_edit_;
# Bind the buffer edit widget to ^Xe
bindkey '^Xe' '_buffer_edit'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment