From 6c676da884de7491412ea5a577cdce115c470140 Mon Sep 17 00:00:00 2001 From: Frank Plowman Date: Mon, 24 Jan 2022 18:08:11 +0000 Subject: [PATCH 1/3] initial implementation --- plugin/surround.vim | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/plugin/surround.vim b/plugin/surround.vim index 527dc3c..7786b18 100644 --- a/plugin/surround.vim +++ b/plugin/surround.vim @@ -35,7 +35,7 @@ endfunction function! s:inputreplacement() let c = s:getchar() - if c == " " + if c =~ "[ 0-9]" let c .= s:getchar() endif if c =~ "\" || c =~ "\" @@ -164,6 +164,11 @@ function! s:wrap(string,char,type,removed,special) elseif newchar ==# ':' let before = ':' let after = '' + elseif newchar =~ '^[0-9].' + let scount = strpart(newchar,0,1) + let newchar = strpart(newchar,1) + let before = repeat(newchar, scount) + let after = repeat(newchar, scount) elseif newchar =~# "[tT\<]" let dounmapp = 0 let dounmapb = 0 From d3562b0bc13d596c8d361d9f552b786ee4aafb9b Mon Sep 17 00:00:00 2001 From: Frank Plowman Date: Wed, 26 Jan 2022 12:25:34 +0000 Subject: [PATCH 2/3] support repeating replacement special cases --- plugin/surround.vim | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/plugin/surround.vim b/plugin/surround.vim index 7786b18..171793d 100644 --- a/plugin/surround.vim +++ b/plugin/surround.vim @@ -139,6 +139,11 @@ function! s:wrap(string,char,type,removed,special) endif let pairs = "b()B{}r[]a<>" let extraspace = "" + let scount = 1 + if newchar =~ '^[0-9]' + let scount = strpart(newchar,0,1) + let newchar = strpart(newchar,1) + endif if newchar =~ '^ ' let newchar = strpart(newchar,1) let extraspace = ' ' @@ -164,11 +169,6 @@ function! s:wrap(string,char,type,removed,special) elseif newchar ==# ':' let before = ':' let after = '' - elseif newchar =~ '^[0-9].' - let scount = strpart(newchar,0,1) - let newchar = strpart(newchar,1) - let before = repeat(newchar, scount) - let after = repeat(newchar, scount) elseif newchar =~# "[tT\<]" let dounmapp = 0 let dounmapb = 0 @@ -256,6 +256,8 @@ function! s:wrap(string,char,type,removed,special) let before = '' let after = '' endif + let before = repeat(before, scount) + let after = repeat(after, scount) let after = substitute(after ,'\n','\n'.initspaces,'g') if type ==# 'V' || (a:special && type ==# "v") let before = substitute(before,' \+$','','') From 86670e63d4bcf75138f719bfa6cde1074c2ffa9a Mon Sep 17 00:00:00 2001 From: Frank Plowman Date: Wed, 26 Jan 2022 12:28:12 +0000 Subject: [PATCH 3/3] update documentation --- doc/surround.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/doc/surround.txt b/doc/surround.txt index fd395d2..f6bec4b 100644 --- a/doc/surround.txt +++ b/doc/surround.txt @@ -129,6 +129,12 @@ b, B, r, and a are aliases for ), }, ], and >. To fulfill the common need for code blocks in C-style languages, (which is really ) adds braces on lines separate from the content. +If a number is used, the remaining replacement argument is multiplied by that +count. + + Old text Command New text ~ + hello ysW2* **hello** + If t or < is used, Vim prompts for an HTML/XML tag to insert. You may specify attributes here and they will be stripped from the closing tag. If replacing a tag, its attributes are kept in the new tag. End your input with > to discard