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-]>
相关推荐
weixin_404679311 小时前
vscode内存过大
ide·vscode·编辑器
天一生水water1 小时前
顶级多项目管理 Excel 模板
excel·敏捷流程
winfredzhang2 小时前
深入剖析 wxPython 配置文件编辑器
python·编辑器·wxpython·ini配置
取啥都被占用2 小时前
VBA的excel逐行替换到word模板及打印还原
excel·vba
hoo3432 小时前
轻量不卡顿!7-Zip 清爽压缩软件:高压缩比
编辑器·7-zip
infiniteWei3 小时前
【VIM 入门到精通】快速查找与替换:定位和修改文本的利器
linux·编辑器·vim
七元权3 小时前
VSCode连接远程容器失败(Missing GLIBC >=2.28!)
ide·vscode·编辑器·连接容器
infiniteWei3 小时前
【VIM 入门到精通】视觉模式与剪贴板:高效选择、复制与粘贴
linux·编辑器·vim
infiniteWei3 小时前
【VIM 入门到精通】精准光标移动与文本对象:Vim思维的进阶
linux·编辑器·vim
坚定信念,勇往无前3 小时前
vue3图片,pdf,word,excel,ppt多格式文件预览组件Vue Doc Viewers Plus
pdf·word·excel