Open utterances-bot opened 2 years ago
I have a slightly different fuzzy file function, for two reasons:
1 - I want to narrow the scope to my dotfiles (my personal wiki is also there) 2 - I want to be able to give up my search and not get right to the nvim
So:
# source:https://stackoverflow.com/a/65375231/2571881
# ~/.dotfiles/zsh/autoload/vif
function vif() {
local fname
local current_dir=$PWD
cd ~/.dotfiles
fname=$(fzf) || return
vim "$fname"
cd $current_dir
}
# https://jdhao.github.io/2019/06/13/zsh_bind_keys/
bindkey -s '^o' 'vif^M'
The difference here is the ||
or in the function, if during my fzf search I press Esc
I get back to my prompt nicely.
I have an article on dev.to where I share some other findings, maybe you can interact sending me some ideas
Thank you for providing a tutorial for "Bind key to run a custom command." I'm spending a lot of time in the terminal and this is very helpful.
I realize this was posted nearly three years ago. Had to say thank you!
I always like your posts. Thought I'd add how I've configured speedily opening vim with fzf. Fzf doesn't seem to work the best by default with git repos, so I've changed the behavior a little to follow gitignore and use rg
.
# fzf doesn't use the default command for fuzzy completion, so I spec'ed it here for vim
# https://github.com/junegunn/fzf#custom-fuzzy-completion
_fzf_complete_vim() {
_fzf_complete --multi --reverse --prompt="vim> " -- "$@" < <(
rg --files --hidden --follow --glob '!.git' --glob-case-insensitive
)
}
bindkey -s '^o' 'vim $(_fzf_complete_vim)^M'
Binding Keys in Zsh - jdhao's blog
In this post, I want to share how to use bindkeys command to solve a few issues when using Zsh.
https://jdhao.github.io/2019/06/13/zsh_bind_keys/