写个自己喜欢的vi工具插件

该vi插件用于查看代码

代码

使用方法:直接拷贝代码到文件,命名为.vimrc代替~/.vimrc即可
配合cscope使用起来看内核代码用的很舒服.

syntax on
"""""""""""""""""""""""""""""""""""
"""""""""""""""""""""""""""""""""""
"cscope setting
"""""""""""""""""""""""""""""""""""
"""""""""""""""""""""""""""""""""""
if has("cscope")
	set csprg=/usr/local/bin/cscope
	set csto=1
	set cst
	set nocsverb
	" add any database in current directory
	if filereadable("cscope.out")
		cs add cscope.out
	endif
	set csverb
endif

"cs add /Users/chenming/Developing/demo/jasper-2.0.14/cscope.out

let csfilelist = []
let csfilecursor = -1

function CmCscopeFind(type,symbol)
	:call add(g:csfilelist,@%)
	:call add(g:csfilelist,line("."))
	:call add(g:csfilelist,a:symbol)
	:let g:csfilecursor = (len(g:csfilelist) / 3) - 1
	:exec "cs find " . a:type . " " . a:symbol
endfunction

function CmJumpBackFile()
	if g:csfilecursor == -1
	else
		if g:csfilecursor > 0
			let g:csfilecursor -= 1
			:call CmJumpFile()
		endif
	endif
endfunction

function CmJumpForwardFile()
	if g:csfilecursor == -1
		return
	endif
	if g:csfilecursor < (( len(g:csfilelist) / 2 ) - 1 )
		let g:csfilecursor += 1
		:call CmJumpFile()
	endif
endfunction

function CmJumpFile()
	if len(g:csfilelist) > 1
		:exec "vi! +" . g:csfilelist[3 * g:csfilecursor + 1] . " " . g:csfilelist[3 * g:csfilecursor]
	else
		:echo "no file in csfilelist!"
	endif
endfunction

function CmCscopeHelp()
	:echo "<C-f>s: Find this C symbol"
	:echo "<C-f>g: Find this definition"	
	:echo "<C-f>a: Find assignments to this symbol"	
	:echo "<C-f>c: Find functions calling this function"	
	:echo "<C-f>i: Find files #including this file"	
	:echo "<C-f>t:Find this text string"	
	:echo "<C-f>d:Find functions called by this function"	
endfunction

function CmShowFileList()
	let i = 0
	while i < (len(g:csfilelist) / 3)	
		:echo i . ". " . g:csfilelist[3 * i + 2] . "\t\t[" . g:csfilelist[3 * i] . ":" . g:csfilelist[3 * i + 1] . "]"
		let i += 1
	endwhile
	:let index = input("please enter index:")
	if (index < 0 || index > ((len( g:csfilelist) / 3) - 1))
		return
	endif
	let g:csfilecursor = index
	:call CmJumpFile()
endfunction

nmap <C-i> <esc>:call CmShowFileList()<cr>
nmap <C-n> <esc>:let @/ = "\\<" . expand("<cword>") . "\\>"<cr>
nmap <C-f> <esc>:call CmCscopeHelp()<cr>
nmap <C-f>w <esc>:call CmJumpBackFile()<cr>
nmap <C-f>b <esc>:call CmJumpForwardFile()<cr>
nmap <C-f>s <esc>:call CmCscopeFind("s",expand("<cword>"))<cr>
nmap <C-f>g <esc>:call CmCscopeFind("g",expand("<cword>"))<cr>
nmap <C-f>a <esc>:call CmCscopeFind("a",expand("<cword>"))<cr>
nmap <C-f>c <esc>:call CmCscopeFind("c",expand("<cword>"))<cr>
nmap <C-f>i <esc>:call CmCscopeFind("i",expand("<cword>"))<cr>
nmap <C-f>t <esc>:call CmCscopeFind("t",expand("<cword>"))<cr>
nmap <C-f>d <esc>:call CmCscopeFind("d",expand("<cword>"))<cr>

部署Taglist

$ mkdir -p $HOME/.vim/pack/downloads/start
$ cd $HOME/.vim/pack/downloads/start
$ git clone https://github.com/yegappan/taglist

使用说明

待补充

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值