mirror of
https://github.com/tpope/vim-surround.git
synced 2026-09-10 07:16:17 -04:00
Merge f15d45049d into 3d188ed211
This commit is contained in:
commit
cc18352287
|
|
@ -23,7 +23,7 @@ function! s:inputtarget()
|
|||
while c =~ '^\d\+$'
|
||||
let c .= s:getchar()
|
||||
endwhile
|
||||
if c == " "
|
||||
if c == " " || c == "\\"
|
||||
let c .= s:getchar()
|
||||
endif
|
||||
if c =~ "\<Esc>\|\<C-C>\|\0"
|
||||
|
|
@ -35,7 +35,7 @@ endfunction
|
|||
|
||||
function! s:inputreplacement()
|
||||
let c = s:getchar()
|
||||
if c == " "
|
||||
if c == " " || c == "\\"
|
||||
let c .= s:getchar()
|
||||
endif
|
||||
if c =~ "\<Esc>" || c =~ "\<C-C>"
|
||||
|
|
@ -139,9 +139,13 @@ function! s:wrap(string,char,type,removed,special)
|
|||
endif
|
||||
let pairs = "b()B{}r[]a<>"
|
||||
let extraspace = ""
|
||||
let prepend = ""
|
||||
if newchar =~ '^ '
|
||||
let newchar = strpart(newchar,1)
|
||||
let extraspace = ' '
|
||||
elseif newchar =~ '^\\'
|
||||
let newchar = strpart(newchar,1)
|
||||
let prepend = '\'
|
||||
endif
|
||||
let idx = stridx(pairs,newchar)
|
||||
if newchar == ' '
|
||||
|
|
@ -209,7 +213,7 @@ function! s:wrap(string,char,type,removed,special)
|
|||
endif
|
||||
endif
|
||||
endif
|
||||
elseif newchar ==# 'l' || newchar == '\'
|
||||
elseif newchar ==# 'l'
|
||||
" LaTeX
|
||||
let env = input('\begin{')
|
||||
if env != ""
|
||||
|
|
@ -239,11 +243,13 @@ function! s:wrap(string,char,type,removed,special)
|
|||
elseif idx >= 0
|
||||
let spc = (idx % 3) == 1 ? " " : ""
|
||||
let idx = idx / 3 * 3
|
||||
let before = strpart(pairs,idx+1,1) . spc
|
||||
let after = spc . strpart(pairs,idx+2,1)
|
||||
let before = prepend . strpart(pairs,idx+1,1) . spc
|
||||
let after = spc . prepend . strpart(pairs,idx+2,1)
|
||||
let prepend = ""
|
||||
elseif newchar == "\<C-[>" || newchar == "\<C-]>"
|
||||
let before = "{\n\t"
|
||||
let after = "\n}"
|
||||
let before = prepend . "{\n\t"
|
||||
let after = "\n" . prepend . "}"
|
||||
let prepend = ""
|
||||
elseif newchar !~ '\a'
|
||||
let before = newchar
|
||||
let after = newchar
|
||||
|
|
@ -252,6 +258,10 @@ function! s:wrap(string,char,type,removed,special)
|
|||
let after = ''
|
||||
endif
|
||||
let after = substitute(after ,'\n','\n'.initspaces,'g')
|
||||
if prepend != ""
|
||||
let before = prepend.before
|
||||
let after = prepend.after
|
||||
endif
|
||||
if type ==# 'V' || (a:special && type ==# "v")
|
||||
let before = substitute(before,' \+$','','')
|
||||
let after = substitute(after ,'^ \+','','')
|
||||
|
|
@ -371,11 +381,25 @@ function! s:dosurround(...) " {{{1
|
|||
set startofline
|
||||
let scount = v:count1
|
||||
let char = (a:0 ? a:1 : s:inputtarget())
|
||||
let leftchar = char
|
||||
let rightchar = char
|
||||
let spc = ""
|
||||
let escape = ""
|
||||
if char =~ '^\d\+'
|
||||
let scount = scount * matchstr(char,'^\d\+')
|
||||
let char = substitute(char,'^\d\+','','')
|
||||
endif
|
||||
if char =~ '^\\'
|
||||
let char = strpart(char,1)
|
||||
let escape = 1
|
||||
let pairs = "b()B{}r[]a<>"
|
||||
let idx = stridx(pairs, char)
|
||||
if idx >= 0
|
||||
let idx = idx / 3 * 3
|
||||
let leftchar = strpart(pairs, idx+1,1)
|
||||
let rightchar = strpart(pairs, idx+2,1)
|
||||
endif
|
||||
endif
|
||||
if char =~ '^ '
|
||||
let char = strpart(char,1)
|
||||
let spc = 1
|
||||
|
|
@ -403,7 +427,14 @@ function! s:dosurround(...) " {{{1
|
|||
let otype = getregtype('"')
|
||||
call setreg('"',"")
|
||||
let strcount = (scount == 1 ? "" : scount)
|
||||
if char == '/'
|
||||
if escape
|
||||
let savecursor = getcurpos()
|
||||
if search('\\'.rightchar, "W") && search('\\'.leftchar, "besW")
|
||||
norm! ld`'
|
||||
else
|
||||
call setpos('.', savecursor)
|
||||
endif
|
||||
elseif char == '/'
|
||||
exe 'norm! '.strcount.'[/d'.strcount.']/'
|
||||
elseif char =~# '[[:punct:][:space:]]' && char !~# '[][(){}<>"''`]'
|
||||
exe 'norm! T'.char
|
||||
|
|
@ -426,7 +457,11 @@ function! s:dosurround(...) " {{{1
|
|||
endif
|
||||
let oldline = getline('.')
|
||||
let oldlnum = line('.')
|
||||
if char ==# "p"
|
||||
if escape
|
||||
call search('\\'.leftchar, "bW")
|
||||
call search('\%#\@!\\'.rightchar, "seW")
|
||||
norm! v`'d
|
||||
elseif char ==# "p"
|
||||
call setreg('"','','V')
|
||||
elseif char ==# "s" || char ==# "w" || char ==# "W"
|
||||
" Do nothing
|
||||
|
|
|
|||
Loading…
Reference in a new issue