zefei / vim-wintabs

Modern buffer manager for Vim
MIT License
325 stars 25 forks source link

Win tabs not showing all opened files when opening multiple files quickly (e.g. with fzf) #43

Closed dylan-chong closed 5 years ago

dylan-chong commented 6 years ago

I am writing a little bit of Vim script where there is a function that takes a list of file names, and I want it to open all of those files as buffers in the current tab. (The purpose of the script is to be able to select multiple filenames with fzf and open them all at once in new buffers)

To simulate such behaviour, we can run something like this.

vi 
:for name in ['tsconfig.json', 'tslint.json']
  execute 'e ' . fnameescape(name)
endfor

Ideally this should open up two buffers, and show both in the tab line. The above script only appears to leave the last of the two files in the tab line.

zefei commented 6 years ago

This is caused by a technical limit of how wintabs detects new buffer. I'll find a solution soon (manually notifying wintabs of new buffers).

dylan-chong commented 6 years ago

I was thinking about the feasibility of a function called something like wintabs_open_file(path). It doesn't seem like a hacky solution. What do you think?

zefei commented 5 years ago

@dylan-chong sorry for the long delay, the issue is more involving than it seemed.

I fixed the WintabsRefresh command so it should refresh the buffer list correctly. You'll need to call this command inside chain edits:

for name in ['tsconfig.json', 'tslint.json']
  execute 'e ' . fnameescape(name)
  WintabsRefresh
endfor
dylan-chong commented 5 years ago

Thanks so much for the fix! No worries for the delay, I'm not paying you anything :P

This is really cool! I can now use fzf to select multiple files and open them all at once. Hopefully this will be helpful for someone else in the future (note this is a modified version of the example in https://github.com/junegunn/fzf/blob/master/README-VIM.md#examples):

function! s:fzf_open_buffers(lines)
  for file_name in a:lines
    execute 'e ' . fnameescape(file_name)
    WintabsRefresh
  endfor
endfunction
let g:fzf_action = {
      \ 'enter': function('s:fzf_open_buffers'),
      \ 'ctrl-q': function('s:fzf_build_quickfix_list'),
      \ 'ctrl-t': 'tab split',
      \ 'ctrl-x': 'split',
      \ 'ctrl-v': 'vsplit',
      \ }