vim-surround icon indicating copy to clipboard operation
vim-surround copied to clipboard

Bug: Adding to a surround has weird spacing

Open ayroblu opened this issue 5 years ago • 5 comments

I was trying to add to a surround and got this:

text = {key: 'a', other: 'b'}
             ^ cursor here

And running ysa'[ produces:

text = {key:[  'a' ], other: 'b'}
            ^ cursor here

And running ysa'] produces:

text = {key:[ 'a'], other: 'b'}
            ^ cursor here

I can kinda see where it's coming from cause a traditionally includes spaces, but in this case the text object is ' not a word so I think it should behave more normally like:

text = {key: [ 'a' ], other: 'b'}
             ^ cursor here
text = {key: ['a'], other: 'b'}
             ^ cursor here

even better if the cursor stays where it is like:

text = {key: [ 'a' ], other: 'b'}
              ^ cursor here
text = {key: ['a'], other: 'b'}
              ^ cursor here

ayroblu avatar Jul 06 '19 19:07 ayroblu

I noticed this as well. Seems to only happen when using the a modifier...

lummish avatar Jul 24 '19 17:07 lummish

You can use 2i modifier instead of a to select a whole word without spaces. Look :h i'. In your case, ys2i'] does what you want. I didn't know this until today 😄 It might be useful if vim-surround converts a", a' and a` to 2i", 2i' and 2i` .

hayatogh avatar Jul 25 '19 05:07 hayatogh

At first glance that sounds reasonable.

tpope avatar Jul 25 '19 15:07 tpope

Odd that this behavior only appears when selecting around quote-like objects (', ", `), and not parentheses, brackets, etc. I wonder why that is?

lummish avatar Jul 26 '19 17:07 lummish

Cool! Thanks so much, I added this to my .vimrc in the mean time:

nmap ysa' ys2i'
nmap ysa" ys2i"
nmap ysa` ys2i`

ayroblu avatar Jul 26 '19 19:07 ayroblu