Monday, August 14, 2017

Re: wrapping a series of comma separated words

Am 14.08.2017 um 17:06 schrieb 'Andy Wokula' via vim_use:
> Am 11.08.2017 um 21:08 schrieb Ben Fritz:
>>
>> On Thursday, August 10, 2017 at 10:57:27 AM UTC-5, Chris Lott wrote:
>>> I'm constantly needing to wrap a series of comma separated titles
>>> with html <i> tags, so this:
>>>
>>> John has published work in foo, fubar, boo review, and many more.
>>>
>>> Becomes this
>>>
>>> John has published work in <i>foo</i>, <i>fubar</i>, <i>boo review</i>, and many more.
>>>
>>> Right now I'm visually highlighting each title and using emmet to
>>> wrap with the tags, but it seems like there must be a shorter way!
>>
>> In general I find working with such lists easier with this pull
>> request compiled in:
>>
>> https://github.com/vim/vim/pull/958
>>
>> I think in this specific case it would possibly only help a small
>> amount, as I'd still probably visually select and then use the
>> surround plugin on the visual selection.
>
> I've also added a script for this purpose:
> https://github.com/Houl/charobj-vim
>
> In the example, with surround.vim (and after setting up keys), you type once
> ysim,<i>
> to make the first replacement and then go the next location (eg with mouse click)
> and hit the dot key to repeat.
>
> charobj still needs fine-tuning (ie options), because with
> foo, fubar, boo review
> the result will be
> <i> foo</i>,<i> fubar</i>,<i> boo review</i>
> (would be more useful to skip surrounding whitespace -- but maybe not always).
>
> And it still assumes selection=inclusive.
>
> Otherwise a count works and dot-repetitions works.
>
> And the region is always within a single line, to make extending the region
> to begin/end-of-line work. Maybe this will change too (with option).

There is also a very elaborate plugin (it creates a lot of mappings):
https://github.com/wellle/targets.vim

It does provide mappings for a comma-separated list, and the inner whitespace
trimmed part can be selected with I, :
ysI,<i>

but it requires commas before and after, not sure how to make it extend the region
to begin-(or end)-of-line.

--
Andy

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments: