From 5497c1b1b656719a8fe428e8b7823855279867e5 Mon Sep 17 00:00:00 2001 From: Sanchayan Maity Date: Wed, 15 Jan 2020 09:46:56 +0530 Subject: [PATCH] nvim: Switch to QF for cscope While we have gone back and forth between quickfix and fzf for cscope, it makes sense for cscope results to be loaded in quickfix window. Results loaded in fzf window will disappear once selected since that's how fuzzy finding is used but we do not want to have that behaviour with results of tools like cscope. Also use a plugin this time instead of having our own function. The plugin also provides the added advantage of jumping to a global definition instead of even opening that in a window. Signed-off-by: Sanchayan Maity --- nvim/.config/nvim/init.vim | 98 +++++++++----------------------------- 1 file changed, 23 insertions(+), 75 deletions(-) diff --git a/nvim/.config/nvim/init.vim b/nvim/.config/nvim/init.vim index 8719acd..4af0f46 100644 --- a/nvim/.config/nvim/init.vim +++ b/nvim/.config/nvim/init.vim @@ -41,8 +41,6 @@ Plug 'rbong/vim-flog' Plug 'whiteinge/diffconflicts' " For tmux yank Plug 'vim-utils/vim-husk' -" Tags -Plug 'steffanc/cscopemaps.vim', { 'for': 'c' } " GDB Plug 'sakhnik/nvim-gdb', { 'do': ':UpdateRemotePlugins' } " Lisp @@ -84,6 +82,7 @@ Plug 'sbdchd/neoformat' Plug 'neomake/neomake' " Quickfix Plug 'sk1418/QFGrep' +Plug 'ronakg/quickr-cscope.vim' Plug 'stefandtw/quickfix-reflector.vim' " Absolute essentials miscellaneous Plug 'tpope/vim-surround' @@ -405,25 +404,17 @@ augroup c_maps au FileType c nmap cu :NeomakeSh cscope -bqR au FileType c nmap cr :cs reset - au FileType c nmap s :call Cscope('0', expand('')) - au FileType c nmap g :call Cscope('1', expand('')) - au FileType c nmap d :call Cscope('2', expand('')) - au FileType c nmap c :call Cscope('3', expand('')) - au FileType c nmap t :call Cscope('4', expand('')) - au FileType c nmap e :call Cscope('6', expand('')) - au FileType c nmap f :call Cscope('7', expand('')) - au FileType c nmap i :call Cscope('8', expand('')) - au FileType c nmap a :call Cscope('9', expand('')) - - au FileType c nmap s :call CscopeQuery('0') - au FileType c nmap g :call CscopeQuery('1') - au FileType c nmap d :call CscopeQuery('2') - au FileType c nmap c :call CscopeQuery('3') - au FileType c nmap t :call CscopeQuery('4') - au FileType c nmap e :call CscopeQuery('6') - au FileType c nmap f :call CscopeQuery('7') - au FileType c nmap i :call CscopeQuery('8') - au FileType c nmap a :call CscopeQuery('9') + au FileType c nmap s (quickr_cscope_symbols) + au FileType c nmap g (quickr_cscope_global) + au FileType c nmap h (quickr_cscope_global_split) + au FileType c nmap v (quickr_cscope_global_vert_split) + au FileType c nmap d (quickr_cscope_functions) + au FileType c nmap c (quickr_cscope_callers) + au FileType c nmap t (quickr_cscope_text) + au FileType c nmap e (quickr_cscope_egrep) + au FileType c nmap f (quickr_cscope_files) + au FileType c nmap i (quickr_cscope_includes) + au FileType c nmap a (quickr_cscope_assignments) augroup END augroup rust_maps @@ -456,10 +447,14 @@ augroup toggle_search autocmd InsertLeave * setlocal hlsearch augroup END -" Close QF window if it is last window -augroup quickfix_close +augroup quickfix au! + " Close QF window if it is last window au WinEnter * if winnr('$') == 1 && &buftype == "quickfix"|q|endif + " Existing bindings for QFGrep + " g input pattern to do further filtering + " v input pattern to do further inverted filtering + " r restore the Quickfix/location list with original entries augroup END augroup terminal_job @@ -662,64 +657,17 @@ let g:psc_ide_auto_imports = 1 " FZF let g:fzf_mru_no_sort = 1 +let $FZF_DEFAULT_OPTS='--layout=reverse' +let g:fzf_layout = { 'window': 'call CreateCentredFloatingWindow()' } + +" Quickr +let g:quickr_cscope_keymaps = 0 " ----------------------------- Functions ------------------------------------ -function! Cscope(option, query) - let color = '{ x = $1; $1 = ""; z = $3; $3 = ""; printf "\033[34m%s\033[0m:\033[31m%s\033[0m\011\033[37m%s\033[0m\n", x,z,$0; }' - let opts = { - \ 'source': "cscope -dL" . a:option . " " . a:query . " | awk '" . color . "'", - \ 'options': ['--ansi', '--prompt', '> ', - \ '--multi', '--bind', 'alt-a:select-all,alt-d:deselect-all', - \ '--color', 'info:144,prompt:161,spinner:135,pointer:135,marker:118', - \ '--color', 'fg:252,bg:233,hl:67,fg+:252,bg+:235,hl+:81'], - \ 'window': 'call CreateCentredFloatingWindow()' - \ } - function! opts.sink(lines) - let data = split(a:lines) - let file = split(data[0], ":") - execute 'e ' . '+' . file[1] . ' ' . file[0] - endfunction - call fzf#run(opts) -endfunction - -function! CscopeQuery(option) - call inputsave() - if a:option == '0' - let query = input('C Symbol: ') - elseif a:option == '1' - let query = input('Definition: ') - elseif a:option == '2' - let query = input('Functions called by: ') - elseif a:option == '3' - let query = input('Functions calling: ') - elseif a:option == '4' - let query = input('Text: ') - elseif a:option == '6' - let query = input('Egrep: ') - elseif a:option == '7' - let query = input('File: ') - elseif a:option == '8' - let query = input('Files #including: ') - elseif a:option == '9' - let query = input('Assignments to: ') - else - echo "Invalid option!" - return - endif - call inputrestore() - if query != "" - call Cscope(a:option, query) - else - echom "Cancelled Search!" - endif -endfunction - function! NvimGdbNoTKeymaps() tnoremap endfunction -let $FZF_DEFAULT_OPTS='--layout=reverse' -let g:fzf_layout = { 'window': 'call CreateCentredFloatingWindow()' } " Stolen from https://github.com/camspiers/dotfiles/blob/master/files/.config/nvim/init.vim function! CreateCentredFloatingWindow() let width = float2nr(&columns * 0.8)