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

Don't block use of user defined text objects

Open alerque opened this issue 9 years ago • 6 comments

I don't know if this is the right solution because there may be ramifications to allowing mappings through here, but this change solves the problem I was having, fixing #199. With these changes and the text objects I have setup such as q for curly double quotes and Q for curly single quotes, I can dow do things like:

  • Change “double̝ quotes” to single with csqQChange ‘double quotes’ to single
  • Change “double̝ quotes” to star with csq*Change *double quotes* to star
  • Change (in̝ parenthesis) to quotes with cs(qChange “in parenthesis” to quotes

These (along with things like dsq to delete surrounding quotes) were ignored before even if the surround mapping AND text object existed.

By contrast the solution presented in #107 only works for arbitrary single characters where the left and right side of the surround use the same character and the 'surround target' character is an exact match for the one being searched for. It doesn't work for more complex surround objects such as mixed matched pairs that have special text objects.

alerque avatar May 07 '16 08:05 alerque

The ramification is that this breaks setups that remap e.g. d (unusual, but not unheard of, particularly among Dvorak users). You can probably achieve your goal by defining global script maps:

nnoremap <SID>d d

I'm not sure off the top of my head how to invoke them from norm; you might need to stitch the script id in yourself (see :h <SID>).

tpope avatar May 08 '16 23:05 tpope

I tried this by using s:SID from the <SID> docs and using the remapping. It works for some things (yss" followed by cs"q, dsq works), but seems to have broken other mappings like ] or }. I wonder if there is a bad interaction with targets.vim?

Here's my attempted fix: https://github.com/Porges/vim-surround/commit/3c49004bc3aa5edb3140b6ab9b1c3b889fdd74b0

Porges avatar Jan 13 '17 04:01 Porges

I’d love to have this feature working. It would be useful not only for “literature” quotes, but also for things like:

/* comment */
begin ... end

Maelan avatar Aug 05 '18 22:08 Maelan

I'm not sure what the status is here. Five years later I'm still using my forked version of this plugin so that it plays nice with vim-textobj-quote. As the newly appointed maintainer of the latter I'd be happy to fix this from that side if it could be done, but I still don't see how, and stabbing in the dark I haven't found any other way of fixing it from this end. If anybody has enough expertise to suggest how this could be resolved from either end I'm all ears.

alerque avatar Apr 17 '21 06:04 alerque

To avoid triggering maps in unwanted places I create a <Plug>-noremap for the sequence, I used this approach in my fork that implements the same functionality: https://github.com/Vftdan/vim-surround/commit/f0183c333abd5eb7d9aa41640c8b4c63eaa6fd83 .

The ramification is that this breaks setups that remap e.g. d (unusual, but not unheard of, particularly among Dvorak users). You can probably achieve your goal by defining global script maps:

nnoremap <SID>d d

I'm not sure off the top of my head how to invoke them from norm; you might need to stitch the script id in yourself (see :h ).

Should a configuration variable be created for cases when someone doesn't want this (omap respecting) behavior?

Vftdan avatar Jul 07 '23 17:07 Vftdan