Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Counts for Replacement Arguments #341

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions doc/surround.txt
Expand Up @@ -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, <C-}> (which is really <C-]>) 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
Expand Down
9 changes: 8 additions & 1 deletion plugin/surround.vim
Expand Up @@ -35,7 +35,7 @@ endfunction

function! s:inputreplacement()
let c = s:getchar()
if c == " "
if c =~ "[ 0-9]"
frankplow marked this conversation as resolved.
Show resolved Hide resolved
let c .= s:getchar()
endif
if c =~ "\<Esc>" || c =~ "\<C-C>"
Expand Down Expand Up @@ -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]'
frankplow marked this conversation as resolved.
Show resolved Hide resolved
let scount = strpart(newchar,0,1)
let newchar = strpart(newchar,1)
endif
if newchar =~ '^ '
let newchar = strpart(newchar,1)
let extraspace = ' '
Expand Down Expand Up @@ -251,6 +256,8 @@ function! s:wrap(string,char,type,removed,special)
let before = ''
let after = ''
endif
let before = repeat(before, scount)
Copy link

@TeaWhyDee TeaWhyDee May 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To fix issue with line select something like this can be used:

  if before =~ '.*\n\t$'
    let before = substitute(before, '\n\t', '', '')
    let before = repeat(before, scount)
    let before = before."\n\t"
  else
    let before = repeat(before, scount)
  endif

let after = repeat(after, scount)
let after = substitute(after ,'\n','\n'.initspaces,'g')
if type ==# 'V' || (a:special && type ==# "v")
let before = substitute(before,' \+$','','')
Expand Down