On Thu, Oct 15, 2015 at 7:27 AM, Tony Mechelynck <[email protected]> wrote: > On Thu, Oct 15, 2015 at 4:30 AM, <[email protected]> wrote: >> Hi all, >> >> I have right now an autocommand, au BufWritePost *.foo :run_cmd. >> >> I want it to run upon writing all files matching *.foo, but not any files >> matching bar.*, or more equivalently bar.*.foo. >> >> How can I disable the autocommand for files starting with bar? The full path >> of an ideally excluded file may be /tmp/dir/bar.qux.foo, while >> /tmp/dir/qux.foo should be included >> >> Thanks, everyone! > > Simple (but sometimes when it's too simple we don't think of it) > > :au BufWritePost *
oops —the above should of course have been :au BufWritePost *.foo > \ if <amatch> !~ '^bar\.' | RunCmd | endif > > see > :h <amatch> > :h expr-!~ > :h line-continuation > > Notes: > 1. !~ takes a full-fledged Vim pattern as in the / :s :g etc. > commands, not a shell-like "glob pattern". So the ^ (spacing > circumflex) matches zero characters at the beginning of the string, > and the \. (slash-dot) matches an actual dot. Any match starting with > "bar." will thus take the (empty) false path of the :if — and do > nothing. > 2. The use of line continuation assumes that you're running Vim in > 'nocompatible' mode, or at least without the C flag in 'cpoptions'. > 3. You cannot define a user command named :run_cmd but you can > define one named :RunCmd (every user-command name must start with an > uppercase letter). > > > Best regards, > Tony. -- -- 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 --- You received this message because you are subscribed to the Google Groups "vim_use" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
