1

There is something I cannot do with YouCompleteMe that I could do when just using tags to navigate to a definition or declaration.

The desired behaviour is (taking into account that , is my leader key):

  1. ,g should attempt to go to the definition/declaration in the current buffer. If changes to the buffer are not saved, it should print an error "No write since last change" or something similar and do nothing.
  2. ,ds should open the definition/declaration in a vertical split, regardless of whether changes to the current buffer have been saved or not (since the original buffer will remain open).
  3. ,dt should open the definition/declaration in a new tab, regardless of whether changes to the current buffer have been saved or not (since the original buffer will remain open).

With ctags, behaviour 1 was the standard Ctrl], and 2 and 3 could be achieved with:

" Open definition in new vertical split
map <leader>ds :vsp <CR>:exec("tag ".expand("<cword>"))<CR>
" Open definition in new tab
map <leader>dt :tab split<CR>:exec("tag ".expand("<cword>"))<CR>

However, YouCompleteMe seems to behave differently. According to the official documentation:

The g:ycm_goto_buffer_command option

Defines where GoTo* commands result should be opened. Can take one of the following values: [ 'same-buffer', 'horizontal-split', 'vertical-split', 'new-tab', 'new-or-existing-tab' ] If this option is set to the 'same-buffer' but current buffer can not be switched (when buffer is modified and nohidden option is set), then result will be opened in horizontal split.

This means that if I define my new mappings as:

" Shortcuts for navigating to definitions using YouCompleteMe
map <leader>g  :YcmCompleter GoToDefinitionElseDeclaration<CR>
" Open definition in new vertical split
map <leader>ds :vsp <CR>:exec("YcmCompleter GoToDefinitionElseDeclaration")<CR>
" Open definition in new tab
map <leader>dt :tab split<CR>:exec("YcmCompleter GoToDefinitionElseDeclaration")<CR>

I can't achieve any of the behaviours if the changes to the file have not been saved:

  1. ,g does not print an error, but instead opens the definition/declaration in a new horizontal split.
  2. ,ds does not open the definition/declaration in the new split directly, but instead creates the vertical split and then opens the definition/declaration in a horizontal split inside the vertical split.
  3. ,dt does not open the definition/declaration in the new tab directly, but instead creates the new tab and then opens the definition/declaration in a horizontal split inside the tab.

What settings/mappings should I set to achieve the desired behaviour?

2
  • You mentioned the option g:ycm_goto_buffer_command. What did you set it to? – Michael Ma Aug 15 '20 at 18:52
  • This was three years ago, so I don't really remember. My .vimrc file does not set a value, so I take it it is the default one, which I believe is same-buffer. Thinking about it, it's possible that the issue is that the new split is of the same buffer, so it cannot open it in the new split of the same buffer if changes have not been saved, hence resulting in the horizontal split. It's been a while since I've used YCM navigation (the office projects are not too friendly for it), so I don't even know if it's an issue any more. – user2891462 Aug 17 '20 at 11:02
0

Reason may be not in ycm, but in other plugins:
I noticed that jedi-vim takes control over go-to command and after specifying

let g:jedi#use_tabs_not_buffers = 1

all work as expected

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.