mirror of
https://github.com/tpope/vim-surround.git
synced 2025-12-08 21:54:46 +08:00
surround_indent now works in insert mode; Added <C-]> for braces
This commit is contained in:
@@ -134,7 +134,6 @@ function! s:process(string)
|
|||||||
let insertion = repl_{char2nr(char)}
|
let insertion = repl_{char2nr(char)}
|
||||||
let subs = strpart(a:string,i+1,next-i-1)
|
let subs = strpart(a:string,i+1,next-i-1)
|
||||||
let subs = matchstr(subs,'\r.*')
|
let subs = matchstr(subs,'\r.*')
|
||||||
echo substitute(subs,'\r','R','g')
|
|
||||||
while subs =~ '^\r.*\r'
|
while subs =~ '^\r.*\r'
|
||||||
let sub = matchstr(subs,"^\r\\zs[^\r]*\r[^\r]*")
|
let sub = matchstr(subs,"^\r\\zs[^\r]*\r[^\r]*")
|
||||||
let subs = strpart(subs,strlen(sub)+1)
|
let subs = strpart(subs,strlen(sub)+1)
|
||||||
@@ -185,17 +184,23 @@ function! s:wrap(string,char,type,...)
|
|||||||
let before = "\n"
|
let before = "\n"
|
||||||
let after = "\n\n"
|
let after = "\n\n"
|
||||||
elseif newchar =~# "[tT\<C-T><,]"
|
elseif newchar =~# "[tT\<C-T><,]"
|
||||||
"let dounmapr = 0
|
let dounmapp = 0
|
||||||
let dounmapb = 0
|
let dounmapb = 0
|
||||||
"if !mapcheck("<CR>","c")
|
if !maparg(">","c")
|
||||||
"let dounmapr = 1
|
|
||||||
"cnoremap <CR> ><CR>
|
|
||||||
"endif
|
|
||||||
if !mapcheck(">","c")
|
|
||||||
let dounmapb= 1
|
let dounmapb= 1
|
||||||
cnoremap > ><CR>
|
" Hide from AsNeeded
|
||||||
|
exe "cn"."oremap > <CR>"
|
||||||
|
exe "cn"."oremap % %<C-V>"
|
||||||
|
"cm ap > <C-R>=getcmdline() =~ '^[^%?].*[%?]$' ? "\026\076" : "\026\076\015"<CR>
|
||||||
endif
|
endif
|
||||||
let default = ""
|
let default = ""
|
||||||
|
if !maparg("%","c")
|
||||||
|
" This is to help when typing things like
|
||||||
|
" <a href="/images/<%= @image.filename %>">
|
||||||
|
" The downside is it breaks backspace, so lets disable it for now
|
||||||
|
"let dounmapp= 1
|
||||||
|
"exe "cn"."oremap % %<C-V>"
|
||||||
|
endif
|
||||||
if newchar ==# "T"
|
if newchar ==# "T"
|
||||||
if !exists("s:lastdel")
|
if !exists("s:lastdel")
|
||||||
let s:lastdel = ""
|
let s:lastdel = ""
|
||||||
@@ -210,10 +215,17 @@ function! s:wrap(string,char,type,...)
|
|||||||
if dounmapb
|
if dounmapb
|
||||||
silent! cunmap >
|
silent! cunmap >
|
||||||
endif
|
endif
|
||||||
|
if dounmapp
|
||||||
|
silent! cunmap %
|
||||||
|
endif
|
||||||
if tag != ""
|
if tag != ""
|
||||||
let tag = substitute(tag,'>*$','','')
|
let tag = substitute(tag,'>*$','','')
|
||||||
let before = "<".tag.">"
|
let before = '<'.tag.'>'
|
||||||
let after = "</".substitute(tag," .*",'','').">"
|
if tag =~ '/$'
|
||||||
|
let after = ''
|
||||||
|
else
|
||||||
|
let after = '</'.substitute(tag,' .*','','').'>'
|
||||||
|
endif
|
||||||
if newchar == "\<C-T>" || newchar == ","
|
if newchar == "\<C-T>" || newchar == ","
|
||||||
if type ==# "v" || type ==# "V"
|
if type ==# "v" || type ==# "V"
|
||||||
let before = before . "\n\t"
|
let before = before . "\n\t"
|
||||||
@@ -254,6 +266,9 @@ function! s:wrap(string,char,type,...)
|
|||||||
let idx = idx / 3 * 3
|
let idx = idx / 3 * 3
|
||||||
let before = strpart(pairs,idx+1,1) . spc
|
let before = strpart(pairs,idx+1,1) . spc
|
||||||
let after = spc . strpart(pairs,idx+2,1)
|
let after = spc . strpart(pairs,idx+2,1)
|
||||||
|
elseif newchar == "\<C-[>" || newchar == "\<C-]>"
|
||||||
|
let before = "{\n\t"
|
||||||
|
let after = "\n}"
|
||||||
elseif newchar !~ '\a'
|
elseif newchar !~ '\a'
|
||||||
let before = newchar
|
let before = newchar
|
||||||
let after = newchar
|
let after = newchar
|
||||||
@@ -272,6 +287,8 @@ function! s:wrap(string,char,type,...)
|
|||||||
endif
|
endif
|
||||||
if keeper !~ '\n$' && after !~ '^\n'
|
if keeper !~ '\n$' && after !~ '^\n'
|
||||||
let keeper = keeper . "\n"
|
let keeper = keeper . "\n"
|
||||||
|
elseif keeper =~ '\n$' && after =~ '^\n'
|
||||||
|
let after = strpart(after,1)
|
||||||
endif
|
endif
|
||||||
if before !~ '\n\s*$'
|
if before !~ '\n\s*$'
|
||||||
let before = before . "\n"
|
let before = before . "\n"
|
||||||
@@ -341,10 +358,14 @@ function! s:insert(...) " {{{1
|
|||||||
"call setreg('"',substitute(getreg('"'),'^\s\+','',''),'c')
|
"call setreg('"',substitute(getreg('"'),'^\s\+','',''),'c')
|
||||||
"endif
|
"endif
|
||||||
if col('.') >= col('$')
|
if col('.') >= col('$')
|
||||||
norm! ""p`]
|
norm! ""p
|
||||||
else
|
else
|
||||||
norm! ""P`]
|
norm! ""P
|
||||||
endif
|
endif
|
||||||
|
if @@ =~ '\r.*\n'
|
||||||
|
call s:reindent()
|
||||||
|
endif
|
||||||
|
norm! `]
|
||||||
call search('\r','bW')
|
call search('\r','bW')
|
||||||
let @@ = reg_save
|
let @@ = reg_save
|
||||||
let &clipboard = cb_save
|
let &clipboard = cb_save
|
||||||
@@ -352,7 +373,7 @@ function! s:insert(...) " {{{1
|
|||||||
endfunction " }}}1
|
endfunction " }}}1
|
||||||
|
|
||||||
function! s:reindent() " {{{1
|
function! s:reindent() " {{{1
|
||||||
if (exists("b:surround_indent") || exists("g:surround_indent"))
|
if exists("b:surround_indent") ? b:surround_indent : (exists("g:surround_indent") && g:surround_indent)
|
||||||
silent norm! '[=']
|
silent norm! '[=']
|
||||||
endif
|
endif
|
||||||
endfunction " }}}1
|
endfunction " }}}1
|
||||||
@@ -565,19 +586,19 @@ if !exists("g:surround_no_mappings") || ! g:surround_no_mappings
|
|||||||
nmap ySS <Plug>YSsurround
|
nmap ySS <Plug>YSsurround
|
||||||
if !hasmapto("<Plug>Vsurround","v")
|
if !hasmapto("<Plug>Vsurround","v")
|
||||||
if exists(":xmap")
|
if exists(":xmap")
|
||||||
xmap s <Plug>Vsurround
|
xmap s <Plug>Vsurround
|
||||||
else
|
else
|
||||||
vmap s <Plug>Vsurround
|
vmap s <Plug>Vsurround
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
if !hasmapto("<Plug>VSurround","v")
|
if !hasmapto("<Plug>VSurround","v")
|
||||||
if exists(":xmap")
|
if exists(":xmap")
|
||||||
xmap S <Plug>VSurround
|
xmap S <Plug>VSurround
|
||||||
else
|
else
|
||||||
vmap S <Plug>VSurround
|
vmap S <Plug>VSurround
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
if !hasmapto("<Plug>Isurround","i") && !mapcheck("<C-S>","i")
|
if !hasmapto("<Plug>Isurround","i") && "" == mapcheck("<C-S>","i")
|
||||||
imap <C-S> <Plug>Isurround
|
imap <C-S> <Plug>Isurround
|
||||||
endif
|
endif
|
||||||
imap <C-G>s <Plug>Isurround
|
imap <C-G>s <Plug>Isurround
|
||||||
|
|||||||
Reference in New Issue
Block a user