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

Conversation

frankplow
Copy link

This PR adds support for repeating replacement arguments by beginning the argument with a count.

Examples:

  Old text            Command           New text
  hello               ysW2*             **hello**
  hello               ysW2]             [[hello]]

Repeated delimeters are used by markdown a lot as well as some other languages. Many of the posed use cases of #97 involve repeated delimeters and I think this PR is a more intuitive way to support them.

@frankplow frankplow changed the title Add Counts for Replacment Arguments Add Counts for Replacement Arguments Jan 26, 2022
@TeaWhyDee
Copy link

TeaWhyDee commented May 12, 2022

I think #226 (almost the exact same PR) implements a better count detection (not limited by 0-9)?

There is also a bug where if you do a line selection and then a surround with a multiplier you get something like this:

*
	*
    I typed VS2* on this line
**

@@ -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

plugin/surround.vim Show resolved Hide resolved
plugin/surround.vim Show resolved Hide resolved
@frankplow
Copy link
Author

Have to admit I didn’t see that PR.

Limiting to 0-9 was actually intentional. It means you can do, for example, ysiw11 to surround a word with a pair of 1s - I thought it was more likely to want to surround something with a pair of numbers rather than 10+ instances of something. Happy to change it if people disagree though.

@TeaWhyDee
Copy link

Oh, I didn't realize that. I also saw not being able to surround with numbers as a problem. Sounds like a little bit of a hack, but I do prefer your solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants