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 小时前
Kettle导入Excel文件进数据库时,数值发生错误的一种原因
excel
Shan12055 小时前
编辑器Vim的快速入门
linux·编辑器·vim
Tomorrow'sThinker5 小时前
✍️ Python 批量设置 Word 文档多级字体样式(标题/正文/名称/小节)
python·自动化·word·excel
通信小小昕7 小时前
ubuntu18.04.1无法安装vscode(安装依赖无效)
ide·vscode·编辑器
大虫小呓8 小时前
50个Python处理Excel示例代码,覆盖95%日常使用场景-全网最全
python·excel
禁默11 小时前
Linux Vim 编辑器详解:从入门到进阶(含图示+插件推荐)
linux·vim·excel
ykjhr_3d12 小时前
华锐云空间展销编辑器:开启数字化展示新时代
编辑器
许白掰12 小时前
Linux入门篇学习——Linux 工具之 make 工具和 makefile 文件
linux·运维·服务器·前端·学习·编辑器
Tomorrow'sThinker1 天前
[特殊字符] Python 批量生成词云:读取词频 Excel + 自定义背景 + Excel to.png 流程解析
python·excel
向宇it1 天前
【unity小技巧】在 Unity 中将 2D 精灵添加到 3D 游戏中,并实现阴影投射效果,实现类《八分旅人》《饥荒》等等的2.5D游戏效果
游戏·3d·unity·编辑器·游戏引擎·材质