vim函数定义跳转相关设置

修改下vim的一些ctags相关快捷键,个人用着顺手点。

小结如下:

  • normal模式下的gk,用来打开一个预览窗口预览函数定义(需要ctags生成好tags文件)。
  • normal模式下的gd,修改映射为ctrl+],即跳转到函数定义(vim内置的ctags的跳转)。
  • normal模式下的F5,用来替换优化下原来的gd(我的个人用法是优化),作用是高亮当前单词,并加入vim的搜索mode中,这样按下n可以跳到下一个位置,N可以上一个位置。

以下是具体内容,加入到 ~/.vimrc中即可。

lua 复制代码
" preview defination in a preview window
" nnoremap gk :ptag expand("<cword>"), This can not be used...
func PreviewSymbol()
    let l:word_under_cursor = expand("<cword>")
    echo "find def for symbol " . l:word_under_cursor
    " :ptag (l:word_under_cursor)
    execute "ptag " . l:word_under_cursor
endf
nnoremap gk :call PreviewSymbol()<CR>




let g:current_word_match_id = -1
function! ToggleHighlightCurrentWord()
  " if has hightword already, clear it
  if g:current_word_match_id != -1
    silent! call matchdelete(g:current_word_match_id)
    let g:current_word_match_id = -1
    return
  endif

  let l:current_word = expand('<cword>')

  " if empty, do nothing
  if empty(l:current_word)
    return
  endif

  " Use the same color with Search highlight group
  highlight link CurrentWord Search

  " set highlight and store the highlighted word to current_word_match_id 
  let g:current_word_match_id = matchadd('CurrentWord', '\<' . escape(l:current_word, '\') . '\>')

  " set cur highlighted word as vim's search pattern
  execute 'let @/ = "\\<' . escape(l:current_word, '\') . '\\>"'
endfunction

" Bind this function to <F5>
nnoremap <F5> :call ToggleHighlightCurrentWord()<CR>

nnoremap gd <c-]>
nnoremap gt <c-]>
相关推荐
葡萄城技术团队3 小时前
从 Excel 到你的表格应用:保护工作表功能的嵌入实践指南
excel
空影星4 小时前
SiriKali,一款跨平台的加密文件管理器
python·编辑器·电脑·智能硬件
TLucas4 小时前
Layui连线题编辑器组件(ConnectQuestion)
前端·编辑器·layui
添砖java‘’10 小时前
vim高效编辑:从入门到精通
linux·编辑器·操作系统·vim
非得登录才能看吗?14 小时前
VScode 入门(设置篇)
ide·vscode·编辑器
番石榴AI16 小时前
自己动手做一款ChatExcel数据分析系统,智能分析 Excel 数据
人工智能·python·数据挖掘·excel
AlphaFinance18 小时前
Windows下Vscode连接到WSL的方法
ide·vscode·编辑器
Lucky GGBond20 小时前
使用 EasyExcel 封装通用 Excel 导出工具类
excel
似水流年 光阴已逝1 天前
从Excel姓名匹配案例学Python:由点及面的系统化学习指南
开发语言·python·excel
空影星1 天前
Tablecruncher,一款轻量级CSV编辑器
python·编辑器·电脑·智能硬件