Loading ...
Sorry, an error occurred while loading the content.
 

Highlight group exists but no highlighting

Expand Messages
  • Samkit Jain
    I am having syntax and highlight group put to the bottom of my ~/.vimrc file. syntax keyword UserKeywords Samkit CHECKME REVIEW CHECKME containedin=ALL
    Message 1 of 4 , May 1, 2011
      I am having syntax and highlight group put to the bottom of my
      ~/.vimrc file.

      syntax keyword UserKeywords Samkit CHECKME REVIEW CHECKME
      containedin=ALL
      highlight def link UserKeywords Todo

      This works fine if I open an unnamed file like just "gvim". But if I
      open a file "gvim 1.c" then the above highlighting does'nt work. To
      get it working again I have to manually source the ~/.vimrc file.
      (tried without containedin too)

      I am suspecting that something is calling "highlight clear" but I am
      not sure of this. Additionally after opening 1.c I checked if my
      syntax group exists and it exists so it can only be the work of
      "highlight clear".

      :hi UserKeywords
      UserKeywords xxx links to Todo

      For this much highlighting I would not like to create a new
      runtimepath/after/syntax/default.vim containing above syntax+highlight
      group commands and then source it for every BufRead and FileRead.

      Also, along with any solution which you may suggest, I would really
      like to know how to debug this.

      --
      You received this message from the "vim_use" maillist.
      Do not top-post! Type your reply below the text you are replying to.
      For more information, visit http://www.vim.org/maillist.php
    • Ben Schmidt
      ... You probably don t want the def in there, but it probably doesn t really matter. ... Syntax is buffer-specific, so as soon as you edit any other file of
      Message 2 of 4 , May 1, 2011
        > syntax keyword UserKeywords Samkit CHECKME REVIEW CHECKME
        > containedin=ALL
        > highlight def link UserKeywords Todo

        You probably don't want the 'def' in there, but it probably doesn't
        really matter.

        > This works fine if I open an unnamed file like just "gvim".

        Syntax is buffer-specific, so as soon as you edit any other file of any
        other type, it will no longer be in effect.

        > I am suspecting that something is calling "highlight clear" but I am
        > not sure of this.

        That won't be happening. You can confirm this, though, by typing

        :verbose highlight

        It will show the highlight group (even with 'cleared' beside it, if it
        has been cleared), and in the line below, the file that last set it (or
        cleared it).

        Likewise

        :verbose syntax

        will let you know where syntax groups originated, though this is often a
        little less useful (cleared groups are not shown, I don't think).

        > Additionally after opening 1.c I checked if my syntax group exists and
        > it exists so it can only be the work of "highlight clear".

        This can't really be possible (that the syntax group exists). Probably
        the highlight group for your syntax item exists, but the actual syntax
        rule will not. I.e. you will see it listed in :highlight but not in
        :syntax.

        > :hi UserKeywords
        > UserKeywords xxx links to Todo

        This is as expected.

        If you do :syn UserKeywords, though, you will not see it.

        > For this much highlighting I would not like to create a new
        > runtimepath/after/syntax/default.vim containing above syntax+highlight
        > group commands and then source it for every BufRead and FileRead.

        You can use an autocommand to just run the syntax you want on those
        events. Put something like this in .vimrc:

        autocmd BufNewFile,BufRead * syntax keyword UserKeywords
        \ Samkit CHECKME REVIEW CHECKME containedin=ALL

        Adjust the * if you want to apply to specific filetypes, and ensure it
        is after the filetype on and/or syntax on commands in your vimrc or the
        autocommanes may run before those related to syntax and thus the former
        may have the syntax cleared by the latter.

        You probably don't need to do the highlight command similarly; just
        having it in your .vimrc as you currently do is probably enough. But if
        you need to include it, or a little more highlighting, in an
        autocommand, a small function in your .vimrc which you call with an
        autocommand becomes an attractive option.

        Hope this helps, and gives enough debugging tips, too.

        Cheers,

        Ben.



        --
        You received this message from the "vim_use" maillist.
        Do not top-post! Type your reply below the text you are replying to.
        For more information, visit http://www.vim.org/maillist.php
      • Samkit Jain
        Thanks Ben, let me try what are suggesting. But I still dont think that it should be a autocmd to do this. On Sun, May 1, 2011 at 7:04 PM, Ben Schmidt ... -- -
        Message 3 of 4 , May 4, 2011
          Thanks Ben, let me try what are suggesting. But I still dont think
          that it should be a autocmd to do this.

          On Sun, May 1, 2011 at 7:04 PM, Ben Schmidt
          <mail_ben_schmidt@...> wrote:
          >> syntax keyword UserKeywords Samkit CHECKME REVIEW CHECKME
          >> containedin=ALL
          >> highlight def link UserKeywords Todo
          >
          > You probably don't want the 'def' in there, but it probably doesn't
          > really matter.
          >
          >> This works fine if I open an unnamed file like just "gvim".
          >
          > Syntax is buffer-specific, so as soon as you edit any other file of any
          > other type, it will no longer be in effect.
          >
          >> I am suspecting that something is calling "highlight clear" but I am
          >> not sure of this.
          >
          > That won't be happening. You can confirm this, though, by typing
          >
          >   :verbose highlight
          >
          > It will show the highlight group (even with 'cleared' beside it, if it
          > has been cleared), and in the line below, the file that last set it (or
          > cleared it).
          >
          > Likewise
          >
          >   :verbose syntax
          >
          > will let you know where syntax groups originated, though this is often a
          > little less useful (cleared groups are not shown, I don't think).
          >
          >> Additionally after opening 1.c I checked if my syntax group exists and
          >> it exists so it can only be the work of "highlight clear".
          >
          > This can't really be possible (that the syntax group exists). Probably
          > the highlight group for your syntax item exists, but the actual syntax
          > rule will not. I.e. you will see it listed in :highlight but not in
          > :syntax.
          >
          >> :hi UserKeywords
          >> UserKeywords   xxx links to Todo
          >
          > This is as expected.
          >
          > If you do :syn UserKeywords, though, you will not see it.
          >
          >> For this much highlighting I would not like to create a new
          >> runtimepath/after/syntax/default.vim containing above syntax+highlight
          >> group commands and then source it for every BufRead and FileRead.
          >
          > You can use an autocommand to just run the syntax you want on those
          > events. Put something like this in .vimrc:
          >
          > autocmd BufNewFile,BufRead * syntax keyword UserKeywords
          >        \ Samkit CHECKME REVIEW CHECKME containedin=ALL
          >
          > Adjust the * if you want to apply to specific filetypes, and ensure it
          > is after the filetype on and/or syntax on commands in your vimrc or the
          > autocommanes may run before those related to syntax and thus the former
          > may have the syntax cleared by the latter.
          >
          > You probably don't need to do the highlight command similarly; just
          > having it in your .vimrc as you currently do is probably enough. But if
          > you need to include it, or a little more highlighting, in an
          > autocommand, a small function in your .vimrc which you call with an
          > autocommand becomes an attractive option.
          >
          > Hope this helps, and gives enough debugging tips, too.
          >
          > Cheers,
          >
          > Ben.
          >
          >
          >
          >



          --
          - Samkit

          --
          You received this message from the "vim_use" maillist.
          Do not top-post! Type your reply below the text you are replying to.
          For more information, visit http://www.vim.org/maillist.php
        • Ben Fritz
          ... How else would you expect syntax highlighting to work? Would you prefer that if you switch between a C file and a PHP file that the syntax rules just keep
          Message 4 of 4 , May 4, 2011
            On May 4, 11:51 am, Samkit Jain <samkit.fe...@...> wrote:
            > Thanks Ben, let me try what are suggesting. But I still dont think
            > that it should be a autocmd to do this.
            >

            How else would you expect syntax highlighting to work? Would you
            prefer that if you switch between a C file and a PHP file that the
            syntax rules just keep building on each other instead of replacing
            each other?

            --
            You received this message from the "vim_use" maillist.
            Do not top-post! Type your reply below the text you are replying to.
            For more information, visit http://www.vim.org/maillist.php
          Your message has been successfully submitted and would be delivered to recipients shortly.