I have an array like this ["/api/static/1_lion.wav",/api/static/2_lion.wav]
, I want to add quotes around /api/static/2_lion.wav
. I have vim-sandwich, and I have a vague feeling I should be able to do this, or have read somewhere about this, but for the life of me I can't figure it out how to do this easily: neither w
nor W
is the selection I want, and there is no symmetrical character around it to use that to select inside. Any ideas?
1 Answer
Most plug-ins that take text objects usually include a version of their mappings that works in Visual mode. That also includes vim-sandwich. So one option is to use Visual mode to select the region you want to wrap with quotes and then use the sa
mapping on those.
For example, you can use f,lvt]
to visually select the /api/static/2_lion.wav
part that comes after the comma and goes 'til the close bracket, and then use sa"
to surround that in quotes.
If you'd like a solution that involves plug-ins, then consider targets.vim which includes a text object to select an "argument" (as in, function argument) that works perfectly here. The targets.vim text objects also accept a n
modifier to select the "next" argument. So from the beginning of this line, you can use the ina
text object to select the second argument. Putting it all together, saina"
would work with both vim-sandwich and targets.vim installed.
-
1targets.vim was what I was looking for! It also has targets for lists, like
a,
with like basically all of the separators you would use:, . ; : + - = ~ _ * # / | \ & $
(actually, I think a bit more than all :D)– fbenceMay 27, 2020 at 11:59