Update vim-surround to v2.1
This commit is contained in:
parent
503c765343
commit
7959b4e930
2 changed files with 24 additions and 30 deletions
|
@ -130,10 +130,9 @@ code blocks in C-style languages, <C-}> (which is really <C-]>) adds braces on
|
||||||
lines separate from the content.
|
lines separate from the content.
|
||||||
|
|
||||||
If t or < is used, Vim prompts for an HTML/XML tag to insert. You may specify
|
If t or < is used, Vim prompts for an HTML/XML tag to insert. You may specify
|
||||||
attributes here and they will be stripped from the closing tag. If replacing a
|
attributes here and they will be stripped from the closing tag. End your
|
||||||
tag, its attributes are kept in the new tag. End your input with > to discard
|
input by pressing <CR> or >. If <C-T> is used, the tags will appear on lines
|
||||||
the those attributes. If <C-T> is used, the tags will appear on lines by
|
by themselves.
|
||||||
themselves.
|
|
||||||
|
|
||||||
If s is used, a leading but not trailing space is added. This is useful for
|
If s is used, a leading but not trailing space is added. This is useful for
|
||||||
removing parentheses from a function call with csbs.
|
removing parentheses from a function call with csbs.
|
||||||
|
|
|
@ -92,7 +92,7 @@ function! s:process(string)
|
||||||
let m = matchstr(a:string,nr2char(i).'.\{-\}\ze'.nr2char(i))
|
let m = matchstr(a:string,nr2char(i).'.\{-\}\ze'.nr2char(i))
|
||||||
if m != ''
|
if m != ''
|
||||||
let m = substitute(strpart(m,1),'\r.*','','')
|
let m = substitute(strpart(m,1),'\r.*','','')
|
||||||
let repl_{i} = input(match(m,'\w\+$') >= 0 ? m.': ' : m)
|
let repl_{i} = input(substitute(m,':\s*$','','').': ')
|
||||||
endif
|
endif
|
||||||
endfor
|
endfor
|
||||||
let s = ""
|
let s = ""
|
||||||
|
@ -124,12 +124,13 @@ function! s:process(string)
|
||||||
return s
|
return s
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:wrap(string,char,type,removed,special)
|
function! s:wrap(string,char,type,...)
|
||||||
let keeper = a:string
|
let keeper = a:string
|
||||||
let newchar = a:char
|
let newchar = a:char
|
||||||
let s:input = ""
|
let s:input = ""
|
||||||
let type = a:type
|
let type = a:type
|
||||||
let linemode = type ==# 'V' ? 1 : 0
|
let linemode = type ==# 'V' ? 1 : 0
|
||||||
|
let special = a:0 ? a:1 : 0
|
||||||
let before = ""
|
let before = ""
|
||||||
let after = ""
|
let after = ""
|
||||||
if type ==# "V"
|
if type ==# "V"
|
||||||
|
@ -164,13 +165,13 @@ function! s:wrap(string,char,type,removed,special)
|
||||||
elseif newchar ==# ':'
|
elseif newchar ==# ':'
|
||||||
let before = ':'
|
let before = ':'
|
||||||
let after = ''
|
let after = ''
|
||||||
elseif newchar =~# "[tT\<C-T><]"
|
elseif newchar =~# "[tT\<C-T><,]"
|
||||||
let dounmapp = 0
|
let dounmapp = 0
|
||||||
let dounmapb = 0
|
let dounmapb = 0
|
||||||
if !maparg(">","c")
|
if !maparg(">","c")
|
||||||
let dounmapb = 1
|
let dounmapb = 1
|
||||||
" Hide from AsNeeded
|
" Hide from AsNeeded
|
||||||
exe "cn"."oremap > ><CR>"
|
exe "cn"."oremap > <CR>"
|
||||||
endif
|
endif
|
||||||
let default = ""
|
let default = ""
|
||||||
if newchar ==# "T"
|
if newchar ==# "T"
|
||||||
|
@ -180,27 +181,21 @@ function! s:wrap(string,char,type,removed,special)
|
||||||
let default = matchstr(s:lastdel,'<\zs.\{-\}\ze>')
|
let default = matchstr(s:lastdel,'<\zs.\{-\}\ze>')
|
||||||
endif
|
endif
|
||||||
let tag = input("<",default)
|
let tag = input("<",default)
|
||||||
|
echo "<".substitute(tag,'>*$','>','')
|
||||||
if dounmapb
|
if dounmapb
|
||||||
silent! cunmap >
|
silent! cunmap >
|
||||||
endif
|
endif
|
||||||
let s:input = tag
|
let s:input = tag
|
||||||
if tag != ""
|
if tag != ""
|
||||||
let keepAttributes = ( match(tag, ">$") == -1 )
|
|
||||||
let tag = substitute(tag,'>*$','','')
|
let tag = substitute(tag,'>*$','','')
|
||||||
let attributes = ""
|
|
||||||
if keepAttributes
|
|
||||||
let attributes = matchstr(a:removed, '<[^ \t\n]\+\zs\_.\{-\}\ze>')
|
|
||||||
endif
|
|
||||||
let s:input = tag . '>'
|
let s:input = tag . '>'
|
||||||
|
let before = '<'.tag.'>'
|
||||||
if tag =~ '/$'
|
if tag =~ '/$'
|
||||||
let tag = substitute(tag, '/$', '', '')
|
|
||||||
let before = '<'.tag.attributes.' />'
|
|
||||||
let after = ''
|
let after = ''
|
||||||
else
|
else
|
||||||
let before = '<'.tag.attributes.'>'
|
|
||||||
let after = '</'.substitute(tag,' .*','','').'>'
|
let after = '</'.substitute(tag,' .*','','').'>'
|
||||||
endif
|
endif
|
||||||
if newchar == "\<C-T>"
|
if newchar == "\<C-T>" || newchar == ","
|
||||||
if type ==# "v" || type ==# "V"
|
if type ==# "v" || type ==# "V"
|
||||||
let before .= "\n\t"
|
let before .= "\n\t"
|
||||||
endif
|
endif
|
||||||
|
@ -212,11 +207,10 @@ function! s:wrap(string,char,type,removed,special)
|
||||||
elseif newchar ==# 'l' || newchar == '\'
|
elseif newchar ==# 'l' || newchar == '\'
|
||||||
" LaTeX
|
" LaTeX
|
||||||
let env = input('\begin{')
|
let env = input('\begin{')
|
||||||
if env != ""
|
|
||||||
let s:input = env."\<CR>"
|
|
||||||
let env = '{' . env
|
let env = '{' . env
|
||||||
let env .= s:closematch(env)
|
let env .= s:closematch(env)
|
||||||
echo '\begin'.env
|
echo '\begin'.env
|
||||||
|
if env != ""
|
||||||
let before = '\begin'.env
|
let before = '\begin'.env
|
||||||
let after = '\end'.matchstr(env,'[^}]*').'}'
|
let after = '\end'.matchstr(env,'[^}]*').'}'
|
||||||
endif
|
endif
|
||||||
|
@ -252,7 +246,7 @@ function! s:wrap(string,char,type,removed,special)
|
||||||
let after = ''
|
let after = ''
|
||||||
endif
|
endif
|
||||||
let after = substitute(after ,'\n','\n'.initspaces,'g')
|
let after = substitute(after ,'\n','\n'.initspaces,'g')
|
||||||
if type ==# 'V' || (a:special && type ==# "v")
|
if type ==# 'V' || (special && type ==# "v")
|
||||||
let before = substitute(before,' \+$','','')
|
let before = substitute(before,' \+$','','')
|
||||||
let after = substitute(after ,'^ \+','','')
|
let after = substitute(after ,'^ \+','','')
|
||||||
if after !~ '^\n'
|
if after !~ '^\n'
|
||||||
|
@ -265,7 +259,7 @@ function! s:wrap(string,char,type,removed,special)
|
||||||
endif
|
endif
|
||||||
if before !~ '\n\s*$'
|
if before !~ '\n\s*$'
|
||||||
let before .= "\n"
|
let before .= "\n"
|
||||||
if a:special
|
if special
|
||||||
let before .= "\t"
|
let before .= "\t"
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
@ -295,10 +289,11 @@ function! s:wrap(string,char,type,removed,special)
|
||||||
return keeper
|
return keeper
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:wrapreg(reg,char,removed,special)
|
function! s:wrapreg(reg,char,...)
|
||||||
let orig = getreg(a:reg)
|
let orig = getreg(a:reg)
|
||||||
let type = substitute(getregtype(a:reg),'\d\+$','','')
|
let type = substitute(getregtype(a:reg),'\d\+$','','')
|
||||||
let new = s:wrap(orig,a:char,type,a:removed,a:special)
|
let special = a:0 ? a:1 : 0
|
||||||
|
let new = s:wrap(orig,a:char,type,special)
|
||||||
call setreg(a:reg,new,type)
|
call setreg(a:reg,new,type)
|
||||||
endfunction
|
endfunction
|
||||||
" }}}1
|
" }}}1
|
||||||
|
@ -319,7 +314,7 @@ function! s:insert(...) " {{{1
|
||||||
set clipboard-=unnamed clipboard-=unnamedplus
|
set clipboard-=unnamed clipboard-=unnamedplus
|
||||||
let reg_save = @@
|
let reg_save = @@
|
||||||
call setreg('"',"\r",'v')
|
call setreg('"',"\r",'v')
|
||||||
call s:wrapreg('"',char,"",linemode)
|
call s:wrapreg('"',char,linemode)
|
||||||
" If line mode is used and the surrounding consists solely of a suffix,
|
" If line mode is used and the surrounding consists solely of a suffix,
|
||||||
" remove the initial newline. This fits a use case of mine but is a
|
" remove the initial newline. This fits a use case of mine but is a
|
||||||
" little inconsistent. Is there anyone that would prefer the simpler
|
" little inconsistent. Is there anyone that would prefer the simpler
|
||||||
|
@ -386,7 +381,7 @@ function! s:dosurround(...) " {{{1
|
||||||
let strcount = (scount == 1 ? "" : scount)
|
let strcount = (scount == 1 ? "" : scount)
|
||||||
if char == '/'
|
if char == '/'
|
||||||
exe 'norm! '.strcount.'[/d'.strcount.']/'
|
exe 'norm! '.strcount.'[/d'.strcount.']/'
|
||||||
elseif char =~# '[[:punct:][:space:]]' && char !~# '[][(){}<>"''`]'
|
elseif char =~# '[[:punct:]]' && char !~# '[][(){}<>"''`]'
|
||||||
exe 'norm! T'.char
|
exe 'norm! T'.char
|
||||||
if getline('.')[col('.')-1] == char
|
if getline('.')[col('.')-1] == char
|
||||||
exe 'norm! l'
|
exe 'norm! l'
|
||||||
|
@ -416,7 +411,7 @@ function! s:dosurround(...) " {{{1
|
||||||
norm! "_x
|
norm! "_x
|
||||||
call setreg('"','/**/',"c")
|
call setreg('"','/**/',"c")
|
||||||
let keeper = substitute(substitute(keeper,'^/\*\s\=','',''),'\s\=\*$','','')
|
let keeper = substitute(substitute(keeper,'^/\*\s\=','',''),'\s\=\*$','','')
|
||||||
elseif char =~# '[[:punct:][:space:]]' && char !~# '[][(){}<>]'
|
elseif char =~# '[[:punct:]]' && char !~# '[][(){}<>]'
|
||||||
exe 'norm! F'.char
|
exe 'norm! F'.char
|
||||||
exe 'norm! df'.char
|
exe 'norm! df'.char
|
||||||
else
|
else
|
||||||
|
@ -447,7 +442,7 @@ function! s:dosurround(...) " {{{1
|
||||||
call setreg('"',keeper,regtype)
|
call setreg('"',keeper,regtype)
|
||||||
if newchar != ""
|
if newchar != ""
|
||||||
let special = a:0 > 2 ? a:3 : 0
|
let special = a:0 > 2 ? a:3 : 0
|
||||||
call s:wrapreg('"',newchar,removed,special)
|
call s:wrapreg('"',newchar, special)
|
||||||
endif
|
endif
|
||||||
silent exe 'norm! ""'.pcmd.'`['
|
silent exe 'norm! ""'.pcmd.'`['
|
||||||
if removed =~ '\n' || okeeper =~ '\n' || getreg('"') =~ '\n'
|
if removed =~ '\n' || okeeper =~ '\n' || getreg('"') =~ '\n'
|
||||||
|
@ -523,7 +518,7 @@ function! s:opfunc(type,...) " {{{1
|
||||||
let keeper = substitute(keeper,'\_s\@<!\s*$','','')
|
let keeper = substitute(keeper,'\_s\@<!\s*$','','')
|
||||||
endif
|
endif
|
||||||
call setreg(reg,keeper,type)
|
call setreg(reg,keeper,type)
|
||||||
call s:wrapreg(reg,char,"",a:0 && a:1)
|
call s:wrapreg(reg,char,a:0 && a:1)
|
||||||
if type ==# "v" && a:type !=# "v" && append != ""
|
if type ==# "v" && a:type !=# "v" && append != ""
|
||||||
call setreg(reg,append,"ac")
|
call setreg(reg,append,"ac")
|
||||||
endif
|
endif
|
||||||
|
|
Loading…
Reference in a new issue