From 17072e06586595da1ef6d1823b736d09cfb0a373 Mon Sep 17 00:00:00 2001 From: Yegappan Lakshmanan Date: Tue, 8 Mar 2022 10:56:05 -0800 Subject: [PATCH] When jumping to a symbol definition, reuse the current window if 'hidden' is set --- autoload/lsp/symbol.vim | 12 ++++++++---- doc/lsp.txt | 17 ++++++++++------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/autoload/lsp/symbol.vim b/autoload/lsp/symbol.vim index 66b1ea5..f61d650 100644 --- a/autoload/lsp/symbol.vim +++ b/autoload/lsp/symbol.vim @@ -264,15 +264,19 @@ export def GotoSymbol(lspserver: dict, location: dict, type: string) else var bnr: number = fname->bufnr() if bnr != -1 - if &modified || &buftype != '' + # Reuse an existing buffer. If the current buffer has unsaved changes + # and 'hidden' is not set or if the current buffer is a special + # buffer, then open the buffer in a new window. + if (&modified && !&hidden) || &buftype != '' exe 'sbuffer ' .. bnr else exe 'buf ' .. bnr endif else - if &modified || &buftype != '' - # if the current buffer has unsaved changes, then open the file in a - # new window + if (&modified && !&hidden) || &buftype != '' + # if the current buffer has unsaved changes and 'hidden' is not set, + # or if the current buffer is a special buffer, then open the file + # in a new window exe 'split ' .. fname else exe 'edit ' .. fname diff --git a/doc/lsp.txt b/doc/lsp.txt index f463686..93ed7cc 100644 --- a/doc/lsp.txt +++ b/doc/lsp.txt @@ -2,7 +2,7 @@ Author: Yegappan Lakshmanan (yegappan AT yahoo DOT com) For Vim version 8.2.2342 and above -Last change: Feb 17, 2022 +Last change: Mar 8, 2022 ============================================================================== *lsp-license* @@ -244,12 +244,15 @@ diagnostic messages, you can add the following line to your .vimrc file: *:LspGotoDefinition* :LspGotoDefinition Jumps to the definition of the symbol under the - cursor. If the file is already present in a window, - then jumps to that window. Otherwise, opens the file - in a new window. If the jump is successful, then the - current cursor location is pushed onto the tag stack. - Also the |``| mark is set to the position before the - jump. + cursor. If the file is already present in a window, + then jumps to that window. Otherwise, opens the file + in a new window. If the current buffer is modified + and 'hidden' is not set or if the current buffer is a + special buffer, then a new window is opened. If the + jump is successful, then the current cursor location + is pushed onto the tag stack. The |CTRL-T| command + can be used to go back up the tag stack. Also the + |``| mark is set to the position before the jump. *:LspGotoDeclaration* :LspGotoDeclaration Jumps to the declaration of the symbol under the -- 2.48.1