写个自己喜欢的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 "s: Find this C symbol"
	:echo "g: Find this definition"	
	:echo "a: Find assignments to this symbol"	
	:echo "c: Find functions calling this function"	
	:echo "i: Find files #including this file"	
	:echo "t:Find this text string"	
	:echo "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("") . "\\>"<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(""))<cr>
nmap <C-f>g <esc>:call CmCscopeFind("g",expand(""))<cr>
nmap <C-f>a <esc>:call CmCscopeFind("a",expand(""))<cr>
nmap <C-f>c <esc>:call CmCscopeFind("c",expand(""))<cr>
nmap <C-f>i <esc>:call CmCscopeFind("i",expand(""))<cr>
nmap <C-f>t <esc>:call CmCscopeFind("t",expand(""))<cr>
nmap <C-f>d <esc>:call CmCscopeFind("d",expand(""))<cr>

使用说明

待补充

你可能感兴趣的:(工具,vim)