targets.vim icon indicating copy to clipboard operation
targets.vim copied to clipboard

Typographic quotes

Open stellarhoof opened this issue 8 years ago • 6 comments

It seems the plugin cannot handle typographic quotes (or other digraphs for that matter). Is that intended? I tried

let g:targets_pairs = '() {} [] <> “”'

to no avail

stellarhoof avatar Jan 26 '17 22:01 stellarhoof

The problem is that the pair text objects currently rely on the built in % operator to find the matching delimiter. Because that one doesn't work on the typographic quotes, this is currently not supported. To make it work I'd need to implement that finding the matching delimiter myself.

I'll leave this issue open to possibly consider this at some point, but please don't expect that to work anytime soon. Thanks for bringing this up 👍

wellle avatar Jan 29 '17 11:01 wellle

I ran into this when trying to define double-angle quotation marks (« and ») as a pair text object, with

autocmd User targets#mappings#user call targets#mappings#extend({
    \ "g": {"pair": [{"o":"«", "c":"»"}]},
    \ })

Reading the comment above about vim's % being used to match pairs, I thought I could hack it by adding «:» to 'matchpairs'. This makes jumping back-and-forth between « and » with % work, but alas this wasn't enough to make targets.vim pick them up as a text object :smiley: (similar story when adding the pattern to matchit's b:match_words)

In the mean time, I have defined custom text objects for them, which is good enough for the "classic" use cases of "in quotes" and "around quotes". But what I was really after was to add this pair to the default q quote trigger, so that I could use q for every kind of quotes! (and other target.vim's features like seeking would have been nice too!)

rafikdraoui avatar Dec 12 '19 03:12 rafikdraoui

That's very interesting, thanks for sharing! This will be helpful when I look into this again 👍

wellle avatar Dec 12 '19 10:12 wellle

I would also love this functionality. I’ve added and to matchpairs in my configuration so that % works with typographic quotes, but like @rafikdraoui that didn’t get it to work with targets#mappings#extend.

Mango0x45 avatar Nov 03 '23 17:11 Mango0x45

set matchpairs+=«:»
call targets#mappings#extend({ "g": {"pair": [{"o":"«", "c":"»"}]} })

@wellle Do you have any idea why this would fail even when matchpairs is set?

I'm seeing this error message: fail #o: modifyTarget invalid: multigen

frangio avatar Dec 13 '23 20:12 frangio

After some debugging I found that this line attempts to run normal v1a»v, and this does not work with the » character (presumably it doesn't work with other Unicode characters either).

https://github.com/wellle/targets.vim/blob/642d3a4ce306264b05ea3219920b13ea80931767/autoload/targets/sources/pair.vim#L60

I'm not sure why the plugin isn't using targets#util#select for pairs?

frangio avatar Dec 13 '23 20:12 frangio