14 Commits

Author SHA1 Message Date
Tim Pope fd75eb2cb2 surround.vim 2.1
* Handle arbitrary punctuation delimiters with cs and ds.
* Default to automatic indenting.
* Provide cS to force surroundings on separate lines.
* Support for disabling mappings only for insert mode.
* Add repeat.vim support to surround with function.
* Work around 'nomagic'.
2015-02-08 14:06:19 -05:00
Tim Pope 6afb2d90e3 Merge pull request #158 from itspriddle/patch-1
Fix typo in `repeat#set` call
2015-02-04 16:50:48 -06:00
Joshua Priddle 7e8f414b8c Fix typo in repeat#set call 2015-02-04 17:49:38 -05:00
Tim Pope 6e0a168a97 Merge pull request #96 from jwhitley/john/cS
Add support for 'cS' per issue 48
2015-02-03 12:39:09 -06:00
John Whitley 5211890344 Update documentation for 'cS' 2015-02-03 10:14:41 -08:00
John Whitley 86f6aca956 Add support for 'cS' per issue 48
This adds support for a cS command that puts the contents of the wrapped
region on their own line, analogous to yS.  This change includes repeat
support.
2015-02-03 10:14:41 -08:00
Tim Pope fa433e0b73 Work around 'nomagic'
Documentation explicitly advises against setting this option, but this
particular problem is easy enough to work around.

Closes #90.
2014-07-26 12:42:47 -04:00
Tim Pope f85cb4e788 Merge pull request #125 from tommcdo/master
Add repeat.vim support to surround with function
2014-06-05 19:24:23 -04:00
Tom McDonald 4e73eeb01d Add repeat.vim support to surround with function
Closes #106.
2014-04-11 15:55:50 -04:00
Tim Pope 42e9b46e7a Fix quote support 2013-09-23 14:05:37 -04:00
Tim Pope 9bf527af3a Merge pull request #107 from DanielleSucher/support-arbitrary-delimiters
Handle arbitrary delimiters with cs and ds
2013-09-09 15:37:09 -07:00
Danielle Sucher 7def4c0772 Handle any punctuation delimiters with cs and ds 2013-09-06 11:31:14 -07:00
Takatoshi Matsumoto 02199ea008 Support to disable mappings only for insert mode
If disable mappings only in normal mode.
let g:surround_no_insert_mappings = 1
2013-01-23 12:26:25 +09:00
Tim Pope 2cc734fd99 Default to automatic indenting
Only one way to find out if this is actually a good idea.
2013-01-18 18:39:59 -05:00
2 changed files with 35 additions and 18 deletions
+3 -2
View File
@@ -39,8 +39,9 @@ easiest to understand with some examples:
<div>Yo!*</div> dst Yo! <div>Yo!*</div> dst Yo!
Change surroundings is *cs* . It takes two arguments, a target like with Change surroundings is *cs* . It takes two arguments, a target like with
|ds|, and a replacement. Details about the second argument can be found |ds|, and a replacement. *cS* changes surroundings, placing the surrounded
below in |surround-replacements|. Once again, examples are in order. text on its own line(s) like |yS|. Details about the second argument can be
found below in |surround-replacements|. Once again, examples are in order.
Old text Command New text ~ Old text Command New text ~
"Hello *world!" cs"' 'Hello world!' "Hello *world!" cs"' 'Hello world!'
+32 -16
View File
@@ -1,6 +1,6 @@
" surround.vim - Surroundings " surround.vim - Surroundings
" Author: Tim Pope <http://tpo.pe/> " Author: Tim Pope <http://tpo.pe/>
" Version: 2.0 " Version: 2.1
" GetLatestVimScripts: 1697 1 :AutoInstall: surround.vim " GetLatestVimScripts: 1697 1 :AutoInstall: surround.vim
if exists("g:loaded_surround") || &cp || v:version < 700 if exists("g:loaded_surround") || &cp || v:version < 700
@@ -127,7 +127,7 @@ endfunction
function! s:wrap(string,char,type,...) function! s:wrap(string,char,type,...)
let keeper = a:string let keeper = a:string
let newchar = a:char let newchar = a:char
let s:tag = "" 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 special = a:0 ? a:1 : 0
@@ -185,10 +185,10 @@ function! s:wrap(string,char,type,...)
if dounmapb if dounmapb
silent! cunmap > silent! cunmap >
endif endif
let s:tag = tag let s:input = tag
if tag != "" if tag != ""
let tag = substitute(tag,'>*$','','') let tag = substitute(tag,'>*$','','')
let s:tag = tag . '>' let s:input = tag . '>'
let before = '<'.tag.'>' let before = '<'.tag.'>'
if tag =~ '/$' if tag =~ '/$'
let after = '' let after = ''
@@ -217,6 +217,7 @@ function! s:wrap(string,char,type,...)
elseif newchar ==# 'f' || newchar ==# 'F' elseif newchar ==# 'f' || newchar ==# 'F'
let fnc = input('function: ') let fnc = input('function: ')
if fnc != "" if fnc != ""
let s:input = fnc."\<CR>"
let before = substitute(fnc,'($','','').'(' let before = substitute(fnc,'($','','').'('
let after = ')' let after = ')'
if newchar ==# 'F' if newchar ==# 'F'
@@ -226,6 +227,7 @@ function! s:wrap(string,char,type,...)
endif endif
elseif newchar ==# "\<C-F>" elseif newchar ==# "\<C-F>"
let fnc = input('function: ') let fnc = input('function: ')
let s:input = fnc."\<CR>"
let before = '('.fnc.' ' let before = '('.fnc.' '
let after = ')' let after = ')'
elseif idx >= 0 elseif idx >= 0
@@ -340,7 +342,7 @@ function! s:insert(...) " {{{1
endfunction " }}}1 endfunction " }}}1
function! s:reindent() " {{{1 function! s:reindent() " {{{1
if exists("b:surround_indent") ? b:surround_indent : (exists("g:surround_indent") && 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
@@ -379,6 +381,12 @@ 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:]]' && char !~# '[][(){}<>"''`]'
exe 'norm! T'.char
if getline('.')[col('.')-1] == char
exe 'norm! l'
endif
exe 'norm! dt'.char
else else
exe 'norm! d'.strcount.'i'.char exe 'norm! d'.strcount.'i'.char
endif endif
@@ -403,9 +411,12 @@ 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:]]' && char !~# '[][(){}<>]'
exe 'norm! F'.char
exe 'norm! df'.char
else else
" One character backwards " One character backwards
call search('.','bW') call search('\m.', 'bW')
exe "norm! da".char exe "norm! da".char
endif endif
let removed = getreg('"') let removed = getreg('"')
@@ -430,7 +441,8 @@ function! s:dosurround(...) " {{{1
endif endif
call setreg('"',keeper,regtype) call setreg('"',keeper,regtype)
if newchar != "" if newchar != ""
call s:wrapreg('"',newchar) let special = a:0 > 2 ? a:3 : 0
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'
@@ -445,11 +457,11 @@ function! s:dosurround(...) " {{{1
if newchar == "" if newchar == ""
silent! call repeat#set("\<Plug>Dsurround".char,scount) silent! call repeat#set("\<Plug>Dsurround".char,scount)
else else
silent! call repeat#set("\<Plug>Csurround".char.newchar.s:tag,scount) silent! call repeat#set("\<Plug>C".(a:0 > 2 && a:3 ? "S" : "s")."urround".char.newchar.s:input,scount)
endif endif
endfunction " }}}1 endfunction " }}}1
function! s:changesurround() " {{{1 function! s:changesurround(...) " {{{1
let a = s:inputtarget() let a = s:inputtarget()
if a == "" if a == ""
return s:beep() return s:beep()
@@ -458,7 +470,7 @@ function! s:changesurround() " {{{1
if b == "" if b == ""
return s:beep() return s:beep()
endif endif
call s:dosurround(a,b) call s:dosurround(a,b,a:0 && a:1)
endfunction " }}}1 endfunction " }}}1
function! s:opfunc(type,...) " {{{1 function! s:opfunc(type,...) " {{{1
@@ -518,9 +530,9 @@ function! s:opfunc(type,...) " {{{1
let &selection = sel_save let &selection = sel_save
let &clipboard = cb_save let &clipboard = cb_save
if a:type =~ '^\d\+$' if a:type =~ '^\d\+$'
silent! call repeat#set("\<Plug>Y".(a:0 && a:1 ? "S" : "s")."surround".char.s:tag,a:type) silent! call repeat#set("\<Plug>Y".(a:0 && a:1 ? "S" : "s")."surround".char.s:input,a:type)
else else
silent! call repeat#set("\<Plug>SurroundRepeat".char.s:tag) silent! call repeat#set("\<Plug>SurroundRepeat".char.s:input)
endif endif
endfunction endfunction
@@ -547,6 +559,7 @@ endfunction " }}}1
nnoremap <silent> <Plug>SurroundRepeat . nnoremap <silent> <Plug>SurroundRepeat .
nnoremap <silent> <Plug>Dsurround :<C-U>call <SID>dosurround(<SID>inputtarget())<CR> nnoremap <silent> <Plug>Dsurround :<C-U>call <SID>dosurround(<SID>inputtarget())<CR>
nnoremap <silent> <Plug>Csurround :<C-U>call <SID>changesurround()<CR> nnoremap <silent> <Plug>Csurround :<C-U>call <SID>changesurround()<CR>
nnoremap <silent> <Plug>CSurround :<C-U>call <SID>changesurround(1)<CR>
nnoremap <silent> <Plug>Yssurround :<C-U>call <SID>opfunc(v:count1)<CR> nnoremap <silent> <Plug>Yssurround :<C-U>call <SID>opfunc(v:count1)<CR>
nnoremap <silent> <Plug>YSsurround :<C-U>call <SID>opfunc2(v:count1)<CR> nnoremap <silent> <Plug>YSsurround :<C-U>call <SID>opfunc2(v:count1)<CR>
" <C-U> discards the numerical argument but there's not much we can do with it " <C-U> discards the numerical argument but there's not much we can do with it
@@ -560,6 +573,7 @@ inoremap <silent> <Plug>ISurround <C-R>=<SID>insert(1)<CR>
if !exists("g:surround_no_mappings") || ! g:surround_no_mappings if !exists("g:surround_no_mappings") || ! g:surround_no_mappings
nmap ds <Plug>Dsurround nmap ds <Plug>Dsurround
nmap cs <Plug>Csurround nmap cs <Plug>Csurround
nmap cS <Plug>CSurround
nmap ys <Plug>Ysurround nmap ys <Plug>Ysurround
nmap yS <Plug>YSurround nmap yS <Plug>YSurround
nmap yss <Plug>Yssurround nmap yss <Plug>Yssurround
@@ -567,11 +581,13 @@ if !exists("g:surround_no_mappings") || ! g:surround_no_mappings
nmap ySS <Plug>YSsurround nmap ySS <Plug>YSsurround
xmap S <Plug>VSurround xmap S <Plug>VSurround
xmap gS <Plug>VgSurround xmap gS <Plug>VgSurround
if !hasmapto("<Plug>Isurround","i") && "" == mapcheck("<C-S>","i") if !exists("g:surround_no_insert_mappings") || ! g:surround_no_insert_mappings
imap <C-S> <Plug>Isurround if !hasmapto("<Plug>Isurround","i") && "" == mapcheck("<C-S>","i")
imap <C-S> <Plug>Isurround
endif
imap <C-G>s <Plug>Isurround
imap <C-G>S <Plug>ISurround
endif endif
imap <C-G>s <Plug>Isurround
imap <C-G>S <Plug>ISurround
endif endif
" vim:set ft=vim sw=2 sts=2 et: " vim:set ft=vim sw=2 sts=2 et: