2

I use matchit.vim and it works. Indeed I write a Fortran code and I can jump from IF to END IF pressing %. I'm trying to add the couple <+, > to b:match_words, adding

let b:match_words = b:match_words . '<+:>'

to my ~/.vimrc file, but I get errors E121 and E15 bout undefined variable b:match_words and invalid expression b:match_words . '<+:>', respectively.

If i change to

let b:match_words = '<+:>'

The error disappear, but obviously I cannot match anything else that this only pair.

  • Have you tried let b:match_words += '<+:>'? I think the let is necessary to declare a variable modification. – statox Jul 18 '16 at 8:23
  • 1
    see also: stackoverflow.com/a/27549685/4082052 – Sundeep Jul 18 '16 at 8:28
  • Oh, I'm sorry, I forgot the let in the question but used it in the code; now I edit the question. – Enrico Maria De Angelis Jul 18 '16 at 8:45
  • 7
    Guys, string concatenation is ., not +. – Sato Katsura Jul 18 '16 at 8:51
  • 3
    Then try adding it to after/ftplugin/fortran.vim. – Sato Katsura Jul 18 '16 at 9:27
4

You want to extend matchit's default b:match_words, so you'll have to to wait for it to be initialised first. The docs make reference to setting it from ftplugins, so the solution is to add

let b:match_words .= ',<+:>'

to a file after/ftplugin/fortran.vim. That's about all there is to it.

On a side note: beware that <+ and > above are actually regexps. This is important if you want to add more pairs to b:match_words.

| improve this answer | |
  • Do you mean that the pair I added should always be the last one? – Enrico Maria De Angelis Jul 18 '16 at 10:45
  • @EnricoMariaDeAngelis I'm not sure I understand your point. The pair you're adding is the last, yes. How / why does that matter? – Sato Katsura Jul 18 '16 at 11:08
  • If I were going to add a pair, I would simply do let b:match_words .= ',<+:>,hello:goodby'. What's the problem with this new pair? (I supposed it is the order..) – Enrico Maria De Angelis Jul 18 '16 at 12:19
  • @EnricoMariaDeAngelis There is nothing wrong with adding a new pair. What problem are you trying to solve? – Sato Katsura Jul 18 '16 at 13:41
  • 2
    matchit treats them as regexps. If you want f.i. [:] you should write that as \[:\]. If you want item*:enditem* you need to write it as item\*:enditem\*. And so on. – Sato Katsura Jul 18 '16 at 14:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.