I am trying to write a vim function to toggle the fzf
window if it is already open using fzf.vim
.
The use case is if I am in the :Buffers
view and I want to change to the :Files
view if I try to execute :Files
before closing :Buffers
then fzf.vim
complains.
The code is as below:
function FzfRunning()
let buffers = filter(range(1, bufnr('$')), 'bufname(v:val) =~# ";#FZF"')
for i in buffers
" Delete buffer by ID
execute "bw!" . i
endfor
endfunction
command! -nargs=* ToggleFiles call FzfRunning| Files
command! -nargs=* ToggleBuffers call FzfRunning| Buffers
This works except for the fact that the fzf
buffer loses focus. I would like it to focus the fzf
buffer when ToggleFiles
or ToggleBuffers
is called.
execute 'bdelete ' . bufname(';#FZF')
? (maybe you'll have to change;#FZF
to the actual name of a fzf buffer) – statox Dec 29 '16 at 13:33:function!
– analogously to:command!
– enables you to overwrite an existing function definition of the same name without restarting vim. Useful during vimscript dev/ debugging, as you seem to be doing. – Aaron Thoma Jan 1 '17 at 10:59:g
(alias:global
) command, thus is not applicable here. (I submitted an edit to remove it.) – Aaron Thoma Jan 1 '17 at 11:10command!
-nargs=*
only makes sense if you use the arguments (if I'm not mistaken); in this case probably by passing them on:command! -nargs=* ToggleFiles call FzfRunning() | Files <args>
– Aaron Thoma Jan 1 '17 at 11:14