代码: 全选
"查找选中文本
vnoremap <c-s> "zy/<c-r>=substitute(escape(@z,'[]*.\\/'),'\n', '\\n', 'g')<cr><cr><cr>
"递归向上级目录查找cscope数据库
if has("gui_running")
if has("cscope")
let s:MyCurDir = getcwd()
let s:MyOldDir = s:MyCurDir
while 1
if filereadable("cscope.out")
if 0 == cscope_connection(2, "cscope.out", s:MyCurDir)
exec "silent! cs add cscope.out " . s:MyCurDir
endif
" exec "setlocal path=\"" . s:MyCurDir . "/**\""
" setlocal cpt-=i
break
endif
if s:MyCurDir =~ '^[a-zA-Z]:\\$'
break
endif
cd ..
let s:MyCurDir = getcwd()
endwhile
exec "cd " . s:MyOldDir . ""
endif
else
if has("cscope")
let s:MyCurDir = getcwd()
let s:MyOldDir = s:MyCurDir
while 1
if filereadable("cscope.out")
if 0 == cscope_connection(2, "cscope.out", s:MyCurDir)
exec "silent! cs add cscope.out " . s:MyCurDir
endif
" exec "setlocal path=\"" . s:MyCurDir . "/**\""
" setlocal cpt-=i
break
endif
if s:MyCurDir =~ '^/$'
break
endif
cd ..
let s:MyCurDir = getcwd()
endwhile
let s:MyOldDir = escape(s:MyOldDir,' ')
exec "cd " . s:MyOldDir
endif
endif
"浮动窗口显示tag, 需要gui, 有点小bug,有时会报错
if has('gui_running')
set ballooneval
set balloondelay=100
set balloonexpr=MyTagDisplay()
function! MyTagDisplay()
if empty(tagfiles())
return ''
endif
let s:MyTagShow = []
let s:MyTaglist = taglist("^" . escape(v:beval_text,'\*.$^') . "$")
for s:MyTag in s:MyTaglist
if s:MyTag['cmd'] =~ '^/\^.*\$/$'
let s:MyTagShow += [strpart(s:MyTag['cmd'],2,strlen(s:MyTag['cmd'])-4)]
endif
endfor
return join (s:MyTagShow,"\n")
endfunction
endif
"使用模板, 新建或打开空文件时自动调用模板
autocmd FileType perl
\ if 1 == line('$') && empty(getline(1)) |
\ if has('gui_running') |
\ 0r D:/xxxxx/templates\pl.pl |
\ else |
\ 0r /xxxxx/templates/pl.pl |
\ endif |
\ normal G |
\ endif
autocmd FileType sh
\ if 1 == line('$') && empty(getline(1)) |
\ if has('gui_running') |
\ 0r D:/xxxx\templates\shell.sh |
\ else |
\ 0r /xxxx/templates/shell.sh |
\ endif |
\ normal G |
\ endif
"查找包含符合特定模式的字符串的行数
function! MyCountMatchLine(MyRegMatch) range
let matchCount = 0
for LineNum in range(a:firstline,a:lastline)
let LineContent = getline(LineNum)
if LineContent =~ a:MyRegMatch
let matchCount += 1
endif
endfor
echo matchCount
endfunction
"查找符合特定模式的字符串的个数
function! MyCountPattern(MyRegMatch) range
let matchCount = 0
for LineNum in range(a:firstline,a:lastline)
let LineContent = getline(LineNum)
let MyLineTmp = substitute(LineContent, a:MyRegMatch, '', 'g')
let matchCount -= strlen(substitute(MyLineTmp, "[^@]", '', 'g'))
let MyLineTmp = substitute(LineContent, a:MyRegMatch, '@', 'g')
let matchCount += strlen(substitute(MyLineTmp, "[^@]", '', 'g'))
endfor
echomsg matchCount
endfunction
"C语言注释和反注释,虽然有EnhancedCommentify,但还是习惯自己写的
"Uncomment
:nnoremap <buffer> <silent> <F2>uc :.s+\(// *\\|/\* *\\| *\*/\)++g<CR>:silent! .s/\|+/\/*/g<CR>:silent! .s/+\|/*\//g<CR>:noh<CR>
"Comment
:nnoremap <buffer> <silent> <F2>cm :silent! .s/\/\*/\|+/g<CR>:silent! .s/\*\//+\|/g<CR>:.s/^\(.*\)$/\/* \1 *\//<CR>:noh<CR>
"Uncomment sub-comment
:vnoremap <buffer> <silent> <F2>usubcm :s+/\@<=\*\@=\\|\*\@<=/\@=+ +g<CR>:noh<CR>
"Virtual comment
:vnoremap <buffer> <silent> * :<ESC>'<O<Home>/*<ESC>'>o<Home>*/<ESC>:silent! '<,'>s/\/\*/\|+/g<CR>:silent! '<,'>s/\*\//+\|/g<CR>:noh<CR>
"Virtual uncomment
:vnoremap <buffer> <silent> u* :s+\(/\*\\|\*/\)++<CR>:silent! '<,'>s/\|+/\/*/g<CR>:silent! '<,'>s/+\|/*\//g<CR>:noh<CR>
"Virtual Partially comment
:vnoremap <buffer> <silent> <F2>pcm xi/* */<ESC>hhP