1

I have some lua auto command that triggers whenever I open a file that has */some_pattern/* in the path.

vim.api.nvim_create_autocmd({ 'BufEnter' }, {
    pattern = vim.fn.expand('~') .. '*/some_pattern/*',
    command="echo 'disable'"
})

I'd also like to have a command that triggers for the exact opposite.

vim.api.nvim_create_autocmd({ 'BufEnter' }, {
    pattern = oppsotite_of(vim.fn.expand('~') .. '*/some_pattern/*'),
    command="echo 'disable'"
})

How can I do this?

1
  • Do you still have something open in your question? How can we help you further? Otherwise may be could accept one of the answers using the v button next to the arrow voting buttons. It allow the question to rest :-) Commented Jul 22, 2023 at 16:11

1 Answer 1

0

Is your pattern is *.py I would do: {*}{*.py}\@<!

vim.api.nvim_create_autocmd({ 'BufEnter' }, {
    pattern = '{*}' .. '{' .. '*/some_pattern/*' .. '}\@<!',
    command="echo 'disable'"
})

Where:

  • {*} is the equivalent of \(.*\)
  • {*.py}\@<! is the equivalent of \(.*\.py\)\@<!

More information with:

  • :help file-pattern
  • :help /\@<!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.