diff --git a/doc/surround.txt b/doc/surround.txt index bcde797..4387fa2 100644 --- a/doc/surround.txt +++ b/doc/surround.txt @@ -66,22 +66,26 @@ There is also *yS* and *ySS* which indent the surrounded text and place it on a line of its own. In visual mode, a simple "s" with an argument wraps the selection. This is -referred to as the *vs* mapping, although ordinarily there will be +referred to as the *vS* mapping, although ordinarily there will be additional keystrokes between the v and s. In linewise visual mode, the -surroundings are placed on separate lines. In blockwise visual mode, each -line is surrounded. - -An "S" in visual mode (*vS*) behaves similarly but always places the -surroundings on separate lines. Additionally, the surrounded text is -indented. In blockwise visual mode, using "S" instead of "s" instead skips -trailing whitespace. - -Note that "s" and "S" already have valid meaning in visual mode, but it is -identical to "c". If you have muscle memory for "s" and would like to use a -different key, add your own mapping and the existing one will be disabled. +surroundings are placed on separate lines and indented. In blockwise visual +mode, each line is surrounded. + +A "gS" in visual mode, known as *vgS* , behaves similarly. In linewise visual +mode, the automatic indenting is surpressed. In blockwise visual mode, this +enables surrounding past the end of the like with 'virtualedit' set (there +seems to be no way in Vim Script to differentiate between a jagged end of line +selection and a virtual block selected past the end of the line, so two maps +were needed). + +Additionally, there is a legacy "s" or *vs* mapping which is basically the +same as |vS|. Due to popular demand of wanting to use "s" as Vim does to mean +replacing the selection (also available as "c"), this mapping is going away. +If you were one of these people and would like to disable "s" with the current +release, indicate this to surround.vim by assigning the "s" mapping to +something else. > - vmap s Vsurround - vmap S VSurround + xmap s Vsurround < *i_CTRL-G_s* *i_CTRL-G_S* Finally, there is an experimental insert mode mapping on s and . diff --git a/plugin/surround.vim b/plugin/surround.vim index 627855f..3c9b768 100644 --- a/plugin/surround.vim +++ b/plugin/surround.vim @@ -302,7 +302,7 @@ function! s:wrap(string,char,type,...) " Really we should be iterating over the buffer let repl = substitute(before,'[\\~]','\\&','g').'\1'.substitute(after,'[\\~]','\\&','g') let repl = substitute(repl,'\n',' ','g') - let keeper = substitute(keeper."\n",'\(.\{-\}\)\('.(special ? '\s\{-\}' : '').'\n\)',repl.'\n','g') + let keeper = substitute(keeper."\n",'\(.\{-\}\)\(\n\)',repl.'\n','g') let keeper = substitute(keeper,'\n\%$','','') else let keeper = before.extraspace.keeper.extraspace.after @@ -512,7 +512,9 @@ function! s:opfunc(type,...) " {{{1 let type = 'V' elseif a:type ==# "v" || a:type ==# "V" || a:type ==# "\" let ve = &virtualedit - set virtualedit= + if !(a:0 && a:1) + set virtualedit= + endif silent exe 'norm! gv"'.reg.'y' let &virtualedit = ve elseif a:type =~ '^\d\+$' @@ -533,7 +535,7 @@ function! s:opfunc(type,...) " {{{1 let keeper = substitute(keeper,'\_s\@Y".(a:0 ? "S" : "s")."surround".char,a:type) + silent! call repeat#set("\Y".(a:0 && a:1 ? "S" : "s")."surround".char,a:type) endif endfunction @@ -577,7 +579,8 @@ nnoremap YSsurround :call opfunc2(v:count1) nnoremap Ysurround :set opfunc=opfuncg@ nnoremap YSurround :set opfunc=opfunc2g@ vnoremap Vsurround :call opfunc(visualmode()) -vnoremap VSurround :call opfunc2(visualmode()) +vnoremap VSurround :call opfunc(visualmode(),visualmode() ==# 'V' ? 1 : 0) +vnoremap VgSurround :call opfunc(visualmode(),visualmode() ==# 'V' ? 0 : 1) inoremap Isurround =insert() inoremap ISurround =insert(1) @@ -589,7 +592,7 @@ if !exists("g:surround_no_mappings") || ! g:surround_no_mappings nmap yss Yssurround nmap ySs YSsurround nmap ySS YSsurround - if !hasmapto("Vsurround","v") + if !hasmapto("Vsurround","v") && !hasmapto("VSurround","v") if exists(":xmap") xmap s Vsurround else @@ -603,6 +606,7 @@ if !exists("g:surround_no_mappings") || ! g:surround_no_mappings vmap S VSurround endif endif + vmap gS VgSurround if !hasmapto("Isurround","i") && "" == mapcheck("","i") imap Isurround endif