Reputation: 309
I use fzf.vim to quickly find files in my projects in neovim.
Sometimes either because I can't find what I'm looking for or because I forgot to do something before open the new file, I need to cancel and close the pop up window without selecting any result.
Currently to do that I press <Esc>
to enter in normal mode and then :q
but ideally it would be much faster to map it to a key combination such as <C-x>
How could I map keybindings that target only the FZF window? or Is there any key combination that already close the popup window without any further action?
Thanks in advance
Upvotes: 6
Views: 3470
Reputation: 116
This solution seems to work by default: https://www.reddit.com/r/neovim/comments/4fxsdq/fzfvim_terminal_integration_questions/
In Brief:
ESC , CTRL-C , CTRL-G and CTRL-Q close fzf by default, no need to go to normal mode and delete the buffer. You can even customize the key bindings with --bind option of fzf; for example, :FZF --bind ctrl-p:abort or you can put it in your $FZF_DEFAULT_OPTS .
Upvotes: 8
Reputation: 309
I didn't find a proper way to do it, however I found a workaround that might work for someone else that has the same issue.
Using the variable g:fzf_action
we can map keys to actions in fzf. So that, we can write a command, and fzf will append the path of the selection to the command.
The most important in this case is that as a side effect it will close the window.
The solution that worked for me, was mapping a key to the command silent exec "!echo"
.
!echo
would only print the selection in the command line. As the command is executed silently the result is that only the window is closed.
Not sure if this solution could have some side effects though, however, so far everything seems ok.
Here are my key mappings:
let g:fzf_action = {
\ 'ctrl-x': 'silent exec "!echo"',
\ 'ctrl-h': 'split',
\ 'ctrl-v': 'vsplit' }
Upvotes: 0
Reputation: 11790
To vim I am still curious about such solution, but in my zsh I have this function:
# source:https://stackoverflow.com/a/65375231/2571881
function vif() {
local fname
fname=$(fzf) || return
vim "$fname"
}
If $fname
receives a file name from fzf zsh runs next line, which is vim
calling the $fname
, otherwise zsh simply returns as if nothing had been done.
Upvotes: 0