Skip to content
This repository
Browse code

Begin phasing out vs and introduce vgS

  • Loading branch information...
commit a48b3be6cbeb3e2218af3abb24f78d4052e33941 1 parent e842a01
Tim Pope authored

Showing 2 changed files with 28 additions and 20 deletions. Show diff stats Hide diff stats

  1. +18 14 doc/surround.txt
  2. +10 6 plugin/surround.vim
32 doc/surround.txt
@@ -66,22 +66,26 @@ There is also *yS* and *ySS* which indent the surrounded text and place it
66 66 on a line of its own.
67 67
68 68 In visual mode, a simple "s" with an argument wraps the selection. This is
69   -referred to as the *vs* mapping, although ordinarily there will be
  69 +referred to as the *vS* mapping, although ordinarily there will be
70 70 additional keystrokes between the v and s. In linewise visual mode, the
71   -surroundings are placed on separate lines. In blockwise visual mode, each
72   -line is surrounded.
73   -
74   -An "S" in visual mode (*vS*) behaves similarly but always places the
75   -surroundings on separate lines. Additionally, the surrounded text is
76   -indented. In blockwise visual mode, using "S" instead of "s" instead skips
77   -trailing whitespace.
78   -
79   -Note that "s" and "S" already have valid meaning in visual mode, but it is
80   -identical to "c". If you have muscle memory for "s" and would like to use a
81   -different key, add your own mapping and the existing one will be disabled.
  71 +surroundings are placed on separate lines and indented. In blockwise visual
  72 +mode, each line is surrounded.
  73 +
  74 +A "gS" in visual mode, known as *vgS* , behaves similarly. In linewise visual
  75 +mode, the automatic indenting is surpressed. In blockwise visual mode, this
  76 +enables surrounding past the end of the like with 'virtualedit' set (there
  77 +seems to be no way in Vim Script to differentiate between a jagged end of line
  78 +selection and a virtual block selected past the end of the line, so two maps
  79 +were needed).
  80 +
  81 +Additionally, there is a legacy "s" or *vs* mapping which is basically the
  82 +same as |vS|. Due to popular demand of wanting to use "s" as Vim does to mean
  83 +replacing the selection (also available as "c"), this mapping is going away.
  84 +If you were one of these people and would like to disable "s" with the current
  85 +release, indicate this to surround.vim by assigning the "s" mapping to
  86 +something else.
82 87 >
83   - vmap <Leader>s <Plug>Vsurround
84   - vmap <Leader>S <Plug>VSurround
  88 + xmap <Leader>s <Plug>Vsurround
85 89 <
86 90 *i_CTRL-G_s* *i_CTRL-G_S*
87 91 Finally, there is an experimental insert mode mapping on <C-G>s and <C-S>.
16 plugin/surround.vim
@@ -302,7 +302,7 @@ function! s:wrap(string,char,type,...)
302 302 " Really we should be iterating over the buffer
303 303 let repl = substitute(before,'[\\~]','\\&','g').'\1'.substitute(after,'[\\~]','\\&','g')
304 304 let repl = substitute(repl,'\n',' ','g')
305   - let keeper = substitute(keeper."\n",'\(.\{-\}\)\('.(special ? '\s\{-\}' : '').'\n\)',repl.'\n','g')
  305 + let keeper = substitute(keeper."\n",'\(.\{-\}\)\(\n\)',repl.'\n','g')
306 306 let keeper = substitute(keeper,'\n\%$','','')
307 307 else
308 308 let keeper = before.extraspace.keeper.extraspace.after
@@ -512,7 +512,9 @@ function! s:opfunc(type,...) " {{{1
512 512 let type = 'V'
513 513 elseif a:type ==# "v" || a:type ==# "V" || a:type ==# "\<C-V>"
514 514 let ve = &virtualedit
515   - set virtualedit=
  515 + if !(a:0 && a:1)
  516 + set virtualedit=
  517 + endif
516 518 silent exe 'norm! gv"'.reg.'y'
517 519 let &virtualedit = ve
518 520 elseif a:type =~ '^\d\+$'
@@ -533,7 +535,7 @@ function! s:opfunc(type,...) " {{{1
533 535 let keeper = substitute(keeper,'\_s\@<!\s*$','','')
534 536 endif
535 537 call setreg(reg,keeper,type)
536   - call s:wrapreg(reg,char,a:0)
  538 + call s:wrapreg(reg,char,a:0 && a:1)
537 539 if type ==# "v" && a:type !=# "v" && append != ""
538 540 call setreg(reg,append,"ac")
539 541 endif
@@ -545,7 +547,7 @@ function! s:opfunc(type,...) " {{{1
545 547 let &selection = sel_save
546 548 let &clipboard = cb_save
547 549 if a:type =~ '^\d\+$'
548   - silent! call repeat#set("\<Plug>Y".(a:0 ? "S" : "s")."surround".char,a:type)
  550 + silent! call repeat#set("\<Plug>Y".(a:0 && a:1 ? "S" : "s")."surround".char,a:type)
549 551 endif
550 552 endfunction
551 553
@@ -577,7 +579,8 @@ nnoremap <silent> <Plug>YSsurround :<C-U>call <SID>opfunc2(v:count1)<CR>
577 579 nnoremap <silent> <Plug>Ysurround :<C-U>set opfunc=<SID>opfunc<CR>g@
578 580 nnoremap <silent> <Plug>YSurround :<C-U>set opfunc=<SID>opfunc2<CR>g@
579 581 vnoremap <silent> <Plug>Vsurround :<C-U>call <SID>opfunc(visualmode())<CR>
580   -vnoremap <silent> <Plug>VSurround :<C-U>call <SID>opfunc2(visualmode())<CR>
  582 +vnoremap <silent> <Plug>VSurround :<C-U>call <SID>opfunc(visualmode(),visualmode() ==# 'V' ? 1 : 0)<CR>
  583 +vnoremap <silent> <Plug>VgSurround :<C-U>call <SID>opfunc(visualmode(),visualmode() ==# 'V' ? 0 : 1)<CR>
581 584 inoremap <silent> <Plug>Isurround <C-R>=<SID>insert()<CR>
582 585 inoremap <silent> <Plug>ISurround <C-R>=<SID>insert(1)<CR>
583 586
@@ -589,7 +592,7 @@ if !exists("g:surround_no_mappings") || ! g:surround_no_mappings
589 592 nmap yss <Plug>Yssurround
590 593 nmap ySs <Plug>YSsurround
591 594 nmap ySS <Plug>YSsurround
592   - if !hasmapto("<Plug>Vsurround","v")
  595 + if !hasmapto("<Plug>Vsurround","v") && !hasmapto("<Plug>VSurround","v")
593 596 if exists(":xmap")
594 597 xmap s <Plug>Vsurround
595 598 else
@@ -603,6 +606,7 @@ if !exists("g:surround_no_mappings") || ! g:surround_no_mappings
603 606 vmap S <Plug>VSurround
604 607 endif
605 608 endif
  609 + vmap gS <Plug>VgSurround
606 610 if !hasmapto("<Plug>Isurround","i") && "" == mapcheck("<C-S>","i")
607 611 imap <C-S> <Plug>Isurround
608 612 endif

0 comments on commit a48b3be

Please sign in to comment.
Something went wrong with that request. Please try again.