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

Surrounding multiple times #213

Open
Chinggis6 opened this issue Nov 3, 2016 · 14 comments
Open

Surrounding multiple times #213

Chinggis6 opened this issue Nov 3, 2016 · 14 comments

Comments

@Chinggis6
Copy link

Chinggis6 commented Nov 3, 2016

Thanks, the plugin is great, I use yss often, and like how the difference between pair characters is implemented (in ] and [ for example).
But, what to do when I need to surround the line with double, triple or N amount of characters?
I tried 2yss] and yss2] to surround the line with double brackets ([[line]]) (which is happening frequently when dealing with org mode in emacs or wikimarkup on wikipedia) but it didn't work (obviously). Any solutions?

@jpassaro
Copy link

you could do yss]ysa]], which surrounds the line with brackets then surrounds those brackets with another pair of brackets. You could probably write a function / plugin that takes a count and interprets it this way: yss<char> followed by count-1 applications of ysa<char><char>.

Wonder if such an extension would be useful enough to include in the plugin... Personally I don't need to do this too often.

@offchan42
Copy link

offchan42 commented Nov 28, 2016

@jpassaro I do this a lot!
For example, when in markdown, you want to surround things with ``` to make it into a code block.
In Python, you want to surround things with """ to make it into a block comment.

@offchan42
Copy link

offchan42 commented Nov 29, 2016

Currently, I map it like this: offchan42/vimrc@ed9b042

So S3" would surround things with 3 double quotes. It's not using vim-surround plugin's engine at all. I think it might be possible that vim-surround should allow counts.

@offchan42
Copy link

offchan42 commented Nov 29, 2016

And a lot of times, I want to surround things with arbitrary text like HEY my text HEY.
It should be obvious for the vim-surround maintainer to implement this because it's like surrounding with tag but no <> symbol.
The desired key should be something like ysw T (for text) followed by HEY. Of course, this T key can be chosen, there are literally hundreds of keys we can substitute in.

shanesmith added a commit to shanesmith/vim-surround that referenced this issue Feb 12, 2017
shanesmith added a commit to shanesmith/vim-surround that referenced this issue Feb 12, 2017
shanesmith added a commit to shanesmith/vim-surround that referenced this issue Feb 12, 2017
@jottr
Copy link

jottr commented May 13, 2017

@tpope would it be possible to implement above feature somehow?
Or are there any workarounds to get to the desired behaviour?
This is especially interesting when editing markdown files.
See #202 and #15

@boardfish
Copy link

boardfish commented Oct 16, 2017

Totally up for this. Right now, the required motion is ysiw*l. for a single word. In other cases, things get complex enough that you might need to make a complex text selection twice.

@Chinggis6
Copy link
Author

@boardfish you might consider using . (dot) to repeat the command until we have numbers ;-)

@Chinggis6
Copy link
Author

Chinggis6 commented Oct 16, 2017

^ oh it doesn't work even with vim-repeat. :-(

though ysw (unlike yss) worked partially... that is it prompts for a character input to surround the word with (instead of remembering the previous character)

@rattletat
Copy link

rattletat commented Dec 31, 2017

Totally opt for this feature. Would fit more nicely into vim's language.
3dsb to delete 3 bracket surroundings for example.
PS: vim-repeat is also not working that way. For me dsb 2. does not work.

@rjmccabe3701
Copy link

@off99555 does this help?

"Code block for markdown
 autocmd FileType markdown let b:surround_45 = "```\n\r\n```"

"Block comment for python
 autocmd FileType python let b:surround_45 = "\"\"\"\n\r\n\"\"\""

@trapier
Copy link

trapier commented Oct 3, 2019

Thanks @rjmccabe3701! With that config the one-line case is covered by yss-. I wish ysip didn't remove indentation, but that seems to be default surround behavior.

I edit a lot of Jira markup in vim, so I'm gonna go wild and set this up for {code}, {noformat}, and the like.

@michaelfresco
Copy link

michaelfresco commented Mar 5, 2021

For markdown code blocks, I use this to wrap ``` around my selection:

vmap <Leader>mc S続<esc>:%s/続/```<CR>

Though yss- with let b:surround_45 is much more elegant.

TeaWhyDee added a commit to TeaWhyDee/vim-surround that referenced this issue May 12, 2022
Support surround character multiplier (Fixes tpope#213)
@naught101
Copy link

Something along these lines would be very useful for using writing **bold text** in markdown.

@qadzek
Copy link

qadzek commented May 6, 2024

Something along these lines would be very useful for using writing bold text in markdown.

This should work:

let b:surround_{char2nr('o')} = "**\r**"

Mnemonic: bOld.

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

No branches or pull requests