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-]>
相关推荐
Smoothcloud润云7 小时前
5大功能精修,重构AI算力使用体验!
java·人工智能·windows·算法·重构·编辑器·sublime text
俊哥工具8 小时前
电脑怎么玩手机APP?超简单新手教程
pdf·电脑·word·excel·音视频
程序大视界11 小时前
【Python系列课程】Pandas(六):数据读写——CSV与Excel文件操作
python·excel·pandas
特立独行的猫a13 小时前
鸿蒙 PC 移植记:将微软的 `edit` 轻量级终端编辑器带到 OpenHarmony
microsoft·rust·编辑器·harmonyos·鸿蒙pc·edit
2501_9160088914 小时前
全面解析常用Web前端开发工具:编辑器、调试工具、性能分析器与框架
android·前端·ios·小程序·uni-app·编辑器·iphone
Land032914 小时前
RPA 实现 Excel 自动化实操教程:批量数据处理零基础落地指南
自动化·excel·rpa
Cloud_Shy61815 小时前
解读《Effective Python 3rd Edition》:从练气到老魔(第二章 Item 13 - 16)
c语言·开发语言·网络·笔记·python·编辑器
搬砖的小码农_Sky1 天前
Excel批量复制全攻略:从单列单行到高级场景
excel·人机交互
专注VB编程开发20年1 天前
淘宝上架销售技巧:Excel管理系统开发 / VBA / ERP / OA办公管理
java·数据库·excel
guslegend1 天前
第2节:AI编辑器底层技术全景导览
人工智能·编辑器