I have a file with two columns, separated by a tab, and would like to match any part of the second column that begins with an asterisk. For example:

  RAFP         rasp
  ET           *ratchet

then *ratchet should be highlighted. (There are two spaces before the first column, and there are supposed to be – in some other rows, there are symbols placed in that space.)

Therefore, I wrote the following match line:

syntax match Keyword "\t\*.*"

It does not highlight anything. I have tried removing and adding escape characters, putting elements in square brackets, playing with the magic option (though I see in the help that syntax matches are always in magic mode no matter what) and just about everything else possible. If I take out the \t, then it works as expected, but this has the potential for false positives, so it's important that the pattern start with the tab.

Most baffling, if I do a simple search for \t\*.* with hlsearch on, it highlights exactly like it's supposed to. What is different about the pattern matching in a syntax highlight command from the normal search matching system?

I'm using Vim 7.4 (I can give more version output if it's relevant).

  • 3
    Did you try inserting a literal tab character in the regexp? With <C-v><Tab>? Jul 30 '15 at 22:27
  • Your syntax command line works for me, highlighting everything from the tab to the end of the line. I'm on Vim 7.4 too. Jul 31 '15 at 9:29
  • That's interesting... I did try <C-v><Tab>, yes, sorry for missing that. It inserts a ^I character, and it doesn't work either. Jul 31 '15 at 15:38
  • You example syntax command seems to work, as it is in the answer. The word *ratchet gets highlighted as a keyword (brown-isn in my case), and the tab just before it is also highlighted (which is only visible when you move the cursor over it). How did you try to apply the :syntax rule? Aug 7 '15 at 13:13