-
-
Notifications
You must be signed in to change notification settings - Fork 488
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
With split windows jump to tag definition goes to other window #794
Comments
@SerSamgy I'm not seeing the same behavior. What version of VIM are you running? When I try this, I am getting the correct behavior as you are expecting. I've tried this with the same tagbar configuration as you have listed, and I've tried it with opening a new buffer directly with the |
Sorry... missed that you were running nvim v0.5.1 in the initial post. I am using vim 8.2, so not sure if that is making the difference. Might need someone who is running nvim to look at this. Also if you can capture the tagbar logs that might be useful as well to try to root-cause the issue. You can use |
I was getting a similar issue behavior but I think I narrowed down the problem. | left | right | tagbar | and let's say the the left and right files are the same. Then when you move focus to the tagbar you are passing through the right window, hence tag bar will by default jump to the right window since it was the last one in focus. A solution would be to have a shortcut that would directly get focus on the tagbar. |
Is there a shortcut to go from left split to tagbar directly? |
@raven42 I have same problem as @jonassvedas. Do you know how to jump from left to tagbar? |
Ah ok. To answer these last questions, there is a way to do this with the current tagbar implementation. The
So keyboard shortcuts could be created to call the TagbarOpen command with the desired flag(s). This should definitely help the situation where a vertically split window is used for the same file. With a keyboard shortcut defined to execute @SerSamgy does this accurately describe the behavior you are seeing as well for originally reporting the issue? In your case it sounded like you had two different files, so this might be a little bit different. I am still trying to help solve this original issue, just that I am unable to reproduce it given the available information. |
Hi @raven42 , thanks for answering !! In my case I need to use tagar-toggle, rather than open. Here is the behavior that I hope a shortcut can provide:
Is there a method to have this behavior with one shortcut? |
There is no tagbar specific command that can do this, but you can have a oneliner vim command that will do this. :if bufname('%') =~# 'Tagbar' | call tagbar#CloseWindow() | else | call tagbar#OpenWindow('fj') | endif Or if you want to create a keymapping for this, you can add something like this to your .vimrc nnoremap <silent> <expr> <Leader>t bufname('%') =~# 'Tagbar' ? ':call tagbar#CloseWindow()<CR>' : ':call tagbar#OpenWindow("fj")<CR>' These commands will check if the current window name conains |
Hi @raven42 , I tried your scritp and rewrite it like this: It cannot close tagbar window when the focus is on the tagbar window, and the opening strategy is correct. Is there any mistake in my script? |
It looks correct. Maybe try adding a debug statement before the if statement to see what the bufname is.
then after hitting the key mapping a few times while focused on different windows, type
|
Hi @raven42 , and I open a file, and then use shortcut to open tagbar, and see the result of |
Ok looks like I'm messing up my scripting languages. Sorry about that. The proper debug is as follows: function! ToggleTagbar()
echom 'ToggleTagbar::bufname() = ' . bufname('%')
if bufname('%') =~# 'Tagbar'
call tagbar#CloseWindow()
else
call tagbar#OpenWindow('fj')
endif
endfunction
nnoremap <silent> <Leader>t :call ToggleTagbar() <CR> string concatenation in vimscript is with a When you try this again, if the tagbar window doesn't open with the shortcut, can you open it with With this defined in my .vimrc I am seeing the correct behavior as you've described it. The debug is showing the following for me as well. The 1st time tagbar was not open and it opened the window, the second time tagbar was the active window and it was closed.
|
Hi @raven42 , Seems that it use the name of my code file as bufname not tagbar. Is it something with my vimrc?
|
I think the problem is about key bindings. I used What does |
@raven42 Thanks a lot !! I have no other question for now. |
Steps to reproduce:
Expected behaviour:
Cursor on chosen tag in left split window.
Real behaviour:
Cursor on random line in right split window.
Tagbar settings:
let g:tagbar_autofocus = 1
let g:tagbar_autoclose = 1
let g:tagbar_sort = 0
let g:tagbar_case_insensitive = 1
let g:tagbar_autoshowtag = 1
let g:tagbar_position = 'rightbelow vertical' " Same behaviour with other positions
Prerequisites:
Fedora 34 x64, NVIM v0.5.1, Universal Ctags 5.9.0(p5.9.20211017.0) with optional compiled features: +wildcards, +regex, +gnulib_regex, +iconv, +option-directory, +xpath, +json, +interactive, +sandbox, +yaml, +packcc, +optscript
The text was updated successfully, but these errors were encountered: