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

Re: autocmd pattern exclusion?

Expand Messages
  • Andy Wokula
    ... Hints: - items starting with ` are used like in regexp patterns - the item to match any character is `? , even within ` (... ) ; the dot `. matches `.
    Message 1 of 6 , Nov 28, 2012
    • 0 Attachment
      Am 28.11.2012 17:31, schrieb Matt Martini:
      > I have an autocmd that I would like to trigger for all files, except a
      > certain file. Is there a way to write this?
      >
      > I'm thinking something like:
      >
      > autocmd BufReadPost *, !.git/COMMIT_EDITMSG <do stuff>

      There is a way:
      :h autocmd-patterns
      and a few lines below:
      :h file-pattern

      It is allowed to intermix regexp patterns:

      :autocmd BufReadPost *\(.git/COMMIT_EDITMSG\)\@<! <do stuff>

      Hints:
      - items starting with `\' are used like in regexp patterns
      - the item to match any character is `?', even within `\(...\)'; the
      dot `.' matches `.' literally here
      - I had to use `\(', because `\%(' gave me an error message
      E55: Unmatched \)

      No warranty, HTH,
      Andy

      --
      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
    • Matt Martini
      ... Worked like a charm, thanks! -- You received this message from the vim_use maillist. Do not top-post! Type your reply below the text you are replying to.
      Message 2 of 6 , Nov 28, 2012
      • 0 Attachment
        On Nov 28, 2012, at 2:22 PM, Andy Wokula wrote:

        > Am 28.11.2012 17:31, schrieb Matt Martini:
        >> I have an autocmd that I would like to trigger for all files, except a
        >> certain file. Is there a way to write this?
        >>
        >> I'm thinking something like:
        >>
        >> autocmd BufReadPost *, !.git/COMMIT_EDITMSG <do stuff>
        >
        > There is a way:
        > :h autocmd-patterns
        > and a few lines below:
        > :h file-pattern
        >
        > It is allowed to intermix regexp patterns:
        >
        > :autocmd BufReadPost *\(.git/COMMIT_EDITMSG\)\@<! <do stuff>
        >
        > Hints:
        > - items starting with `\' are used like in regexp patterns
        > - the item to match any character is `?', even within `\(...\)'; the
        > dot `.' matches `.' literally here
        > - I had to use `\(', because `\%(' gave me an error message
        > E55: Unmatched \)
        >
        > No warranty, HTH,
        > Andy
        >

        Worked like a charm, thanks!



        --
        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
        ... I didn t know you could use regex patterns in autocmds. The only indication I see of this fact is from :help file-patterns: special meaning like in a
        Message 3 of 6 , Nov 28, 2012
        • 0 Attachment
          On Wednesday, November 28, 2012 1:22:55 PM UTC-6, Andy Wokula wrote:
          >
          > There is a way:
          >
          > :h autocmd-patterns
          >
          > and a few lines below:
          >
          > :h file-pattern
          >
          >
          >
          > It is allowed to intermix regexp patterns:
          >
          >
          >
          > :autocmd BufReadPost *\(.git/COMMIT_EDITMSG\)\@<! <do stuff>
          >
          >
          >
          > Hints:
          >
          > - items starting with `\' are used like in regexp patterns
          >
          > - the item to match any character is `?', even within `\(...\)'; the
          >
          > dot `.' matches `.' literally here
          >
          > - I had to use `\(', because `\%(' gave me an error message
          >
          > E55: Unmatched \)
          >
          >

          I didn't know you could use regex patterns in autocmds. The only indication I see of this fact is from :help file-patterns:

          \ special meaning like in a |pattern|

          This certainly doesn't tell me regex in general is supported! I wonder if things other than \%( and . break, and how much of it works by accident.

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