lsp icon indicating copy to clipboard operation
lsp copied to clipboard

LspGotoDefinition on filename opens file in a horizontal split

Open lucas-mior opened this issue 1 month ago • 4 comments

When I use LspGotoDefinition on a filename under the cursor, the file is opened on a horizontal split. Can I configure it to never do that?

lucas-mior avatar Dec 05 '25 15:12 lucas-mior

I found a workaround (also includes :tag command in case Lsp fails)

function! Gototo() abort
    let l:cur_win = win_getid()
    let l:pos     = getcurpos()

    silent! LspGotoDefinition

    if getcurpos() ==# l:pos
        let l:word = expand('<cword>')
        let l:word_escaped = escape(l:word, '\')
        execute 'tag ' . l:word_escaped
        return
    endif

    let l:new_win = win_getid()

    if l:new_win != l:cur_win
        let l:buf = expand('%:p')
        close
        execute 'edit' l:buf
    endif
endfunction

nnoremap <C-]> :call Gototo()<CR>

lucas-mior avatar Dec 05 '25 18:12 lucas-mior

Shouldn't :help 'switchbuf' define this behavior?

Konfekt avatar Dec 06 '25 05:12 Konfekt

I've tried set switchbuf= but the result was the same.

lucas-mior avatar Dec 06 '25 15:12 lucas-mior

I am not able to reproduce this issue. When I try to open a file using the :LspGotoDefinition command, it opens the file in the current window (if the current window is not modified or a special buffer). Can you describe the sequence of steps to reproduce this issue? Is the buffer in the current window modified? Do you have the hidden option set? Are you specifying any command modifiers to the :LspGotoDefinition command?

yegappan avatar Dec 06 '25 17:12 yegappan

Yes, I have the hidden option set.

But I have been messing around with my vimrc and now I can't reproduce the problem.

lucas-mior avatar Dec 09 '25 18:12 lucas-mior