1
au FileType python let b:coc_root_patterns = ['.git', '.env', 'venv', '.venv', 'setup.cfg', 'setup.py', 'pyrightconfig.json']

I guess not many people using this config with neovim.

jdhao
  • 24,001
  • 18
  • 134
  • 273

3 Answers3

1

See:
:help nvim_command
Than you can do...

local vscript = "au FileType python let b:coc_root_patterns = ['.git', '.env', 'venv', '.venv', 'setup.cfg', 'setup.py', 'pyrightconfig.json']"

vim.api.nvim_command(vscript)

Check afterwards in nvim command mode: :au FileType

koyaanisqatsi
  • 2,585
  • 2
  • 8
  • 15
1

If you are using nvim 0.7 or later, there is now native Lua api nvim_create_autocmd for this.

local api = vim.api

api.nvim_create_autocmd({'FileType'},
  pattern = 'python',
  callback = function()
    vim.b.coc_root_patterns = {'.git', '.env', 'venv', '.venv', 'setup.cfg', 'setup.py', 'pyrightconfig.json'}
  end
)

The equivalent for vim script b:xxx variable is vim.b in Lua, see also :help vim.b for more info.

jdhao
  • 24,001
  • 18
  • 134
  • 273
1

I think it should be like this.

local group = vim.api.nvim_create_augroup('coc_root', { clear = true })
local events = { 'FileType' }
vim.api.nvim_create_autocmd( events, {
  pattern = 'python',
  callback = function()
    vim.bo.coc_root_patterns = { '.git', '.env', 'venv', '.venv', 'setup.cfg', 'setup.py', 'pyrightconfig.json' }
  end,
  group = group,
})

I really did not test it, let me know if it does not work.

vim.bo, autocmd

LoneExile
  • 151
  • 1
  • 5