-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Description
Issue Prelude
Please complete these steps and check these boxes (by putting an x inside
the brackets) before filing your issue:
- I have read and understood YCM's [CONTRIBUTING][cont] document.
- I have read and understood YCM's [CODE_OF_CONDUCT][code] document.
- I have read and understood YCM's [README][readme], especially the
[Frequently Asked Questions][faq] section. - I have searched YCM's issue tracker to find issues similar to the one I'm
about to report and couldn't find an answer to my problem. - I understand this is an open-source project staffed by volunteers and
that any help I receive is a selfless, heartfelt gift of their free time. I
know I am not entitled to anything and will be polite and courteous. - I understand my issue may be closed if it becomes obvious I didn't
actually perform all of these steps.
Thank you for adhering to this process! It ensures your issue is resolved
quickly and that neither your nor our time is needlessly wasted.
Issue Details
I like to both manually use :YcmCompleter GoTo commands, while also keeping a keybind to use them while directly opening the resulting file/line in a new tab. As mentioned in #1146, this can be achieved by setting g:ycm_goto_buffer_command to same-buffer, and creating the following keybind:
nnoremap f :tab split \| YcmCompleter GoToDefinition<CR>
Now something I noticed is that from time to time this would still result in a split. After reading again the manpage for g:ycm_goto_buffer_command, I now realize the reason for this:
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 a split.
Indeed, if my starting buffer is modified, my custom map will open a new tab, then call YcmCompleter GoToDefinition, see that the buffer is modified, and create new split.
However, this is completely unnecessary, as there already exists an opened window (the one I left in the original tab) containing the same modified buffer, so there is no chance of the changes being lost if jumping within the same buffer. For this reason, I'd like to suggest that if it can be proven by YCM that the current buffer, although modified, is already opened elsewhere, that the same-buffer policy can be fully respected regardless of the state of the buffer in the current window.