Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

How to disable nvim-cmp or disable all cmp-sources for certain files? #1522

Closed
doronbehar opened this issue Apr 18, 2023 · 5 comments
Closed

Comments

@doronbehar
Copy link

I have a long bash script with an enormous amount of variables that I think make my nvim-cmp stuck when I try to edit it. How do I disable it? I'm looking for something like treesitter's feature:

https://github.com/nvim-treesitter/nvim-treesitter/blob/master/README.md?plain=1#L132-L139

@doronbehar
Copy link
Author

BTW I did encounter the enable = function() ... end option to cmp.setup, but the problem is that it seems that I either enable completely, or disable completely nvim-cmp... The behavior I'm looking for is per-buffer and per cmp-source: to be able to control which cmp source is enabled for each buffer. I did find out that the problematic cmp source is cmp-treesitter.

@uga-rosa
Copy link
Contributor

It can be managed from the source side by defining the source:is_available() method.

nvim-cmp/doc/cmp.txt

Lines 748 to 752 in e28fb7a

---Return whether this source is available in the current context or not (optional).
---@return boolean
function source:is_available()
return true
end

In other words, this issue should be put up in cmp-treesitter, not here.

@hrsh7th
Copy link
Owner

hrsh7th commented Apr 25, 2023

You can fully control nvim-cmp configuration based on autocmd as below.

vim.api.nvim_create_autocmd('FileType', {
  callback = function()
    require('cmp').setup.buffer {
      ...
    }
  end,
})

@hrsh7th hrsh7th closed this as completed Apr 25, 2023
@doronbehar
Copy link
Author

Thanks for the idea @hrsh7th :) For the sake of others I added a wiki subsection at:

https://github.com/hrsh7th/nvim-cmp/wiki/Advanced-techniques#disable--enable-cmp-sources-only-on-certain-buffers

@gitaarik
Copy link

gitaarik commented Mar 9, 2024

This seems to work for me too, for completely disabling nvim-cmp for a certain filetype:

require("cmp").setup.filetype("txt", {
  enabled = false,
})

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants