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-]>
相关推荐
AI英德西牛仔10 小时前
文心 Excel 与“AI 导出鸭”:PC 端批量导出方案的技术解构
人工智能·excel·deepseek·ai导出鸭
Am-Chestnuts12 小时前
AI 对话里的表格怎么导出成 Excel 还能筛选排序?用DS随心转把数据整理成可分析表格
大数据·人工智能·excel
Metaphor69213 小时前
使用 Python 读取和删除 Excel 文件属性
python·excel
weixin_4692738117 小时前
银行流水 PDF 转 Excel 或者 CSV 完整指南
人工智能·pdf·excel
百事牛科技17 小时前
Excel部分单元格禁止修改:锁住该锁的,放开该放的
windows·excel
asdzx6719 小时前
使用 Python 为 Excel 添加各类数据验证规则
开发语言·python·excel
Tanner_SL20 小时前
Linux笔记之vim操作
linux·vim
足球中国21 小时前
.net DataExcel控件 2.11.1.53版发布
c#·.net·excel
程序员贺加贝1 天前
列表导出不够用-SaaS-ERP-单据详情导出的-Provider-模板与文档型-Excel-设计
java·后端·设计模式·架构·excel
城数派1 天前
1901-2025年中国省市县三级逐月平均气温数据(Shp/Excel格式)
excel