Add a shortcut to edit the current buffer in vim
This file contains 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