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

R double brackets `[[` nested with `[` and `[[`

Open BertrandSim opened this issue 2 years ago • 2 comments

Hello, thank you for this plugin! I installed your plugin recently, and wanted to add my own support for R, and in particular, for [[...]].

In the R language, one has the [[ (extraction) operator, and the [ (subset) operator. As there is no support for the R filetype, I proceeded to add my own ftplugin:

" ~/.vim/after/ftplugin/r/match.vim
let b:match_words .= '\V[[:]]'

As there is already vim's built-in support for [ by default, I only needed to add support for [[.

However, some parts of [[ are confused with a single [. In addition, when the [['s and ['s are nested together, the double and single brackets are not matched properly.
Here's a minimal example:

[abc] # ok
[[abc]] # the second '[' should be part of '[[', instead of a single '['. Similarly for the last ']'.
x[a[b]] # the first ']' does not have a matching '['
x[a[[b]]] # the second ']' does not have a matching '['. 
x[[a[b]]] # first and second '['s wrongly matched with first and second ']'s
x[[a[[b]]]] # first and second '['s wrongly matched with second and third ']'s

I also tried to use the priority of b:match_words, by preferring to match [[ over [. That is,

" ~/.vim/after/ftplugin/r/match.vim
let b:match_words .= '\V[[:]],[:]'
set matchpairs-=[:]

but the result was the same.

BertrandSim avatar Aug 21 '21 16:08 BertrandSim

just checking- are you using classic or tree-sitter (nvim only)?

andymass avatar Aug 21 '21 17:08 andymass

Oh yes, I forgot to mention. I'm using classic vim 8.1 (ie. no tree-sitter)

BertrandSim avatar Aug 21 '21 17:08 BertrandSim