I want to split the window only if the target is not in the open files, none of edit, split, vsplit, tabe, drop and tab drop can make it done right, could we supply an option to do that?
the target is not in the open files
What does open means? Buffer loaded or shown in window?
Try use <C-o> and <C-i> for jump list.
Jump to definition will split the window if I using coc.preferences.jumpCommand="split" and the definition already in the open files.
I only want to split the window if the definition is not in the open files.
You can use drop if you want to use exists windows, it doesn't split but reuse current window so you can make use of jump list.
The behavior is not hard to implemented but I don't think it's necessary.
Yeah, but sometimes reopens the old one and closes the new one drive me crazy...
You can use :bd or use plugin like https://github.com/moll/vim-bbye if you want to remove current buffer and jump to previous one.
split-if-not-open could be confusing, you can create your own command for open files, and set it to "coc.preferences.jumpCommand"
@damnever I too had the same wish and figured out a solution that I wrote about here https://ramgo.li/posts/coc.nvim_split_if_not_open/ 馃槃
@ramsgoli Thanks a lot! 馃憤
I modified it to suit my need 馃槄
function! CocSplitIfNotCurrentFile(...)
" Ref: https://github.com/neoclide/coc.nvim/blob/7e9e0e91e24fc447e96079ae59e9f6caffe604a4/autoload/coc/util.vim#L380-L383
let cursorCmd = ''
let fname = a:1
if a:0 == 2 " Two arguments.
let cursorCmd = a:1
let fname = a:2
endif
if fname != fnamemodify(expand('%'), ':p:~:.')
exec 'split '.fname
endif
if len(cursorCmd)
exec cursorCmd
endif
endfunction
@damnever I too had the same wish and figured out a solution that I wrote about here https://ramgo.li/posts/coc.nvim_split_if_not_open/
This function kept giving me a "not enough arguments" error when there were multiple definitions (causing the locations list to open), for example in a destructured require in Nodejs.
I modified it to detect which arguments were available, similar to @damnever's solution, which seems to fix the problem.
function! SplitIfNotOpen(...)
let fname = a:1
let call = ''
if a:0 == 2
let fname = a:2
let call = a:1
endif
let bufnum=bufnr(expand(fname))
let winnum=bufwinnr(bufnum)
if winnum != -1
" Jump to existing split
exe winnum . "wincmd w"
else
" Make new split as usual
exe "vsplit " . fname
endif
" Execute the cursor movement command
exe call
endfunction
command! -nargs=+ CocSplitIfNotOpen :call SplitIfNotOpen(<f-args>)
@jack0son Nice!
It can be mapped with :call CocAction('jumpDefinition'). Works like a charm!
Most helpful comment
@ramsgoli Thanks a lot! 馃憤
I modified it to suit my need 馃槄