1

I would like to format my code using /bin/black everytime I save a python file in neovim. So I have the following in my ~/.config/nvim/init.lua

a.nvim_create_autocmd( { "BufWritePre" }, {
  pattern = { "*.py" },
  command = [[ /bin/black ]],
})

but I get the error like:

E492: Not an editor command:  /bin/black

Could someone let me know how can I run black (an external command) in BufWritePre set.

Cheers, DD.

romainl
  • 186,200
  • 21
  • 280
  • 313
DDStackoverflow
  • 505
  • 1
  • 11
  • 26

1 Answers1

1

sorry for the question and I got it.

it command should be

a.nvim_create_autocmd( { "BufWritePre" }, {
  pattern = { "*.py" },
  command = [[ !/bin/black % ]],
})

where ! for external command and % for current file.

DDStackoverflow
  • 505
  • 1
  • 11
  • 26