Coc.nvim: Disable coc.nvim per filetype (i.e. a filetype whitelist or blacklist)

Created on 16 Jan 2019  路  8Comments  路  Source: neoclide/coc.nvim

Hi folks, I'd like to propose a feature (or maybe it exists and I simply couldn't find how to invoke it).

I'd like to be able to enable/disable coc on a filetype-by-filetype basis.

Why? In my opinion, there are certain filetypes where YouCompleteMe handles completion better than than LSPs. But in most filetypes, coc is better. Ideally I'd like to use YouCompleteMe in the filetypes where it shines, and coc.nvim in other filetypes.

YouCompleteMe can already handle this with g:ycm_filetype_whitelist and g:ycm_filetype_blacklist, but I don't believe coc can do this.

There's also an alternative implementation, as seen in ncm2, where you must call ncm2#enable_for_buffer(), which allows for autocmd entries on a filetype basis. This would also satisfy my feature request.

Is this feature already available in coc, or is it something that could possibly be implemented in the future?

Thank you!

Most helpful comment

Argh, don't close this! Many of us are using something other than ... whatever you're using for plugins. For example, I'm using the native vim package manager, and it's not clear how to have CoC disabled in every buffer except ones of a certain file type.

I don't want CoC to do anything with Markdown, but still want it to be enabled on Go files. These are files in the same project and likely to be open in the same nvim instance. Is the recommendation seriously that we add buffopen commands for every filetype for this behavior?

All 8 comments

It's designed to work with all your buffers, you can use plugin manager to load it on specific filetypes.

For enable/disable coc after plugin loaded ,use :CocEnable and :CocDisable commands.

Ok, thank you for the guidance. I have something that seems to be working effectively:

Load coc.nvim on certain filetypes:

Plug 'neoclide/coc.nvim', {'tag': '*', 'do': 'yarn install', 'for': ['json', 'lua', 'vim', ]}

Blacklist those types for YCM:

let g:ycm_filetype_blacklist = {
            \ 'vim': 1,         
            \ 'lua': 1,         
            \ 'json': 1,        
            \ }

Enable on BufNew/BufEnter, disable on BufLeave:

autocmd BufNew,BufEnter *.json,*.vim,*.lua execute "silent! CocEnable"
autocmd BufLeave *.json,*.vim,*.lua execute "silent! CocDisable"

Closing. Thanks again.

Argh, don't close this! Many of us are using something other than ... whatever you're using for plugins. For example, I'm using the native vim package manager, and it's not clear how to have CoC disabled in every buffer except ones of a certain file type.

I don't want CoC to do anything with Markdown, but still want it to be enabled on Go files. These are files in the same project and likely to be open in the same nvim instance. Is the recommendation seriously that we add buffopen commands for every filetype for this behavior?

I have a use-case where I want to disable CoC for diffs. The problem is, diff is a buffer type, not a file type. So this approach doesn't work.

Is it possible to get the Language source in the completion list even if the file type is not appropriate?

E.g. I really want to have autocompletion for Latex formulas while I'm editing in Markdown.
But even after manually activating the latex extension, auto-complete suggestion do not show up in the list?

Is there any way to achieve this?

@igor-dimi you can :set ft=tex temporarily, or setup a mapping for that.

Like others here, I am interested for CoC to be enabled only for certain file types. I attempted to address this with the for option in Plug (sensu Plug 'neoclide/coc.nvim', {'branch': 'release', 'for': ['r', 'rmd']} ) but I get the following error when opening nvim.

Error detected while processing CursorHold Autocommands for "*":
E117: Unknown function: CocActionAsync

I get the same results even with the autocmd suggestions that @mike-hearn added, and the Plug syntax he had used.

For the time being, I will just disable CoC for all files (autocmd BufNew,BufRead * execute "CocDisable") and enable manually with CocEnable when needed, but that is not ideal so any help or suggestions would be appreciated. Thanks!

UPDATE:

Able to address this with an augroup per this related issue but, still, it seems that addressing this with the plugin manager would be preferable, especially as there is a lag as noted by @mb720

augroup CocGroup
  autocmd!
  autocmd BufNew,BufRead * execute "CocDisable"
  autocmd BufNew,BufEnter *.R execute "silent! CocEnable"
  autocmd BufNew,BufEnter *.Rmd execute "silent! CocEnable"
  autocmd BufNew,BufEnter *.py execute "silent! CocEnable"
augroup end

Thanks for the great plugin.

Being able to disable by default but whitelist certain filetypes would be top of my list in terms of feature requests too.

Getting coc.nvim and deoplete to play nice together is mind bending and I feel this would make it easier.

Was this page helpful?
0 / 5 - 0 ratings