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-]>
相关推荐
前端小超人rui12 小时前
UEditor 对接 秀米 手机编辑器流程与问题
编辑器
l1x1n013 小时前
Vim 编辑器常用操作详解(新手快速上手指南)
linux·编辑器·vim
星沙丘秋19 小时前
Kettle导入Excel文件进数据库时,数值发生错误的一种原因
excel
Shan120521 小时前
编辑器Vim的快速入门
linux·编辑器·vim
Tomorrow'sThinker21 小时前
✍️ Python 批量设置 Word 文档多级字体样式(标题/正文/名称/小节)
python·自动化·word·excel
通信小小昕1 天前
ubuntu18.04.1无法安装vscode(安装依赖无效)
ide·vscode·编辑器
大虫小呓1 天前
50个Python处理Excel示例代码,覆盖95%日常使用场景-全网最全
python·excel
禁默1 天前
Linux Vim 编辑器详解:从入门到进阶(含图示+插件推荐)
linux·vim·excel
ykjhr_3d1 天前
华锐云空间展销编辑器:开启数字化展示新时代
编辑器
许白掰1 天前
Linux入门篇学习——Linux 工具之 make 工具和 makefile 文件
linux·运维·服务器·前端·学习·编辑器