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

Allow multiple characters surround #15

Open
tonicebrian opened this issue Nov 29, 2010 · 21 comments
Open

Allow multiple characters surround #15

tonicebrian opened this issue Nov 29, 2010 · 21 comments

Comments

@tonicebrian
Copy link

Hi,

I'd like to use your plugin for editing Trac wiki pages. In this language sections have more than one = level, for instance:

= Section1 =

== Section2 ==

=== Section3 ===

would it be possible to specify a number before the character to wrap? For instance if I want to convert a text into Section3 header it will be something like cs<text_selection>3=

Thank you

@tangledhelix
Copy link

This would also be useful for Mediawiki: ''italic'', '''bold'''

And of course Markdown: bold

@tpope
Copy link
Owner

tpope commented Dec 14, 2010

I guess it'd be possible, though I'm not too keen on implementing it. In the past, I've just created one-offs for those, e.g.:

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

@fncll
Copy link

fncll commented Oct 2, 2013

I'm resurrecting this because I have a question about your philosophy on this and a specific question regarding multiple characters. I am wondering why
ysw<em>
works but
ysw**
does not (to surround the word with two * marks)

@tpope
Copy link
Owner

tpope commented Oct 2, 2013

All surroundings are invoked as a single character. < is a special surrounding that prompts for the tag.

@isovector
Copy link

I think the majority of use cases for this would be covered by allowing a prefix for the surround plugin; 2ysw* really should run the surround twice, which would give the desired behavior.

@tommcdo
Copy link
Contributor

tommcdo commented Nov 3, 2015

That seems like a reasonable solution. Today, the count for the operator is unused.

You can still supply a count for the motion (e.g. ys2w*); I'm pretty sure that comes for free when implementing custom operators.

@haakenlid
Copy link

How about using < for this as well? Since XML/HTML tags must start with a letter, and the multi-character tags in markdown and friends usually are non-letter characters, this could make sense.

Currently you can use cs*<**> to turn *bold* into <**>bold</**>

That isn't very useful, since <**> is not a valid xml tag name. Instead this could result in **bold**, which is what you want if you write ReStructured Text.

@isovector
Copy link

That strikes me as being a hack; then you wouldn't be able to do multiple
surrounds of alphanumeric characters.

@haakenlid
Copy link

What do you mean "multiple surrounds of alphanumeric characters"?

@isovector
Copy link

This proposal fails to allow surrounding with the characters "tt", since
that is valid html and would result in "..." rather than
"tt...tt". Furthermore it makes surrounding with "***********" a lot of
work.

On Thu, Nov 26, 2015 at 6:07 PM, Håken Lid notifications@github.com wrote:

What do you mean "multiple surrounds of alphanumeric characters"?


Reply to this email directly or view it on GitHub
#15 (comment).

@derBingle
Copy link

I know it's a bit of a hack, but for anyone else trying to figure this out, you can use gv to solve this problem. For instance, I'm using a custom leader mapping to bold sentences, and it looks like this:

nmap <silent> <leader>sb ysis*gvS*

Gets the job done.

@RubenVerborgh
Copy link

Since the solutions in this thread involved a lot of keypresses, I started the Vim Markup Assistant plugin, which toggles single words in Markdown to italic or bold. Thereby, I lose the flexibility of vim-surround, but I gain simplicity. Examples here.

@feistiny
Copy link

feistiny commented Sep 7, 2018

with vim-repeat, an alternative is:
e.g. now has text 123, and the cursor is at 1
type ysf3" result in "123", now the cursor is at " not 1
again, type ysf3/ result in /"123/", now the cursor is at /
once more, type ysf3? result in ?/"123?/", now the cursor is at ?
so, if " / ? is the same char like a ", the result will be """123""", and just type once ysf3", also the later two can be repeat with ., unfortunately vim-repeat is neither not support for count operation, otherwise repeat may be more easy

@jacktose
Copy link

jacktose commented Oct 23, 2018

Just adding a possible use-case: Jinja2 has this kind of stuff:

  • {{ ... }} (doable with counts or repeats)
  • {% ... %}
  • {# ... #}

and it's common to put a space between those and the contents. So I'd love to do something like this:

  1. test comment please ignore
  2. a vim-surround miracle occurs
  3. {# test comment please ignore #}

@achilleas-k
Copy link

I guess it'd be possible, though I'm not too keen on implementing it. In the past, I've just created one-offs for those, e.g.:

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

I came across this issue while looking for a way to do **bold** in Markdown. The quoted way works fine, but then I thought it might be nice to have a prompt for a generic multi-char surround

let g:surround_{char2nr('m')} = "\1Surround: \1\r\1\1"

This seems to work fine as long as the characters on one side are identical to the ones on the other (so no ((( )))). For that I could also do

let g:surround_{char2nr('M')} = "\1S-Open: \1\r\2S-Close: \2"

but at that point I might as well just do it manually.

My main issue is how to make these, or at least the Markdown bold **\r** one, available in replacement or deletion as well.

@russurquhart1
Copy link

Glad I wasn't the only one wanting this! (This was part of why I liked using Asciidoc vs Markdown.) If this changes, please let me know! Use your plugin all the time!

@ccaprani
Copy link

ccaprani commented Nov 28, 2020

If I'm not mistaken this is addressed in PR #226 from 2017 that has not been merged yet.

@Lamby777
Copy link
Sponsor

For anyone finding this thread later... it's kind of a hack but the best solution I've found is to just press i as the character you want to surround stuff with, and it prompts you for what will be added to each side. (for example, ysiWi for a WORD or VSi for the current line).

@g-i-o-r-g-i-o
Copy link

I'm trying to resurrect this thread... I have these in my vimrc... I'd like to be able to surround words with two or more characters to have "bold" in markdown.

autocmd filetype python nmap <leader>7 <Esc>yiwoprint('�*:', �*)�o�<CR>

" inserisce * per formattazine in grassetto
autocmd filetype wri,markdown nmap <Leader>1 <Esc>ysiw*
autocmd filetype wri,markdown nmap <Leader>2 <Esc>ys2aw*
autocmd filetype wri,markdown nmap <Leader>3 <Esc>ys3aw*

@fancsali
Copy link

fancsali commented Dec 6, 2023

For anyone finding this thread later... it's kind of a hack but the best solution I've found is to just press i as the character you want to surround stuff with, and it prompts you for what will be added to each side. (for example, ysiWi for a WORD or VSi for the current line).

That doesn't seem to work for me... 🤔

@Lamby777
Copy link
Sponsor

Lamby777 commented Dec 6, 2023

For anyone finding this thread later... it's kind of a hack but the best solution I've found is to just press i as the character you want to surround stuff with, and it prompts you for what will be added to each side. (for example, ysiWi for a WORD or VSi for the current line).

That doesn't seem to work for me... 🤔

oh, I'm not sure if I wrote that before or after using surround.nvim... might be for that instead

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