nvim: init.vim: Integrate cscope & fzf

Since we can load results of cscope in fzf we no longer
need quickfix & cscope integration.

Signed-off-by: Sanchayan Maity <maitysanchayan@gmail.com>
This commit is contained in:
Sanchayan Maity 2019-10-30 22:42:33 +05:30
parent be6d4aeaec
commit 21ba6a5c2b

View file

@ -42,7 +42,6 @@ Plug 'vim-utils/vim-husk'
" Tags
Plug 'steffanc/cscopemaps.vim'
Plug 'ludovicchabant/vim-gutentags'
Plug 'sk1418/QFGrep'
" GDB
Plug 'sakhnik/nvim-gdb', { 'do': ':UpdateRemotePlugins' }
" Lisp
@ -161,7 +160,7 @@ nnoremap <Leader>/ :Rg<CR>
" Save
nnoremap <Leader>w <Esc>:w<CR>
" Search and Replace
nmap <Leader>s :%s//g<Left><Left>
nnoremap <Leader>sr :%s//g<Left><Left>
" Quit
nnoremap <Leader>q <Esc>:q<CR>
" Search for the word under cursor
@ -180,7 +179,6 @@ nnoremap <Leader>gp :Git! push<CR>
nnoremap <Leader>gu :Git! push -u
nnoremap <Leader>gr :Git! remote -v<CR>
" For Cscope
nnoremap <Leader>cu :!cscope -Rbq<CR>
nnoremap <Leader>cr :cs reset<CR>
" Quickfix
@ -371,23 +369,6 @@ autocmd BufRead,BufNewFile */pulseaudio/*.[ch] set et sw=4 tw=128
" Spell Checking
autocmd BufRead,BufNewFile *.md,*.txt setlocal spell spelllang=en_uk
" For CScope and Quickfix
" https://medium.com/@lakshmankumar12/quickfix-and-location-list-in-vim-ca0292ac894d
" https://medium.com/@lakshmankumar12/vim-and-cscope-5f4558c8a8b8
function! LoadCscopeToQuickFix(currword, oper)
execute "normal mZ"
execute "set csqf=" . a:oper . "-"
execute "lcs find " a:oper . " " . a:currword
execute "lopen"
execute "wincmd p"
execute "normal `Z"
execute "set csqf="
endfunction
nnoremap <Leader>css <Esc>:call LoadCscopeToQuickFix(expand("<cword>"),"s")<CR>
nnoremap <Leader>csg <Esc>:call LoadCscopeToQuickFix(expand("<cword>"),"g")<CR>
nnoremap <Leader>csc <Esc>:call LoadCscopeToQuickFix(expand("<cword>"),"c")<CR>
" For swoop
let g:swoopUseDefaultKeyMap = 0
let g:swoopPatternSpaceInsertsWildcard = 0
@ -398,3 +379,75 @@ nmap <Leader>os :call Swoop()<CR>
vmap <Leader>os :call SwoopSelection()<CR>
nmap <Leader>om :call SwoopMulti()<CR>
vmap <Leader>om :call SwoopMultiSelection()<CR>
" CScope & fzf integration
" Taken from https://gist.github.com/amitab/cd051f1ea23c588109c6cfcb7d1d5776
" However, the above gist has completely wrong mappings
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', 'bw'],
\ 'down': '40%'
\ }
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 == '9'
let query = input('Assignments to: ')
elseif a:option == '3'
let query = input('Functions calling: ')
elseif a:option == '2'
let query = input('Functions called by: ')
elseif a:option == '6'
let query = input('Egrep: ')
elseif a:option == '7'
let query = input('File: ')
elseif a:option == '1'
let query = input('Definition: ')
elseif a:option == '8'
let query = input('Files #including: ')
elseif a:option == '0'
let query = input('C Symbol: ')
elseif a:option == '4'
let query = input('Text: ')
else
echo "Invalid option!"
return
endif
call inputrestore()
if query != ""
call Cscope(a:option, query)
else
echom "Cancelled Search!"
endif
endfunction
nnoremap <silent> <Leader>ss :call Cscope('0', expand('<cword>'))<CR>
nnoremap <silent> <Leader>sg :call Cscope('1', expand('<cword>'))<CR>
nnoremap <silent> <Leader>sd :call Cscope('2', expand('<cword>'))<CR>
nnoremap <silent> <Leader>sc :call Cscope('3', expand('<cword>'))<CR>
nnoremap <silent> <Leader>st :call Cscope('4', expand('<cword>'))<CR>
nnoremap <silent> <Leader>se :call Cscope('6', expand('<cword>'))<CR>
nnoremap <silent> <Leader>sf :call Cscope('7', expand('<cword>'))<CR>
nnoremap <silent> <Leader>si :call Cscope('8', expand('<cword>'))<CR>
nnoremap <silent> <Leader>sa :call Cscope('9', expand('<cword>'))<CR>
nnoremap <silent> <Leader><Leader>ss :call CscopeQuery('0')<CR>
nnoremap <silent> <Leader><Leader>sg :call CscopeQuery('1')<CR>
nnoremap <silent> <Leader><Leader>sd :call CscopeQuery('2')<CR>
nnoremap <silent> <Leader><Leader>sc :call CscopeQuery('3')<CR>
nnoremap <silent> <Leader><Leader>st :call CscopeQuery('4')<CR>
nnoremap <silent> <Leader><Leader>se :call CscopeQuery('6')<CR>
nnoremap <silent> <Leader><Leader>sf :call CscopeQuery('7')<CR>
nnoremap <silent> <Leader><Leader>si :call CscopeQuery('8')<CR>
nnoremap <silent> <Leader><Leader>sa :call CscopeQuery('9')<CR>