Skip to content

Disable autocomplete in a comment block #122

Answered by VonHeikemen
twiclo asked this question in Q&A
Discussion options

You must be logged in to vote

The autocomplete plugin is nvim-cmp.

If you are using the recommended preset then change it to lsp-compe, then use this snippet.

local lsp = require('lsp-zero')
lsp.preset('lsp-compe')

lsp.setup()

vim.opt.completeopt = {'menu', 'menuone', 'noselect'}

local cmp = require('cmp')
local cmp_enabled = cmp.get_config().enabled
local cmp_config = lsp.defaults.cmp_config({
  enabled = function()
    if require('cmp.config.context').in_treesitter_capture('comment') == true
      or require('cmp.config.context').in_syntax_group('Comment')
    then
      return false
    else
      -- execute cmp's original function
      return cmp_enabled()
    end
  end
})

cmp.setup(cmp_config)

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@twiclo
Comment options

@windowsrefund
Comment options

@VonHeikemen
Comment options

Answer selected by twiclo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants