feature request: add preview mode #161

UncleBill opened this Issue Jul 26, 2013 · 23 comments


None yet
4 participants

A preview mode like unite with -auto-preview option: when navigate the tags, splitting up a preview window, that will be very convenience for reading code. 😄


majutsushi commented Jul 30, 2013

This is probably doable, I'll have closer look when I have a bit more time.


majutsushi commented Nov 11, 2013

I've now had the time to implement this. Let me know if you still have some issues with it.

@majutsushi Can you add a variable to control the preview window position? I would like to change the default top left position to something else (bottom left or, even better , to open it as a vertical split of the already opened tagbar window) . Is it possible to adjust the width of the preview window (or to set it to the same size as the tagbar window)? Thanks!


majutsushi commented Nov 13, 2013

I have now added a configuration option that should do what you want.
Let me know if it doesn't work for you.

@majutsushi Thanks it works great! The only problem I have (maybe it is a feature) is that the preview window is folded and (i think not vertically centered). What I would like is to select (highlight) a tag in the tagbar window and have the preview (i) automatically open the fold where that tag is and (ii) vertically center it (or align it at the top). The first image shows the current behaviour and the second one what I would like. Thanks (again)!!

@majutsushi I forgot something: if i close the tagbar window with the q mapping I would like the preview window to close as well. Thanks!


majutsushi commented Nov 22, 2013

Opening the folds and closing the preview window should work now. The
centering should already be done automatically by Vim, does it still
happen for you?

@majutsushi Thanks it works very nice now (the centering is indeed automatic). One last question (I'm really sorry to bother you all the time): I think that when using preview mode each entry in the tagbar window is added to the undo history. What I mean is that if I have, for instance, two functions "foo()" and "bar()" and in the tagbar window I select (highlight) "foo()" and then "bar()" and then jump to the buffer where these functions are defined and press "u" (to undo the changes) it travels backwards to each of the functions definitions (so if I'm now where the function "bar()" is defined and press "u" it will take me back to "foo()"). Can this behaviour change?


majutsushi commented Nov 23, 2013

I'm not quite sure I understand what you mean. At what point are you doing any changes, and what exactly do you mean by highlighting something in Tagbar?


majutsushi commented Nov 28, 2013

Do you have any more information about this? I would like to release a new stable version soon but would like to make sure that the preview mode is working properly. Thanks!

I hope the following animated gif explains things better. What I mean is when using preview mode, selecting each tag in the preview window (placing the cursor over it) seems to add it to the undo history. While being in the Tagbar window if I place the cursor over AdjustWindowHeight function and then go down to BibComp function, then jump to the BibComp function definition in the vimrc file by pressing Enter key and finally pressing u there to undo the changes, I'm taken back to the AdjustWindowHeight definition . Please let me know if the image doesn't clear things up or if this is in fact a feature. Sorry for all the troubles.



majutsushi commented Nov 29, 2013

Okay, I've managed to reproduce it now. I was a bit confused because you talked about undoing a change, but not when or where you actually did a change. Using the :pedit command that I've done so far apparently reloads the file every time just like a normal :edit would, and that creates an empty undo entry.

I think I've fixed it now. It's a bit hacky, but it should work and also seems to be faster than before.

Thanks! It is really fast now!! I have two minor issues now: (i) with my previous setting of

let g:tagbar_previewwin_pos = "belowright"

the preview window is not opened as a vertical split of the tagbar window as it used to be but rather to the side.

(ii) Sometimes the preview window centers the content and sometimes it doesn't (maybe you can explicitly tell vim to do it?) . This two behaviors can be seen in the gif below. On a side note: if I jump from the tagbar window to a tag that is in a closed fold (for instance as you can see in my previous gif with the BibComp function) is it possible to automatically open the fold to display the tag? Thanks for all the great help.



majutsushi commented Nov 29, 2013

For me it does centre properly for every tag. What happens if in the function s:ShowInPreviewWin() after the line that says normal! zv you put a line with normal! zz?


majutsushi commented Nov 29, 2013

I just realized that the centring was happening due to my 'scrolloff' setting. I have now added the line I mentioned to always centre the window. I will have a look at the window position tomorrow.


majutsushi commented Nov 30, 2013

I think I should have everything fixed now. Let me know if there's still anything left.

petobens commented Dec 1, 2013

It works great. Thanks!!!

petobens commented Dec 7, 2013

I am sorry to bother you again. I have one unrelated question (that I mentioned in one of the previous comments): if I jump from the tagbar window to a tag that is in a closed fold (for instance as you can see in the first gif with the BibComp function) is it possible to automatically open the fold to display the tag? Thanks for the help and patience.


majutsushi commented Dec 9, 2013

I pushed a fix for that together with the preview fixes a few days ago.
Is it still not working for you?

petobens commented Dec 9, 2013

I'm so sorry, it works perfectly. My mistake. Thanks once again for all the help and for creating such an excellent plugin.

azag0 commented Oct 9, 2014

I observe unexpected behaviour with three vertically split windows, say 1, 2, 3 from left to right. I have the cursor in 3, hit my tagbar shortcut, the correct tags are displayed for a split of a second and then tags for window 2 are displayed.

Another observation, the cursor is in 1, I hit tagbar shortcut two times to open and close and the cursor ends up in 3. You can watch it here. It happens with .vimrc stripped to minimum both in terminal vim and macvim.

Also notice that the preview window opens above the code window, which I'm not sure is the intended behaviour. I guess all these problems are somehow related.

And yes, this happens just with autopreview on.


majutsushi commented Oct 12, 2014

Dang, Vim window management is really tricky. I can reproduce it and will have a closer look soon.


majutsushi commented Oct 14, 2014

Okay, I have tracked down the problem. The main cause was actually an
incorrect setting of the 'previewwin_pos' option: you have set it to
"splitbelow", but that is an option, not a splitting command. So opening
the preview window failed silently and this caused the following code to
behave in strange ways. I have now made a change so that an incorrect
setting of that option will actually result in an error instead of this
strange behaviour. I have also fixed a few other small things that I
found along the way. So hopefully everything should be working fine now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment