有没有一种方法可以通过按Escape键来取消fzf [英] Is there a way to cancel fzf by pressing escape
问题描述
我的〜/.zprofile
中有 alias vif ='vim $ {fzf)
,效果很好;但是,即使我单击 esc
按钮,它也始终会打开vim窗口,因为我没有找到要查找的文件.如果我按 esc
,如何不打开 vim
?
I have alias vif='vim $(fzf)
in my ~/.zprofile
and it works great; however, it always opens vim window even if I click esc
button because I didn't find the file I was looking for. How do I get it to not open vim
if I press esc
?
推荐答案
使用shell函数,该函数可让您检查 fzf
是否以非零状态退出.(如果被Esc或Ctrl + C中断,它将以状态130退出.)
Use a shell function, that will allow you to check whether fzf
exited with a non-zero status. (It exits with status 130 if interrupted with Esc or Ctrl+C.)
function vif() {
local fname
fname=$(fzf) || return
vim "$fname"
}
||return
部分将在返回码非零时提前中断,因此 vim
仅在成功执行 fzf
后才被调用.
The || return
part will break out early when the return code is non-zero, so vim
will only be invoked after a successful fzf
execution.
这篇关于有没有一种方法可以通过按Escape键来取消fzf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!