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

Question: How does `vim-surround` plays with `vim-textobj-user` related plugins?

Open doronbehar opened this issue 7 years ago • 5 comments

Hello @tpope,

Continuing from the discussion in https://github.com/lervag/vimtex/issues/1096, I kept thinking about the subject and I was wondering whether you know or use any plugins which depend on vim-textobj-user? What these plugins provide are just various text objects for various usages, a full list is in it's WiKi, a latex specific one is there as well: vim-textobj-latex.

Basically my question is this: Does vim-surround (perhaps with changes that need to be made to the other plugins as well) could be implemented / extended in a way that will be integrated with those other plugins?

I understand that vim-textobj-* plugins offer only / usually {c,s,d,y}{i,a}<text-object> commands and vim-surround's most notable feature is offering {y,c}*s*<text-object> for creating or changing the surroundings around a selected text-object but imagine a world where people could install the text objects they handle often with vim-textobj-user and vim-surround will take care of creating the corresponding mappings that create surroundings according to the text-objects themselves.

Do you think this should be part of vim-surround or perhaps part of vim-textobj-user?

doronbehar avatar Apr 04 '18 21:04 doronbehar

Never tried it, I don't know of any reason that vim-textobj-user would need special casing. You should be able to use ys with custom text objects just fine, and cs should work if there's a pair of i and a text objects.

tpope avatar Apr 04 '18 22:04 tpope

Well I understand that vim-surround's mappings can surround any text-object with vim-surround's already known basic surroundings like *, { ( etc. but, my question is:

Would it be possible that for every text-object defined with vim-textobj-user, vim-surround will create a corresponding {y,c,d}s<text-object><text-object-target> mapping for that relevant text-object, allow me to use an example for demonstrating: vim-textobj-latex provides the text object for Latex quotes:

``word''

This text-object is mapped by default to the letter Q by vim-textobj-latex. What if vim-surround will detect this text-object and automatically create a mapping for {y,c,d}s<text-object>Q that will create/change/delete this surrounding?

Do you think it is even possible with the way vim-surround and vim-textobj-user are currently implemented?

doronbehar avatar Apr 04 '18 22:04 doronbehar

I don't have much experience with vim-textobj-user, but it looks like it's defined in terms of regexps, which means we can't just treat it as a literal for insertion. The php example in the README, for instance, is defined as starting with <?php\>, but intuitively, surround should insert <?php .

tpope avatar Apr 04 '18 22:04 tpope

Hmm than I guess it should be possible to but perhaps this should be part of totally different project.. I'll contact @kana as well about the subject, it seems they've had a discussion about the subject as well in https://github.com/kana/vim-textobj-user/issues/59 .

doronbehar avatar Apr 05 '18 15:04 doronbehar

I made a slight modification that expands operator-pending mode maps during deletion, so it should now automatically work for custom i<char>, a<char> textobject mappings. https://github.com/Vftdan/vim-surround/commit/f0183c333abd5eb7d9aa41640c8b4c63eaa6fd83

However https://github.com/rbonvall/vim-textobj-latex seems to treat linebreaks as parts of environment delimeters, so the behavior may be somewhat broken.

Vftdan avatar Mar 17 '23 14:03 Vftdan