I followed the link creating-a-simple-vim-syntax-highlighting, for doing the syntax highlighting for my purpose. This is really nice., but it's static. So, keywords are to be predefined.

In a situation, where i see lot of pointers or addresses in my file, which i want to track individually.

example below, whatever follows "msm_vidc: pkt: XXXXXXXX " to be colored differently/individually. In below case, 00211005,00211004,00221007,00211001

[  615.738018] msm_vidc:  pkt: 0000002c 00211005 eac11e40 00000000 00000000 00021000 00000000 00000000
[  615.738078] msm_vidc:  pkt: 0000003c 00211004 eac11e40 00000000 00000000 00000000 00000000 00000000
[  615.753302] msm_vidc:  pkt: 00000028 00221007 eac11e40 0000100b 00000018 00000000 5dc00000 5dc00000
[  616.257331] msm_vidc:  pkt: 0000003c 00211004 eac11e40 00051da6 97658047 00000000 00000000 00000000
[  616.262023] msm_vidc:  pkt: 00000028 00221007 eac11e40 0000100b 00000018 00000000 5dc00000 5dc00000
[  616.336188] msm_vidc:  pkt: 0000003c 00211004 eac11e40 00051da6 97659fd2 00000000 00000000 00000000
[  616.336483] msm_vidc:  pkt: 0000003c 00211004 eac11e40 00051da6 9766a276 00000000 00000000 00000000
[  616.344627] msm_vidc:  pkt: 00000034 00021001 eac11e40 01000003 01000001 00000002 00001001 00000002

So, that, it can be viewed as below. enter image description here

  • You want something on the lines of 'semantic highlighting', if it helps (for searching).
    – VanLaser
    Aug 26 '15 at 16:11

Edit : To share the script more easily, I made a github repo here where you can go and try it for yourself.

Here is how I did it.

  1. Get the matching strings :

The workflow is the following : you do a search and then you call the Reload command. It will build a list of all matched strings with a function and the following substitution command :

%s//\=<SID>AddToList(l:list, submatch(0))/n
  1. Sort and remove duplicates over the list with the functions uniq() and sort()

  2. Build a dictionary that has for keys the matched strings and for values a random color (see the s:GetColor() function for details)

  3. Create a new empty buffer

  4. For each entry in the dictionary :

    1. Create two new syntax and highlight strings

    e.g. for the entry 'foo1' : 'red'

    syntax match foo1 "foo1"
    highlight foo1 ctermbg=red
    1. Add the created lines into the buffer
  5. Move vim to the location of the syntax file (This part is currently not dynamic, you might want to change it).

  6. Override the current syntax file.

  7. Reload the syntax

Note :

  • For this to work (as specified in the ftdetect file) you should use .foo as filetype. (this could be dynamic as well)

Here is a demo :


If you have a question , please leave a comment, I'll be happy to answer it.

  • Thanks for your invaluable efforts. I saw uniq function was not available in my vim 7.4. managed with ingo#compat#uniq. Still I could not. I get error when I did the same thing as per the video you had shared. "E127: Cannot redefine function <SNR>23_ReloadSyntax: It is in use". i think, the script is fine, and now in my case(as per the example content in the question), its in the matter of selecting the keywords. i.e making your function,s:GetMatchingText(), to select only 00211005,00211004,00221007,00211001 Sep 1 '15 at 15:24
  • You can do that with a visual selection :) since all your number are in the same columns you should be able to do it quickly : <C-V>
    – nobe4
    Sep 1 '15 at 15:29
  • Excellent.! Worked fine. Actually the error, "E127: Cannot redefine function", was since, i had kept the .vim/plugin/syntaxreload.vim at .vim/syntax/syntaxreload.vim.Thanks. Sep 2 '15 at 9:02
  • Great it worked :) I recommend using github.com/junegunn/vim-plug with github.com/tpope/vim-scriptease to develop vim plugin, you should give it a try :)
    – nobe4
    Sep 2 '15 at 9:06

Check out Ingo Karkat's Mark plugin. You can highlight patterns by specifying them on the command line or by a couple of keystrokes over the word of interest. It rotates through a pallette of colors, or you can choose the color yourself.

  • this seems a manually enabling method, to achieve different keywords with different color. I could not get the way to get it automatically like syntax highlighting. Aug 27 '15 at 6:38
  • 1
    I don't know what you mean by "automatic". Somehow you have to specify the addresses you wish to highlight. Since the addresses of interest are likely to change from file to file and from time to time, I thought that being able to select them manually would be a feature. Once selected, you can save them with :MarkSave and load them with :MarkLoad. You can even load them automatically by setting g:mwAutoLoadMarks. Alternatively, you could use the matchadd() function (:help matchadd()). It's hard to know what to suggest without knowing more about what you want.
    – garyjohn
    Aug 27 '15 at 6:55

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.