Top Related Projects
Fast as FUCK nvim completion. SQLite, concurrent scheduler, hundreds of hours of optimization.
Nodejs extension host for vim & neovim, load extensions like VSCode and host language servers.
:stars: Dark powered asynchronous completion framework for neovim/Vim8
async language server protocol plugin for vim and neovim
Quickstart configs for Nvim LSP
A code-completion engine for Vim
Quick Overview
nvim-cmp is a completion plugin for Neovim, written in Lua. It provides a highly extensible and performant completion engine with support for various sources, including LSP, snippets, and buffer words.
Pros
- Highly customizable with a wide range of configuration options
- Fast and efficient completion engine
- Supports multiple completion sources out of the box
- Integrates well with other Neovim plugins and LSP clients
Cons
- Requires some initial setup and configuration
- May have a steeper learning curve for beginners
- Occasional compatibility issues with certain language servers or plugins
- Performance can degrade with a large number of completion sources enabled
Code Examples
- Basic setup with LSP and luasnip:
local cmp = require('cmp')
cmp.setup({
snippet = {
expand = function(args)
require('luasnip').lsp_expand(args.body)
end,
},
sources = cmp.config.sources({
{ name = 'nvim_lsp' },
{ name = 'luasnip' },
}, {
{ name = 'buffer' },
})
})
- Custom mapping for completion:
cmp.setup({
mapping = cmp.mapping.preset.insert({
['<C-b>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4),
['<C-Space>'] = cmp.mapping.complete(),
['<C-e>'] = cmp.mapping.abort(),
['<CR>'] = cmp.mapping.confirm({ select = true }),
}),
})
- Configuring completion menu appearance:
cmp.setup({
window = {
completion = cmp.config.window.bordered(),
documentation = cmp.config.window.bordered(),
},
formatting = {
fields = { "kind", "abbr", "menu" },
format = function(entry, vim_item)
vim_item.menu = ({
nvim_lsp = "[LSP]",
luasnip = "[Snippet]",
buffer = "[Buffer]",
})[entry.source.name]
return vim_item
end,
},
})
Getting Started
To get started with nvim-cmp, follow these steps:
- Install nvim-cmp and its dependencies using your preferred plugin manager.
- Add the following basic configuration to your Neovim config file:
require('cmp').setup({
sources = {
{ name = 'nvim_lsp' },
{ name = 'buffer' },
},
mapping = require('cmp').mapping.preset.insert({
['<C-b>'] = require('cmp').mapping.scroll_docs(-4),
['<C-f>'] = require('cmp').mapping.scroll_docs(4),
['<C-Space>'] = require('cmp').mapping.complete(),
['<C-e>'] = require('cmp').mapping.abort(),
['<CR>'] = require('cmp').mapping.confirm({ select = true }),
}),
})
- Configure your LSP client to work with nvim-cmp (if using LSP completion).
- Customize the setup further based on your preferences and needs.
Competitor Comparisons
Fast as FUCK nvim completion. SQLite, concurrent scheduler, hundreds of hours of optimization.
Pros of coq_nvim
- Faster completion due to native implementation in Python
- More extensive fuzzy matching capabilities
- Built-in snippets engine with LSP integration
Cons of coq_nvim
- Steeper learning curve and more complex configuration
- Less community support and fewer extensions compared to nvim-cmp
- May have compatibility issues with some Neovim plugins
Code Comparison
coq_nvim configuration:
vim.g.coq_settings = {
auto_start = 'shut-up',
keymap = { recommended = false },
clients = { tabnine = { enabled = true } }
}
nvim-cmp configuration:
require('cmp').setup({
sources = {{ name = 'nvim_lsp' }, { name = 'buffer' }},
mapping = cmp.mapping.preset.insert({
['<C-b>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4),
}),
})
Both nvim-cmp and coq_nvim are popular autocompletion plugins for Neovim. nvim-cmp offers a more modular approach with extensive customization options and broader plugin ecosystem support. coq_nvim, on the other hand, provides faster completion and more advanced fuzzy matching out of the box. The choice between them depends on individual preferences for speed, customization, and integration with other Neovim plugins.
Nodejs extension host for vim & neovim, load extensions like VSCode and host language servers.
Pros of coc.nvim
- More mature and stable project with a larger user base
- Extensive language server protocol (LSP) support out of the box
- Easier setup for beginners with pre-configured language servers
Cons of coc.nvim
- Heavier resource usage due to Node.js dependency
- Slower startup time compared to nvim-cmp
- Less customizable and modular than nvim-cmp
Code Comparison
coc.nvim configuration:
vim.g.coc_global_extensions = {
'coc-json',
'coc-tsserver',
'coc-eslint',
'coc-prettier'
}
nvim-cmp configuration:
require('nvim-cmp').setup({
sources = {
{ name = 'nvim_lsp' },
{ name = 'buffer' },
{ name = 'path' }
}
})
coc.nvim offers a more straightforward setup with global extensions, while nvim-cmp provides a more modular approach with customizable sources. nvim-cmp requires additional setup for LSP integration, but offers greater flexibility in configuration.
Both plugins provide excellent autocompletion capabilities, but coc.nvim is more beginner-friendly with its pre-configured language servers, while nvim-cmp offers better performance and customization options for advanced users.
:stars: Dark powered asynchronous completion framework for neovim/Vim8
Pros of deoplete.nvim
- Mature and stable project with a long history of development
- Extensive plugin ecosystem and community support
- Supports both Vim and Neovim
Cons of deoplete.nvim
- Written in Python, which can lead to slower performance compared to Lua-based alternatives
- Less active development and updates in recent years
- Configuration can be more complex for advanced setups
Code Comparison
deoplete.nvim configuration:
call deoplete#custom#option('sources', {
\ '_': ['buffer', 'file'],
\ 'cpp': ['buffer', 'tag', 'file']
\})
nvim-cmp configuration:
require('cmp').setup({
sources = {
{ name = 'buffer' },
{ name = 'path' },
{ name = 'nvim_lsp' },
},
})
Both plugins offer powerful completion capabilities, but nvim-cmp is generally considered more modern and performant due to its Lua implementation. It also integrates more seamlessly with Neovim's built-in LSP client. However, deoplete.nvim still has a strong user base and may be preferred by those who need Vim compatibility or are already familiar with its ecosystem.
async language server protocol plugin for vim and neovim
Pros of vim-lsp
- Supports both Vim and Neovim, offering broader compatibility
- Lightweight and focused solely on LSP integration
- Easier setup for users familiar with traditional Vim plugin architecture
Cons of vim-lsp
- Less extensive completion features compared to nvim-cmp
- Slower development cycle and fewer updates
- Limited extensibility for advanced customization
Code Comparison
vim-lsp configuration:
let g:lsp_diagnostics_enabled = 1
let g:lsp_signs_enabled = 1
let g:lsp_diagnostics_echo_cursor = 1
nvim-cmp configuration:
require('cmp').setup({
sources = {
{ name = 'nvim_lsp' },
{ name = 'buffer' },
},
})
vim-lsp focuses on LSP integration, while nvim-cmp provides a more comprehensive completion framework. vim-lsp uses Vimscript for configuration, making it more accessible to traditional Vim users. nvim-cmp, written in Lua, offers more advanced features and better performance, but requires Neovim.
vim-lsp is a solid choice for users who want basic LSP functionality across both Vim and Neovim. nvim-cmp is better suited for Neovim users seeking a powerful, extensible completion engine with broader language support and more frequent updates.
Quickstart configs for Nvim LSP
Pros of nvim-lspconfig
- Provides out-of-the-box configurations for numerous language servers
- Simplifies the setup process for LSP in Neovim
- Maintained by the Neovim team, ensuring compatibility and regular updates
Cons of nvim-lspconfig
- Focused solely on LSP configuration, lacking advanced completion features
- Requires additional plugins for a full completion experience
- May have a steeper learning curve for users new to LSP concepts
Code Comparison
nvim-lspconfig:
require'lspconfig'.pyright.setup{}
nvim-cmp:
local cmp = require'cmp'
cmp.setup({
sources = {{ name = 'nvim_lsp' }}
})
Summary
nvim-lspconfig is a powerful tool for configuring language servers in Neovim, offering pre-configured setups for many languages. It's maintained by the Neovim team, ensuring compatibility and updates. However, it focuses solely on LSP configuration and lacks advanced completion features.
nvim-cmp, on the other hand, is a completion engine that provides a more comprehensive solution for code completion. It offers a wider range of completion sources and more customization options. While it requires more setup, it provides a more feature-rich completion experience.
The choice between the two depends on your specific needs: nvim-lspconfig for straightforward LSP setup, or nvim-cmp for a more advanced completion system.
A code-completion engine for Vim
Pros of YouCompleteMe
- More mature and established project with a longer history
- Supports a wider range of programming languages out of the box
- Offers semantic completion for C-family languages using clangd
Cons of YouCompleteMe
- Requires compilation and external dependencies, making installation more complex
- Less flexible and harder to customize compared to nvim-cmp
- Heavier resource usage, which may impact performance on older systems
Code Comparison
YouCompleteMe configuration:
let g:ycm_auto_trigger = 1
let g:ycm_min_num_of_chars_for_completion = 2
let g:ycm_complete_in_comments = 1
nvim-cmp configuration:
require('cmp').setup({
sources = {
{ name = 'nvim_lsp' },
{ name = 'buffer' },
},
mapping = {
['<C-Space>'] = cmp.mapping.complete(),
},
})
YouCompleteMe provides a more straightforward configuration in Vimscript, while nvim-cmp offers a more modular and extensible setup using Lua. nvim-cmp allows for easier customization of completion sources and keybindings, making it more flexible for advanced users.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
nvim-cmp
A completion engine plugin for neovim written in Lua. Completion sources are installed from external repositories and "sourced".
https://github.com/hrsh7th/nvim-cmp/assets/22756295/afa70011-9121-4e42-aedd-0153b630eeab
Readme!
- There is a GitHub issue that documents breaking changes for nvim-cmp. Subscribe to the issue to be notified of upcoming breaking changes.
- This is my hobby project. You can support me via GitHub sponsors.
- Bug reports are welcome, but don't expect a fix unless you provide minimal configuration and steps to reproduce your issue.
- The
cmp.mapping.preset.*
is pre-defined configuration that aims to mimic neovim's native like behavior. It can be changed without announcement. Please manage key-mapping by yourself.
Concept
- Full support for LSP completion related capabilities
- Powerful customizability via Lua functions
- Smart handling of key mappings
- No flicker
Setup
Recommended Configuration
This example configuration uses vim-plug
as the plugin manager and vim-vsnip
as a snippet plugin.
call plug#begin(s:plug_dir)
Plug 'neovim/nvim-lspconfig'
Plug 'hrsh7th/cmp-nvim-lsp'
Plug 'hrsh7th/cmp-buffer'
Plug 'hrsh7th/cmp-path'
Plug 'hrsh7th/cmp-cmdline'
Plug 'hrsh7th/nvim-cmp'
" For vsnip users.
Plug 'hrsh7th/cmp-vsnip'
Plug 'hrsh7th/vim-vsnip'
" For luasnip users.
" Plug 'L3MON4D3/LuaSnip'
" Plug 'saadparwaiz1/cmp_luasnip'
" For ultisnips users.
" Plug 'SirVer/ultisnips'
" Plug 'quangnguyen30192/cmp-nvim-ultisnips'
" For snippy users.
" Plug 'dcampos/nvim-snippy'
" Plug 'dcampos/cmp-snippy'
call plug#end()
lua <<EOF
-- Set up nvim-cmp.
local cmp = require'cmp'
cmp.setup({
snippet = {
-- REQUIRED - you must specify a snippet engine
expand = function(args)
vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users.
-- require('luasnip').lsp_expand(args.body) -- For `luasnip` users.
-- require('snippy').expand_snippet(args.body) -- For `snippy` users.
-- vim.fn["UltiSnips#Anon"](args.body) -- For `ultisnips` users.
-- vim.snippet.expand(args.body) -- For native neovim snippets (Neovim v0.10+)
end,
},
window = {
-- completion = cmp.config.window.bordered(),
-- documentation = cmp.config.window.bordered(),
},
mapping = cmp.mapping.preset.insert({
['<C-b>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4),
['<C-Space>'] = cmp.mapping.complete(),
['<C-e>'] = cmp.mapping.abort(),
['<CR>'] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
}),
sources = cmp.config.sources({
{ name = 'nvim_lsp' },
{ name = 'vsnip' }, -- For vsnip users.
-- { name = 'luasnip' }, -- For luasnip users.
-- { name = 'ultisnips' }, -- For ultisnips users.
-- { name = 'snippy' }, -- For snippy users.
}, {
{ name = 'buffer' },
})
})
-- To use git you need to install the plugin petertriho/cmp-git and uncomment lines below
-- Set configuration for specific filetype.
--[[ cmp.setup.filetype('gitcommit', {
sources = cmp.config.sources({
{ name = 'git' },
}, {
{ name = 'buffer' },
})
})
require("cmp_git").setup() ]]--
-- Use buffer source for `/` and `?` (if you enabled `native_menu`, this won't work anymore).
cmp.setup.cmdline({ '/', '?' }, {
mapping = cmp.mapping.preset.cmdline(),
sources = {
{ name = 'buffer' }
}
})
-- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore).
cmp.setup.cmdline(':', {
mapping = cmp.mapping.preset.cmdline(),
sources = cmp.config.sources({
{ name = 'path' }
}, {
{ name = 'cmdline' }
}),
matching = { disallow_symbol_nonprefix_matching = false }
})
-- Set up lspconfig.
local capabilities = require('cmp_nvim_lsp').default_capabilities()
-- Replace <YOUR_LSP_SERVER> with each lsp server you've enabled.
require('lspconfig')['<YOUR_LSP_SERVER>'].setup {
capabilities = capabilities
}
EOF
Where can I find more completion sources?
Have a look at the Wiki and the nvim-cmp
GitHub topic.
Where can I find advanced configuration examples?
See the Wiki.
Top Related Projects
Fast as FUCK nvim completion. SQLite, concurrent scheduler, hundreds of hours of optimization.
Nodejs extension host for vim & neovim, load extensions like VSCode and host language servers.
:stars: Dark powered asynchronous completion framework for neovim/Vim8
async language server protocol plugin for vim and neovim
Quickstart configs for Nvim LSP
A code-completion engine for Vim
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot