Created
February 20, 2019 16:33
-
-
Save the-eater/acaa34333ac3ef4f2831fcc6cbcfb7b8 to your computer and use it in GitHub Desktop.
Add a shortcut to edit the current buffer in vim
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_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