Closed fcying closed 6 years ago
Yes, it's vim built-in feature. You can enable it by add this snippet in your vimrc.
set cscopequickfix=s+,c+,d+,i+,t+,e+,a+
But the default mapping will not works, you need to type the cscope command, like
:copen | cs find s <cword>
I'm not sure if there any solution to fix it, I'll look into it when I have some spare time.
it work fine, thanks~~
set cscopequickfix=s+,c+,d+,i+,t+,e+,a+
noremap <leader>gt :cs find t <C-R>=expand('<cword>')<CR><CR>:copen<CR>
noremap <leader>gs :cs find s <C-R>=expand('<cword>')<CR><CR>:copen<CR>
noremap <leader>gi :cs find i <C-R>=expand('<cfile>')<CR><CR>:copen<CR>
noremap <leader>gg :cs find g <C-R>=expand('<cword>')<CR><CR>:copen<CR>
noremap <leader>gf :cs find f <C-R>=expand('<cfile>')<CR><CR>:copen<CR>
noremap <leader>ge :cs find e <C-R>=expand('<cword>')<CR><CR>:copen<CR>
noremap <leader>gd :cs find d <C-R>=expand('<cword>')<CR><CR>:copen<CR>
noremap <leader>gc :cs find c <C-R>=expand('<cword>')<CR><CR>:copen<CR>
I just realized that I set let g:gen_tags#gtags_default_map = 0
in vimrc 😢
Still a little problem, when I use quickfix, it will automatically jump to the first search result, can be set to not jump?
I wrote a specified string to the top of quickfix list, so it can't jump now, but it will display the string in the top of quickfix...I don't know if there is any better way.
set cscopequickfix=s+,c+,d+,i+,t+,e+,a+
function! s:gen_tags_find(cmd, keyword) abort
let l:cmd = 'cs find ' . a:cmd . ' ' . a:keyword
exec 'cexpr l:cmd'
call setqflist([], 'a')
exec l:cmd
copen
endfunction
noremap <leader>cc :call <SID>gen_tags_find('c', "<C-R><C-W>")<CR>
noremap <leader>cd :call <SID>gen_tags_find('d', "<C-R><C-W>")<CR>
noremap <leader>ce :call <SID>gen_tags_find('e', "<C-R><C-W>")<CR>
noremap <leader>cf :call <SID>gen_tags_find('f', "<C-R><C-F>")<CR>
noremap <leader>cg :call <SID>gen_tags_find('g', "<C-R><C-W>")<CR>
noremap <leader>ci :call <SID>gen_tags_find('i', "<C-R><C-F>")<CR>
noremap <leader>cs :call <SID>gen_tags_find('s', "<C-R><C-W>")<CR>
noremap <leader>ct :call <SID>gen_tags_find('t', "<C-R><C-W>")<CR>
I saw a solution in here https://github.com/ronakg/quickr-cscope.vim/blob/master/plugin/quickr-cscope.vim#L103
But it looks a bit tricky
This way will not display additional data, but if the jumped buf is existed, bdelete it will effect buffer manager
function! s:gen_tags_find(cmd, keyword) abort
let l:cur_buf=@%
let l:cur_line=line('.')
let l:cur_col=col('.')
let l:cmd = 'cs find ' . a:cmd . ' ' . a:keyword
exec l:cmd
if l:cur_buf !=# @%
bdelete
else
call cursor(l:cur_line, l:cur_col)
endif
copen
endfunction
if v:version >= 800
set cscopequickfix=s+,c+,d+,i+,t+,e+,g+,f+,a+
else
set cscopequickfix=s+,c+,d+,i+,t+,e+,g+,f+
endif
function! s:gen_tags_find(cmd, keyword) abort
" Mark this position
execute "normal! mY"
" Close any open quickfix windows
cclose
" Clear existing quickfix list
cal setqflist([])
let l:cur_buf=@%
let l:cmd = 'cs find ' . a:cmd . ' ' . a:keyword
silent! keepjumps execute l:cmd
if len(getqflist()) > 1
" If the buffer that cscope jumped to is not same as current file, close the buffer
if l:cur_buf != @%
" Go back to where the command was issued
execute "normal! `Y"
" delete previous buffer.
bdelete #
endif
copen
endif
endfunction
noremap <leader>c :call <SID>gen_tags_find('c', "<C-R><C-W>")<CR>
noremap <leader>f :call <SID>gen_tags_find('f', "<C-R><C-F>")<CR>
noremap <leader>g :call <SID>gen_tags_find('g', "<C-R><C-W>")<CR>
noremap <leader>i :call <SID>gen_tags_find('i', "<C-R><C-F>")<CR>
noremap <leader>s :call <SID>gen_tags_find('s', "<C-R><C-W>")<CR>
Sometimes only need to show related content, no need to jump