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

Re: Having trouble using conceal

Expand Messages
  • Ben Fritz
    ... When Vim does filetype detection, it clears any existing syntax and sources the proper syntax file for the newly detected filetype, if any. Your syntax
    Message 1 of 7 , Jan 1, 2013
    • 0 Attachment
      On Monday, December 31, 2012 3:59:03 PM UTC-6, HarleyPig wrote:
      > I have a map I use that inserts a timestamp in the form of
      >
      > __TS:1356990559|Dec 31, 2012 14:49__
      >
      > The dual nature allows me to visually parse the date, and process my entries easily with a program that parses the file.
      >
      > I'm trying to conceal the TS:...| part to make it visually more pleasing. Basically, eye-candy. But I am not succeeding at all.
      >
      > This is what I have (if you want the context, see it here: http://goo.gl/EDZ3q )
      >
      > if has( 'conceal' )
      >
      > " How can I use variables for the patterns?
      > "syntax region myTimeStamp start="__TS:" end="\|" oneline conceal cchar=_
      > syntax region myTimeStamp start="__TS:" end="\|"
      > "highlight link myTimeStamp Conceal
      > highlight myTimeStamp ctermfg=red ctermbg=blue
      > set conceallevel=2
      >
      > endif
      >
      > Obviously, I'm misunderstanding syntax highlighting in general, because the region isn't being highlighted, let aloned concealed (when uncommented).
      >
      > What am I doing wrong?

      When Vim does filetype detection, it clears any existing syntax and sources the proper syntax file for the newly detected filetype, if any.

      Your syntax rules (defined globally, outside of any filetype) are probably being discarded.

      Try creating the file in .vim/syntax and detecting the filetype. Or source the syntax file manually for a quick check.

      You should look at the syntax files in $VIMRUNTIME/syntax for an example, there are other things to do to set up for a new syntax, unless you're adding to an existing syntax, in which case your current method still won't work for the reason given above.

      I think there's a help section for new syntax files as well but I don't have Vim installed on the system I'm on at the moment so I can't easily look it up.

      --
      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
    • HarleyPig
      Hmm ... I thought I could have a global syntax. I wanted this to work across any syntax and/or filetype. If I manually source the file it works, or if I make
      Message 2 of 7 , Jan 1, 2013
      • 0 Attachment
        Hmm ... I thought I could have a global syntax. I wanted this to work across any syntax and/or filetype.

        If I manually source the file it works, or if I make a after/syntax/perl.vim file it will work in my perl files, at least partially--I can't seem to make it work when the timestamp is part of a comment.

        I'll have to experiment further.

        --
        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
      • Tony Mechelynck
        ... Try sourcing it from an autocommand, as follows: au VimEnter * au Syntax * source ~/.vim/ownsyntax.vim The VimEnter autocommand is there to add the Syntax
        Message 3 of 7 , Jan 1, 2013
        • 0 Attachment
          On 02/01/13 07:13, HarleyPig wrote:
          > Hmm ... I thought I could have a global syntax. I wanted this to work across any syntax and/or filetype.
          >
          > If I manually source the file it works, or if I make a after/syntax/perl.vim file it will work in my perl files, at least partially--I can't seem to make it work when the timestamp is part of a comment.
          >
          > I'll have to experiment further.
          >

          Try sourcing it from an autocommand, as follows:

          au VimEnter * au Syntax * source ~/.vim/ownsyntax.vim

          The VimEnter autocommand is there to add the Syntax autocommand as late
          as possible among Syntax autocommands (I hope it will add it late
          enough, I didn't check); the Syntax autocommand (defined by the VimEnter
          autocommand) will then be triggered (and source the script) by setting
          the 'syntax' option for any file. This ownsyntax.vim script should then
          change only settings local to the current editfile (using :setlocal,
          :map <buffer>, etc.).

          Best regards,
          Tony.
          --
          Have an adequate day.

          --
          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
        • HarleyPig
          ... That didn t work, but this did: if ! exists( autocmds_loaded ) let autocmds_loaded = 1 autocmd BufEnter * source endif if has( conceal ) How
          Message 4 of 7 , Jan 2, 2013
          • 0 Attachment
            On Wednesday, January 2, 2013 12:24:05 AM UTC-7, Tony Mechelynck wrote:
            > Try sourcing it from an autocommand, as follows:
            >
            > au VimEnter * au Syntax * source ~/.vim/ownsyntax.vim

            That didn't work, but this did:

            if ! exists( "autocmds_loaded" )

            let autocmds_loaded = 1
            autocmd BufEnter * source <sfile>

            endif

            if has( 'conceal' )

            " How can I use variables for the patterns?
            "syntax region myTimeStamp start="__TS:" end="|" conceal
            syntax match myTimeStamp "__TS:.*|" conceal
            highlight myTimeStamp ctermfg=red ctermbg=blue
            set conceallevel=2

            endif


            Thank you.

            My remaining problems are how to use a variable in the match (or region, I'm not sure which is better) and how to make the syntax work in commented sections.

            --
            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
          • Charles Campbell
            ... variable in the match/region: :help execute syntax work in (whatever) section: :help syn-containedin To figure out what section you re in... see
            Message 5 of 7 , Jan 2, 2013
            • 0 Attachment
              HarleyPig wrote:
              > <snip>
              > My remaining problems are how to use a variable in the match (or
              > region, I'm not sure which is better) and how to make the syntax work
              > in commented sections.
              variable in the match/region: :help execute
              syntax work in (whatever) section: :help syn-containedin

              To figure out what section you're in... see
              http://www.drchip.org/astronaut/vim/index.html#HILINKS

              Regards,
              Chip Campbell

              --
              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
            • HarleyPig
              ... Oh! Thanks ... I was looking for eval and it just wasn t making any sense for what I was trying to do. Now I ve got execute syntax match myTimeStamp .
              Message 6 of 7 , Jan 2, 2013
              • 0 Attachment
                On Wednesday, January 2, 2013 2:11:46 PM UTC-7, Charles Campbell wrote:
                > variable in the match/region: :help execute
                > syntax work in (whatever) section: :help syn-containedin

                Oh! Thanks ... I was looking for eval and it just wasn't making any sense for what I was trying to do. Now I've got

                execute 'syntax match myTimeStamp "' . g:timestamp_format_begin . '.*' . g:timestamp_format_delim . '" conceal containedin=.*Comment.*'

                and it's working fine. Thanks.

                > http://www.drchip.org/astronaut/vim/index.html#HILINKS

                Interesting plugin ... along with some others. I don't suppose you have these in a publicly available repo somewhere?

                Nice ... I'm already using Align. Didn't realize you were the author.

                --
                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.