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-]>
相关推荐
Q16849645152 小时前
红帽Linux复习-Vim
linux·运维·vim
R-G-B4 小时前
【23】MFC入门到精通——MFC资源视图 报错“在另一个编辑器中打开” ,MFC Dialog窗口消失 资源视图“在另一个编译器中打开”
c++·编辑器·mfc·“在另一个编辑器中打开”·mfc dialog窗口消失
广州华锐视点5 小时前
多场景 VR 教学编辑器:重构教学流程的场景化实践
重构·编辑器·vr
petunsecn5 小时前
Excel文件中的VBA脚本,在文件使用WPS编辑保存后无法执行
excel·wps
一路向北⁢10 小时前
基于 Apache POI 5.2.5 构建高效 Excel 工具类:从零到生产级实践
java·apache·excel·apache poi·easy-excel·fast-excel
alladmin18 小时前
Clang-LLVM编译STM32
编辑器
FJW02081420 小时前
Linux编辑神器——vim工具的使用
linux·运维·vim
Java小王子呀21 小时前
Java实现Excel转PDF
java·pdf·excel
数字冰雹1 天前
从静态模型到数据驱动:图观模型编辑器让工程设备真实还原
编辑器
迷途呀1 天前
Latex中的错误汇总
论文阅读·笔记·学习·其他·编辑器