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-]>
相关推荐
ONLYOFFICE27 分钟前
ONLYOFFICE 桌面编辑器正式成为 ShaniOS 默认办公套件
linux·编辑器·github·onlyoffice
zhyongrui31 分钟前
SnipTrip:贴纸画布编辑器与“光晕动效”的交互细节
编辑器·交互
罗政1 小时前
AI提取一批Excel单元格内容(快递信息)数据安全,支持断网提取
人工智能·excel
山峰哥1 小时前
SQL调优实战:从索引到执行计划的深度优化指南
大数据·开发语言·数据库·sql·编辑器·深度优先
2501_930707781 小时前
使用C#代码合并或取消合并 Excel 单元格
excel
罗政1 小时前
面向提示词对多Excel,多表单进行“数据分组统计”,“条件合并”,“复杂查询”,“SQL执行”,本地操作,支持百万行表单数据
数据库·sql·excel
无穷小亮11 小时前
Flutter框架跨平台鸿蒙开发——Excel函数教程APP的开发流程
flutter·华为·excel·harmonyos·鸿蒙
生活很暖很治愈11 小时前
Linux基础开发工具
linux·服务器·git·vim
开开心心_Every18 小时前
家长控制电脑软件:定时锁屏管理使用时长
网络协议·tcp/ip·游戏·微信·pdf·excel·语音识别
山峰哥19 小时前
破解SQL性能瓶颈:索引优化核心策略
大数据·数据库·sql·oracle·编辑器·深度优先·数据库架构