Case sensitive comparisons; minor tweaks

This commit is contained in:
Tim Pope 2006-10-29 21:03:15 +00:00
parent d99a4b9e01
commit 62021e986e

View File

@ -126,6 +126,9 @@ endfunction
function! s:inputtarget() function! s:inputtarget()
let c = s:getchar() let c = s:getchar()
if c == " "
let c = c . s:getchar()
endif
if c =~ "\<Esc>\|\<C-C>\|\0" if c =~ "\<Esc>\|\<C-C>\|\0"
return "" return ""
else else
@ -164,7 +167,7 @@ function! s:wrap(string,char,...) " {{{1
let linemode = a:0 ? a:1 : 0 let linemode = a:0 ? a:1 : 0
let before = "" let before = ""
let after = "" let after = ""
" Duplicate b's are just placeholders " Duplicate b's are just placeholders (removed)
let pairs = "b()B{}r[]a<>" let pairs = "b()B{}r[]a<>"
let extraspace = "" let extraspace = ""
if newchar =~ '^ ' if newchar =~ '^ '
@ -178,10 +181,10 @@ function! s:wrap(string,char,...) " {{{1
elseif exists("g:surround_".char2nr(newchar)) elseif exists("g:surround_".char2nr(newchar))
let before = matchstr(g:surround_{char2nr(newchar)},'.*\ze\n') let before = matchstr(g:surround_{char2nr(newchar)},'.*\ze\n')
let after = matchstr(g:surround_{char2nr(newchar)},'\n\zs.*') let after = matchstr(g:surround_{char2nr(newchar)},'\n\zs.*')
elseif newchar == "p" elseif newchar ==# "p"
let before = "\n" let before = "\n"
let after = "\n\n" let after = "\n\n"
elseif newchar == "t" || newchar == "T" || newchar == "<" elseif newchar ==# "t" || newchar ==# "T" || newchar == "<"
let dounmapr = 0 let dounmapr = 0
let dounmapb = 0 let dounmapb = 0
if !mapcheck("<CR>","c") if !mapcheck("<CR>","c")
@ -193,7 +196,7 @@ function! s:wrap(string,char,...) " {{{1
cnoremap > ><CR> cnoremap > ><CR>
endif endif
let default = "" let default = ""
if newchar == "T" if newchar ==# "T"
let default = matchstr(@@,'<\zs.\{-\}\ze>') let default = matchstr(@@,'<\zs.\{-\}\ze>')
endif endif
let tag = input("<",default) let tag = input("<",default)
@ -209,26 +212,23 @@ function! s:wrap(string,char,...) " {{{1
let before = "<".tag.">" let before = "<".tag.">"
let after = "</".substitute(tag," .*",'','').">" let after = "</".substitute(tag," .*",'','').">"
endif endif
elseif newchar == 'l' || newchar == '\' elseif newchar ==# 'l' || newchar == '\'
let dounmapr = 0
if !mapcheck("<CR>","c")
let dounmapr = 1
cnoremap <silent> <CR> <C-R>=<SID>closematch()<CR><CR>
endif
let env = input('\begin','{') let env = input('\begin','{')
let env = env . s:closematch(env)
echo '\begin'.env echo '\begin'.env
if dounmapr
silent! cunmap <CR>
endif
if env != "" if env != ""
let before = '\begin'.env let before = '\begin'.env
let after = '\end'.matchstr(env,'[^}]*').'}' let after = '\end'.matchstr(env,'[^}]*').'}'
endif endif
elseif newchar == 'f' elseif newchar ==# 'f' || newchar ==# 'F'
let func = input('function: ') let func = input('function: ')
if func != "" if func != ""
let before = substitute(func,'($','','').'(' let before = substitute(func,'($','','').'('
let after = ')' let after = ')'
if newchar ==# 'F'
let before = before . ' '
let after = ' ' . after
endif
endif endif
elseif idx >= 0 elseif idx >= 0
let spc = (idx % 3) == 1 ? " " : "" let spc = (idx % 3) == 1 ? " " : ""
@ -288,7 +288,7 @@ function! s:reindent() " {{{1
endfunction " }}}1 endfunction " }}}1
function! s:dosurround(...) " {{{1 function! s:dosurround(...) " {{{1
let g:scount = v:count1 let scount = v:count1
let char = (a:0 ? a:1 : s:inputtarget()) let char = (a:0 ? a:1 : s:inputtarget())
let spc = "" let spc = ""
if char =~ '^ ' if char =~ '^ '
@ -305,7 +305,7 @@ function! s:dosurround(...) " {{{1
let append = "" let append = ""
let original = @@ let original = @@
let @@ = "" let @@ = ""
exe "norm di".char exe "norm d".(scount==1 ? "": scount)."i".char
"exe "norm vi".char."d" "exe "norm vi".char."d"
let keeper = @@ let keeper = @@
let okeeper = keeper " for reindent below let okeeper = keeper " for reindent below
@ -315,11 +315,11 @@ function! s:dosurround(...) " {{{1
endif endif
let oldline = getline('.') let oldline = getline('.')
let oldlnum = line('.') let oldlnum = line('.')
if char == "p" if char ==# "p"
let append = matchstr(keeper,'\n*\%$') let append = matchstr(keeper,'\n*\%$')
let keeper = substitute(keeper,'\n*\%$','','') let keeper = substitute(keeper,'\n*\%$','','')
let @@ = "" let @@ = ""
elseif char == "s" || char == "w" || char == "W" elseif char ==# "s" || char ==# "w" || char ==# "W"
" Do nothing " Do nothing
let @@ = "" let @@ = ""
elseif char =~ "[\"'`]" elseif char =~ "[\"'`]"
@ -337,11 +337,11 @@ function! s:dosurround(...) " {{{1
"let g:rem2 = rem2 "let g:rem2 = rem2
"let g:keeper = keeper "let g:keeper = keeper
let regtype = getregtype('"') let regtype = getregtype('"')
if char =~ '[\[({<]' || spc if char =~# '[\[({<T]' || spc
let keeper = substitute(keeper,'^\s\+','','') let keeper = substitute(keeper,'^\s\+','','')
let keeper = substitute(keeper,'\s\+$','','') let keeper = substitute(keeper,'\s\+$','','')
endif endif
if oldtail == rem2 && col('.') + 1 == col('$') if oldtail ==# rem2 && col('.') + 1 == col('$')
if oldhead =~# '^\s*$' && a:0 < 2 if oldhead =~# '^\s*$' && a:0 < 2
"let keeper = substitute(keeper,'\n\s*','\n','') "let keeper = substitute(keeper,'\n\s*','\n','')
let keeper = substitute(keeper,oldhead.'\%$','','') let keeper = substitute(keeper,oldhead.'\%$','','')
@ -354,7 +354,7 @@ function! s:dosurround(...) " {{{1
endif endif
let pcmd = "P" let pcmd = "P"
endif endif
if line('.') < oldlnum && regtype == "V" if line('.') < oldlnum && regtype ==# "V"
let pcmd = "p" let pcmd = "p"
endif endif
if removed =~ '\n$' if removed =~ '\n$'
@ -368,7 +368,7 @@ function! s:dosurround(...) " {{{1
"endif "endif
"let g:removed = removed "let g:removed = removed
if newchar != "" if newchar != ""
let keeper = s:wrap(keeper,newchar,char == "p") . append let keeper = s:wrap(keeper,newchar,char ==# "p") . append
endif endif
let @@ = substitute(keeper,'\n\s+\n','\n\n','g') let @@ = substitute(keeper,'\n\s+\n','\n\n','g')
call setreg('"','','a'.regtype) call setreg('"','','a'.regtype)
@ -402,12 +402,12 @@ function! s:opfunc(type) " {{{1
let sel_save = &selection let sel_save = &selection
let &selection = "inclusive" let &selection = "inclusive"
let reg_save = @@ let reg_save = @@
let linemode = (a:type == "line" || a:type == "V") let linemode = (a:type == "line" || a:type ==# "V")
if a:type == "char" if a:type == "char"
silent norm! `[v`]y silent norm! `[v`]y
elseif a:type == "line" elseif a:type == "line"
silent norm! '[V']y silent norm! '[V']y
elseif a:type == "v" || a:type == "V" elseif a:type ==# "v" || a:type ==# "V"
silent norm! gvy silent norm! gvy
elseif a:type =~ '^\d\+$' elseif a:type =~ '^\d\+$'
silent exe 'norm! ^v'.a:type.'$hy' silent exe 'norm! ^v'.a:type.'$hy'
@ -424,6 +424,7 @@ function! s:opfunc(type) " {{{1
let append = matchstr(keeper,'\s*$') let append = matchstr(keeper,'\s*$')
let keeper = substitute(keeper,'\s*$','','') let keeper = substitute(keeper,'\s*$','','')
endif endif
let @@ = reg_save " s:wrap() may peek at this
let keeper = s:wrap(keeper,char,linemode) . append let keeper = s:wrap(keeper,char,linemode) . append
let @@ = keeper let @@ = keeper
silent norm! gvp`[ silent norm! gvp`[
@ -434,9 +435,9 @@ function! s:opfunc(type) " {{{1
let &selection = sel_save let &selection = sel_save
endfunction " }}}1 endfunction " }}}1
function! s:closematch() function! s:closematch(str)
" Close an open (, {, [, or < on the command line. " Close an open (, {, [, or < on the command line.
let tail = matchstr(getcmdline(),'.[^\[\](){}<>]*$') let tail = matchstr(a:str,'.[^\[\](){}<>]*$')
if tail =~ '^\[.\+' if tail =~ '^\[.\+'
return "]" return "]"
elseif tail =~ '^(.\+' elseif tail =~ '^(.\+'
@ -455,8 +456,8 @@ function! s:closedcmd()
return getcmdline() . cm return getcmdline() . cm
endfunction endfunction
nnoremap <silent> <Plug>DSurround :call <SID>dosurround(<SID>inputtarget())<CR> nnoremap <silent> <Plug>DSurround :<C-U>call <SID>dosurround(<SID>inputtarget())<CR>
nnoremap <silent> <Plug>CSurround :call <SID>changesurround()<CR> nnoremap <silent> <Plug>CSurround :<C-U>call <SID>changesurround()<CR>
nnoremap <silent> <Plug>YSurround :set opfunc=<SID>opfunc<CR>g@ nnoremap <silent> <Plug>YSurround :set opfunc=<SID>opfunc<CR>g@
nnoremap <silent> <Plug>YSSurround :<C-U>call <SID>opfunc(v:count1)<CR> nnoremap <silent> <Plug>YSSurround :<C-U>call <SID>opfunc(v:count1)<CR>
vnoremap <silent> <Plug>VSurround :<C-U>call <SID>opfunc(visualmode())<CR> vnoremap <silent> <Plug>VSurround :<C-U>call <SID>opfunc(visualmode())<CR>