junegunn / fzf.vim

fzf :heart: vim
MIT License
9.62k stars 584 forks source link

suggestion: refuse to open `:Files` (and other commands) if `'hidden'` is off and window has unsaved changes #1557

Open andmis opened 1 month ago

andmis commented 1 month ago

Checklist

Output of :echo system(fzf#exec() .. ' --version')

n/a

OS

Problem / Steps to reproduce

sometimes i enter :Files, spend some time to find the file i want to open, then press enter, only to be greeted with an error, because i run w/ 'hidden' off and happen to have some unsaved changes.

it would be great for :Files to refuse to open at all in this case.

junegunn commented 1 month ago

Files can open files even in that case when the user presses CTRL-X, CTRL-T, or CTRL-V, so not opening fzf at all is not desirable. If you really must, It is possible to conditionally disable enter key like so.

command! -bang -nargs=? -complete=dir Files
  \ call fzf#vim#files(<q-args>, fzf#vim#with_preview({'options': &modified && !&hidden ? ['--bind=enter:ignore', '--header', 'Enter key disabled'] : []}), <bang>0)
junegunn commented 1 month ago

Let me see whether if it makes sense to make this the default.