From 5a8686ddb1405535d7f4461fd0153d5ecadc1711 Mon Sep 17 00:00:00 2001 From: Luc Ma Date: Sun, 6 Feb 2022 11:28:02 +0800 Subject: [PATCH] add cscope/vim key mappings Signed-off-by: Luc Ma --- vimrcs/extended.vim | 96 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) diff --git a/vimrcs/extended.vim b/vimrcs/extended.vim index 8b1284fd..920f6c9e 100644 --- a/vimrcs/extended.vim +++ b/vimrcs/extended.vim @@ -146,6 +146,102 @@ map p :cp autocmd BufReadPost quickfix nnoremap +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +" => Cscope/Vim key mappings +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +if has("cscope") + " use both cscope and ctag for 'ctrl-]', ':ta', and 'vim -t' + set cscopetag + + " check cscope for definition of a symbol before checking ctags + " set to 1 if you want the reverse check order. + set csto=0 + + " add any cscope database in current directory + if filereadable("cscope.out") + cs add cscope.out + " else add the database pointed to by environment variable + elseif $CSCOPE_DB != "" + cs add $CSCOPE_DB + endif + + " show msg when any other cscope db added + set cscopeverbose + + """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" + " + " The following maps all invoke one of the following cscope search types: + " + " 's' symbol: find all references to the token under cursor + " 'g' global: find global definition(s) of the token under cursor + " 'c' calls: find all calls to the function name under cursor + " 't' text: find all instances of the text under cursor + " 'e' egrep: egrep search for the word under cursor + " 'f' file: open the filename under cursor + " 'i' includes: find files that include the filename under cursor + " 'd' called: find functions that function under cursor calls + " + " Using CTRL-\ as the starting keys for these maps, as it's unlikely + " that you need its default mapping (CTRL-\'s default use is as part + " of CTRL-\ CTRL-N typemap, which basically just does the same thing + " as hitting 'escape'). + " + " If you don't like using CTRL-\, you can change some or all of these + " maps to use other keys. One likely candidate is 'CTRL-_' (which also + " maps to CTRL-/, which is easier to type). By default it is used to + " switch between Hebrew and English keyboard mode. + " + " To do the navigation, hit 'CTRL-\', followed by one of the cscope + " search types above (s,g,c,t,e,f,i,d). The result of your cscope + " search will be displayed in the current window. You can use CTRL-T + " to go back to where you were before the search. + " + """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" + let b:cscope_mapping_start_key = '' + + exe 'nmap '.b:cscope_mapping_start_key.'s :cs find s =expand("")' + exe 'nmap '.b:cscope_mapping_start_key.'g :cs find g =expand("")' + exe 'nmap '.b:cscope_mapping_start_key.'c :cs find c =expand("")' + exe 'nmap '.b:cscope_mapping_start_key.'t :cs find t =expand("")' + exe 'nmap '.b:cscope_mapping_start_key.'e :cs find e =expand("")' + exe 'nmap '.b:cscope_mapping_start_key.'f :cs find f =expand("")' + exe 'nmap '.b:cscope_mapping_start_key.'i :cs find i ^=expand("")$' + exe 'nmap '.b:cscope_mapping_start_key.'d :cs find d =expand("")' + + """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" + " + " These key maps use multiple keystrokes (2 or 3 keys). If you find that + " vim keeps timing you out before you can complete them, try changing + " your timeout settings as explained below. + " + """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" + + " By default Vim will only wait 1 second for each keystroke in a mapping. + " You may find that too short with the above typemaps. If so, you should + " either turn off mapping timeouts via 'notimeout'. + " + "set notimeout + + " Or, you can keep timeouts, by uncommenting the timeoutlen line below, + " with your own personal favorite value (in milliseconds): + set timeoutlen=4000 + + " Either way, since mapping timeout settings by default also set the + " timeouts for multicharacter 'keys codes' (like ), you should also + " set ttimeout and ttimeoutlen: otherwise, you will experience strange + " delays as vim waits for a keystroke after you hit ESC (it will be + " waiting to see if the ESC is actually part of a key code like ). + set ttimeout + + " Personally a tenth of a second works well for key code timeouts. If you + " experience problems and have a slow terminal or network connection, + " set it higher. If you don't set ttimeoutlen, the value for timeoutlen + " (default: 1000 = 1 second, which is sluggish) is used. + set ttimeoutlen=100 + +endif + + """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " => Helper functions """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""