zefei / vim-wintabs

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

persistence of folds between tabs (or buffers in a window) #67

Open jwhite510 opened 2 years ago

jwhite510 commented 2 years ago

Hello, the plugin looks very cool. I am very interested in the idea of using multiple tabs within a window in vim, in addition to the normal tabs of vim.

The reason I want to have multiple tabs per window is primarily to keep the folds (im usually using manual folds) updated. And it seems that unfortunately this plugin does not do what I hoped for.

What I really want is to preserve the exact view of the file and update the folded lines dynamically as edits are made, as is done when a window is open in the current window or any other tab. So if a fold is present, and 3 new lines are added above the fold, the fold should be moved down 3 lines

I've used :mkview which kind of works, but does not update the folds like it would if a window had remained open

I've also used this https://vim.fandom.com/wiki/Avoid_scrolling_when_switch_buffers but the problem with this is it does not update folded lines.

The problem I'm trying to explain can be produced as follows:

save the following as 'test.vim' and run this command with either neovim or vim nvim -u NONE -S test.vim vim -u NONE -S test.vim

" remove the files if they exist
:!rm filea.txt
:!rm fileb.txt
" create a test file (filea.txt)
:e filea.txt
normal! idont fold me
normal! 2odont fold me
normal! 4ofoldme
normal! 3odont fold me
" go to line 4
normal! 4gg
:set foldmethod=manual
" fold down 3 lines (all of the 'fold me' lines are now folded)
normal! zf3j

" make a split and send it to the next tab
" (just to reference at the end)
:sp
wincmd T
" return to the original tab
normal! gT

" create a vertical split
:vs

" open a new file in the first window and do some editing
:e fileb.txt
normal! ihello
:w

" go to the other window (with filea.txt)
wincmd w
" insert a new line
normal! 3gg
normal! onew line that should not be folded
:w

" now go back to the previous window
wincmd p
" and switch to the file a buffer
:b filea.txt
" actual behaviour:
" 'foldme' is visible in the current window
" desired behaviour:
" 'foldme should be hidden, as it is in the other window'
"
" notice that in the other tab (press gt)
" the fold has been properly updated even
" though that window was not in view when the
" edit was made

I'm considering writing my own plugin which achieves this with a set of floating windows in neovim. I think I would make floating windows that are in a location that is off screen somewhere. do you have any thoughts on this? I wish that I did not have to rely on floating windows and a neovim specific solution to this problem. I think what I want could be achieved if there were somehow a way to hide windows or set their height to 0, so the folds will still be updated as if they were open, just in another tab somewhere, but I want to be able to reference them quickly like your plugin does.