vim-surround
vim-surround copied to clipboard
Surrounding multiple times
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?
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.
@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.
Currently, I map it like this: https://github.com/off99555/vimrc/commit/ed9b0428d898a20587629652d35e7e9f61d0761f
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.
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.
@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 https://github.com/tpope/vim-surround/issues/202 and https://github.com/tpope/vim-surround/issues/15
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.
@boardfish you might consider using .
(dot) to repeat the command until we have numbers ;-)
^ 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)
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.
@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\"\"\""
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.
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.
Something along these lines would be very useful for using writing **bold text**
in markdown.
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.