Skip to content

Advanced techniques

Matthew Leong edited this page Apr 15, 2022 · 15 revisions

This page contains advanced techniques.

Managing completion timing completely

nvim-cmp has a programmatic API. So you can manage the completion behavior by yourself.

See https://github.com/hrsh7th/nvim-cmp/issues/519#issuecomment-969674104

Disabling completion in certain contexts, such as comments

See https://github.com/hrsh7th/nvim-cmp/pull/676#issuecomment-1002532096

cmp.setup({
    enabled = function()
      -- disable completion in comments
      local context = require 'cmp.config.context'
      -- keep command mode completion enabled when cursor is in a comment
      if vim.api.nvim_get_mode().mode == 'c' then
        return true
      else
        return not context.in_treesitter_capture("comment") 
          and not context.in_syntax_group("Comment")
      end
    end
})
Clone this wiki locally