Convert Figma logo to code with AI

ms-jpq logocoq_nvim

Fast as FUCK nvim completion. SQLite, concurrent scheduler, hundreds of hours of optimization.

3,486
96
3,486
171

Top Related Projects

24,306

Nodejs extension host for vim & neovim, load extensions like VSCode and host language servers.

A completion plugin for neovim coded in Lua.

:stars: Dark powered asynchronous completion framework for neovim/Vim8

A code-completion engine for Vim

3,103

async language server protocol plugin for vim and neovim

13,476

Check syntax in Vim/Neovim asynchronously and fix files, with Language Server Protocol (LSP) support

Quick Overview

Coq_nvim is a fast, asynchronous auto-completion plugin for Neovim. It aims to provide a smooth and efficient completion experience with minimal configuration, leveraging the power of Neovim's built-in Language Server Protocol (LSP) client.

Pros

  • Fast and lightweight, with minimal impact on editor performance
  • Asynchronous operation, ensuring smooth typing experience
  • Integrates well with Neovim's built-in LSP client
  • Highly customizable with a wide range of configuration options

Cons

  • Requires Neovim 0.5 or later, not compatible with older versions or Vim
  • May have a steeper learning curve for users new to Neovim or LSP
  • Some advanced features may require additional setup or plugins

Code Examples

Here are a few examples of how to configure and use coq_nvim:

Basic setup in your Neovim configuration:

vim.cmd('packadd coq_nvim')
local coq = require('coq')
vim.cmd('COQnow -s')

Configuring completion sources:

require('coq').setup({
  sources = {
    { name = 'nvim_lsp' },
    { name = 'buffer', max_item_count = 7 },
    { name = 'path', max_item_count = 10 },
  }
})

Custom keybindings for completion navigation:

vim.api.nvim_set_keymap('i', '<C-j>', 'pumvisible() ? "<C-n>" : "<C-j>"', { expr = true, noremap = true })
vim.api.nvim_set_keymap('i', '<C-k>', 'pumvisible() ? "<C-p>" : "<C-k>"', { expr = true, noremap = true })

Getting Started

To get started with coq_nvim, follow these steps:

  1. Ensure you have Neovim 0.5 or later installed.
  2. Install coq_nvim using your preferred plugin manager. For example, with packer.nvim:
use {
  'ms-jpq/coq_nvim',
  branch = 'coq'
}
use {'ms-jpq/coq.artifacts', branch = 'artifacts'}
  1. Add the following to your Neovim configuration:
vim.cmd('packadd coq_nvim')
local coq = require('coq')
vim.cmd('COQnow -s')
  1. Restart Neovim and enjoy enhanced auto-completion!

Competitor Comparisons

24,306

Nodejs extension host for vim & neovim, load extensions like VSCode and host language servers.

Pros of coc.nvim

  • Extensive language server protocol (LSP) support with a wide range of extensions
  • Well-established and mature project with a large user base
  • Supports multiple programming languages out of the box

Cons of coc.nvim

  • Heavier resource usage compared to coq_nvim
  • Requires Node.js as a dependency
  • Can be slower to start up, especially with many extensions loaded

Code Comparison

coc.nvim configuration example:

let g:coc_global_extensions = ['coc-json', 'coc-tsserver']
inoremap <silent><expr> <TAB> pumvisible() ? "\<C-n>" : "\<TAB>"
inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"

coq_nvim configuration example:

vim.g.coq_settings = {
  auto_start = 'shut-up',
  keymap = { recommended = false },
  clients = { tabnine = { enabled = true } }
}

Both projects aim to provide autocompletion and LSP integration for Neovim, but they differ in their approach and resource usage. coc.nvim offers a more comprehensive set of features and extensions, while coq_nvim focuses on performance and minimal resource consumption. The choice between the two depends on the user's specific needs and system capabilities.

A completion plugin for neovim coded in Lua.

Pros of nvim-cmp

  • More extensive plugin ecosystem and wider community support
  • Highly customizable with a modular architecture
  • Better out-of-the-box performance for large codebases

Cons of nvim-cmp

  • Steeper learning curve and more complex configuration
  • Requires more manual setup for optimal functionality
  • May have occasional stability issues with certain plugin combinations

Code Comparison

nvim-cmp configuration example:

require('cmp').setup({
  sources = {
    { name = 'nvim_lsp' },
    { name = 'buffer' },
  },
  mapping = {
    ['<C-Space>'] = cmp.mapping.complete(),
  },
})

coq_nvim configuration example:

let g:coq_settings = { 'auto_start': 'shut-up' }

nvim-cmp offers more granular control over sources and mappings, while coq_nvim provides a simpler setup with sensible defaults. nvim-cmp's configuration is typically done in Lua, whereas coq_nvim uses Vimscript for its primary configuration.

Both plugins aim to provide efficient autocompletion for Neovim, but they differ in their approach to configuration and extensibility. nvim-cmp offers more flexibility at the cost of complexity, while coq_nvim focuses on ease of use and performance out of the box.

:stars: Dark powered asynchronous completion framework for neovim/Vim8

Pros of deoplete.nvim

  • Mature and stable project with a large user base
  • Extensive plugin ecosystem for various languages and frameworks
  • Lightweight and efficient, with minimal impact on editor performance

Cons of deoplete.nvim

  • Requires more manual configuration compared to coq_nvim
  • Less out-of-the-box functionality for certain advanced features
  • Development has slowed down in recent years

Code Comparison

deoplete.nvim configuration:

call deoplete#custom#option('sources', {
    \ '_': ['buffer', 'file', 'around'],
    \ 'python': ['jedi'],
})

coq_nvim configuration:

require('coq').setup({
    auto_start = true,
    clients = {
        lsp = true,
        tree_sitter = true,
        snippets = true,
    },
})

Both projects aim to provide autocompletion for Neovim, but they differ in their approach and feature set. deoplete.nvim offers a more traditional, plugin-based system with extensive customization options, while coq_nvim provides a more modern, integrated experience with built-in LSP support and advanced features like snippets and treesitter integration. The choice between the two largely depends on the user's preferences for configuration complexity and desired out-of-the-box functionality.

A code-completion engine for Vim

Pros of YouCompleteMe

  • Mature and well-established project with a large user base
  • Supports a wide range of programming languages out of the box
  • Integrates with external tools for enhanced functionality

Cons of YouCompleteMe

  • Can be complex to set up and configure
  • Requires compilation, which may be challenging for some users
  • Heavier resource usage compared to lighter alternatives

Code Comparison

YouCompleteMe configuration example:

let g:ycm_auto_trigger = 1
let g:ycm_min_num_of_chars_for_completion = 2
let g:ycm_complete_in_comments = 1

coq_nvim configuration example:

let g:coq_settings = { 'auto_start': 'shut-up' }

YouCompleteMe offers more granular control over its behavior, while coq_nvim aims for simplicity with fewer configuration options. coq_nvim is designed to be fast and lightweight, with a focus on Lua-based configuration. It also features a unique "3-stage" completion system. On the other hand, YouCompleteMe provides robust language support and integration with external tools, making it a powerful choice for developers working with multiple languages.

3,103

async language server protocol plugin for vim and neovim

Pros of vim-lsp

  • Lightweight and focused solely on LSP integration
  • Supports a wide range of language servers out of the box
  • Highly customizable with extensive configuration options

Cons of vim-lsp

  • Requires manual setup and configuration for each language server
  • Less feature-rich in terms of autocompletion compared to coq_nvim
  • May have slower performance for large projects or complex language servers

Code Comparison

vim-lsp configuration example:

let g:lsp_settings = {
    \ 'pyls': {'workspace_config': {'pyls': {'plugins': {'pycodestyle': {'enabled': v:false}}}}},
    \ 'gopls': {'initialization_options': {'usePlaceholders': v:true}},
    \ }

coq_nvim configuration example:

require("coq_3p") {
  { src = "nvimlua", short_name = "nLUA" },
  { src = "vimtex", short_name = "vTEX" },
  { src = "copilot", short_name = "COP", accept_key = "<c-f>" },
}

Both plugins aim to enhance Vim/Neovim with language server capabilities, but they take different approaches. vim-lsp focuses on providing a flexible LSP client, while coq_nvim offers a more comprehensive autocompletion solution with additional features. The choice between them depends on the user's specific needs and preferences for customization versus out-of-the-box functionality.

13,476

Check syntax in Vim/Neovim asynchronously and fix files, with Language Server Protocol (LSP) support

Pros of ALE

  • Broader language support with over 200 linters and fixers
  • Integrates linting, fixing, and completion in one plugin
  • More mature project with a larger community and extensive documentation

Cons of ALE

  • Can be slower and more resource-intensive, especially with multiple linters
  • Configuration can be complex due to the wide range of supported tools
  • Less focused on autocompletion compared to Coq.nvim

Code Comparison

ALE configuration example:

let g:ale_linters = {
\   'javascript': ['eslint'],
\   'python': ['flake8', 'pylint']
\}
let g:ale_fixers = {
\   '*': ['remove_trailing_lines', 'trim_whitespace'],
\   'javascript': ['prettier', 'eslint'],
\}

Coq.nvim configuration example:

require("coq").setup({
  auto_start = true,
  clients = {
    lsp = {
      enabled = true,
      weight_adjust = 1.5,
    },
    tree_sitter = {
      enabled = true,
    },
  },
})

Both plugins offer powerful features for Neovim users, but they focus on different aspects. ALE provides a comprehensive linting and fixing solution with broad language support, while Coq.nvim specializes in fast, asynchronous autocompletion with a more streamlined setup.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

coq.nvim 🐔

Named after the famous theorem prover

coq also means 鸡 in français québécois, and I guess 🥖.

Fast as FUCK and loads of features.

Faster Than Pure Lua

  • Native C in-memory B-trees

  • SQLite VM interrupts

  • Coroutine based incremental & interruptible scheduler

  • TCP-esque flow control

More details at the PERFORMANCE.md

Features

Note: Due to compression, reality is faster than gifs

Fast as fuck

  • Results on every keystroke

  • Throttling? Never heard of her

  • Real time performance statistics

  • Look at the gifs! The bottom few are the fastest when I didn't slow down on purpose to show features.

Fuzzy Search

Error correction: cour -> colour_space, flgr -> flag_group, nasp -> Namespace

fuzz_search.img

Preview

  • Press key to view documentation in big buffer

  • Auto open preview on side with most space

  • Customizable location: n, s, w, e

  • Ubiquitous: Tags, LSP, TreeSitter, Paths, Snippets

doc_popup.img

LSP

  • Incremental completion

  • Client-side caching

  • Multi-server completion (i.e. tailwind + cssls)

  • Multi-encoding utf-8, utf-16, utf-32

  • Header imports

lsp_imports.img

  • Snippet Support

lsp_snippets.img

Install the Nvim Official LSP integration

Requires 2 lines of change to support LSP snippets

local lsp = require "lspconfig"
local coq = require "coq" -- add this

lsp.<server>.setup(<stuff...>)                              -- before
lsp.<server>.setup(coq.lsp_ensure_capabilities(<stuff...>)) -- after

Snippets

snippet_norm.img

  • Linked regions

snippet_expand.img

snip_load.img

The % statistic comes from compiling the 10,000 snippets

TreeSitter

  • Shows context

  • Partial document parsing

  • Auto-disable if document is too big

  • Unicode ready

treesitter.img

Treesitter is still unstable in nvim0.5: slow and crash prone

The promise is that Treesitter will have real time parsing on every keystroke, but it's actually too slow on big files.

The Treesitter source only parses a limited number of lines about the cursor and only on Idle events due to unrealized performance promises.

CTags

  • LSP like

  • Incremental & automatic background compilation

  • Non-blocking

ctags.img

Requires Universal CTags, NOT ctags

# MacOS
brew uninstall ctags           # bad
brew install   universal-ctags # good

# Ubuntu
apt remove  ctags              # bad
apt install universal-ctags    # good

Paths

  • Preview contents

  • $VARIABLE expansion, %EVEN_UNDER_WINDOWS%

  • Relative to both cwd and file path

paths.img

Buffers

  • Real time completion

  • Fast in files with thousands of lines

buffers.img

Registers

  • words Last yank 0 + custom a-z coq_settings.clients.registers.words

  • lines coq_settings.clients.registers.lines (a-z)

Tmux

tmux.img

Tabnine

  • CPU preserving flow control

  • Auto download & install & update

  • Platform specific cgroupv2 & taskpolicy core pinning / CPU management.

tabnine.img

T9 is disabled by default, I might remove it, if they do not improve the CPU usage. Their own bug tracker.

Enable via: coq_settings.clients.tabnine.enabled=true

Modular lua sources & external third party integrations

repl.img

Shown above: shell repl.

Some other built-ins:

Statistics

:COQstats

statistics.img

Validating config parser

  • Prevents typos & type errors in your config

Here I make a type error on purpose inputting string instead of an integer.

conf_demo.img

Pretty

pretty.gif

If you can't see icons properly:

Either set let g:coq_settings = { 'display.icons.mode': 'none' } to disable icons, or install a supported font

Install

Windows requires symlinks support in git.

git config --global core.symlinks true

Needs python virtual env

apt install --yes -- python3-venv

Minimum version: python:3.8.2, nvim: 0.5, sqlite: recentish

Vim

Install the usual way, ie. VimPlug, Vundle, etc

" main one
Plug 'ms-jpq/coq_nvim', {'branch': 'coq'}
" 9000+ Snippets
Plug 'ms-jpq/coq.artifacts', {'branch': 'artifacts'}

" lua & third party sources -- See https://github.com/ms-jpq/coq.thirdparty
" Need to **configure separately**

Plug 'ms-jpq/coq.thirdparty', {'branch': '3p'}
" - shell repl
" - nvim lua api
" - scientific calculator
" - comment banner
" - etc
Neovim

lazy.nvim

{
  "neovim/nvim-lspconfig", -- REQUIRED: for native Neovim LSP integration
  lazy = false, -- REQUIRED: tell lazy.nvim to start this plugin at startup
  dependencies = {
    -- main one
    { "ms-jpq/coq_nvim", branch = "coq" },

    -- 9000+ Snippets
    { "ms-jpq/coq.artifacts", branch = "artifacts" },

    -- lua & third party sources -- See https://github.com/ms-jpq/coq.thirdparty
    -- Need to **configure separately**
    { 'ms-jpq/coq.thirdparty', branch = "3p" }
    -- - shell repl
    -- - nvim lua api
    -- - scientific calculator
    -- - comment banner
    -- - etc
  },
  init = function()
    vim.g.coq_settings = {
        auto_start = true, -- if you want to start COQ at startup
        -- Your COQ settings here
    }
  end,
  config = function()
    -- Your LSP settings here
  end,
}

Documentation

To start coq

" the [-s, --shut-up] flag will remove the greeting message
:COQnow [--shut-up]

🌟 If required, it will ask you to run :COQdeps, please run it and do :COQnow again.

There is built-in help command

:COQhelp [--web] [topic]

FAQ

Default hotkeys?

Always:

keyfunction
<c-space>manual completion
<c-h>edit snippet placeholder

When completion menu is open:

keyfunction
<c-k>move preview to bigger window
<esc>exit to normal
<backspace>backspace
<enter>select completion
<tab>next result
<s-tab>prev result

Unbound:

keymapfunction
coq_settings.keymap.repeatrepeat last edit
coq_settings.keymap.eval_snipsevulate snippet in document / under selection

When hovering over a result, entering any key [a-z] will select it

This is a vim thing, I have zero control over :(

. Repeat

Set coq_settings.keymap.repeat to a hotkey.

See :COQhelp keybind for details

Flickering

By default, the old results are cleared on each keystroke, so the popup menu is closed right away.

You can disable this: at the cost of having stale results shown until the new ones come in.

let g:coq_settings = { 'display.pum.fast_close': v:false }

This is not the default because some LSP servers are very slow (ie. tailwindcss), leading to stale results being shown for too long.

Autostart COQ

let g:coq_settings = { 'auto_start': v:true } or let g:coq_settings = { 'auto_start': 'shut-up' }

This must be set BEFORE require("coq")

LSP too slow to show up on keystroke.

You have some options, each has its trade off:

  1. Increase the coq_settings.limits.completion_auto_timeout.

This will slow down feedback on every keystroke, as coq waits for LSP.

  1. Use the manual completion hotkey (default <c-space>)

Annoying! And the manual completion also has a timeout coq_settings.limits.completion_manual_timeout.

Some LSP servers will still fail to respond within the default .66 seconds, in that case pressing <c-space> multiple times might actually help some LSP servers catch up, depending on their implementation.

LSP sometimes not importing

Increase coq_settings.clients.lsp.resolve_timeout

This will however, make applying edits slower.

Missing Results

On keystroke only a max of coq_settings.match.max_results are shown.

Use manual completion hotkey to show all results.

Some LSP servers give inconsistent completions

This happens when certain LSP servers give you 1000s of unfiltered results in alphabetical order and you still have to respond in a few dozen milliseconds.

To eliminate a-z bias, coq does a random sort on the resultset and process and cache as many of them as possible within the performance window.

So if some results are not in the SQLite cache, and have yet to be processed, they will be missing. They might however still show up on later keystrokes.

Use the manual hotkey if you need to see everything.

My vim crashed!

Disable TreeSitter

Treesitter still needs stability work.

I want to use a different python version

vim.g.python3_host_prog=<absolute path to python>

If you like this...

Also check out

  • sad, it's a modern sed that does previews with syntax highlighting, and lets you pick and choose which chunks to edit.

  • CHADTree, it's a FULLY featured file manager.

  • isomorphic-copy, it's a cross platform clipboard that is daemonless, and does not require third party support.

Special Thanks & Acknowledgements

The snippets are compiled from the following open source projects:

Super special thanks goes to Typescript LSP.

Nothing like good motivation to improve my design than dumping 1000 results on my client every other keystroke.