# nvim-cmp — Completion Engine for Neovim Written in Lua > Auto-completion plugin for Neovim supporting LSP, buffer, path, and snippet sources. ## Install Save as a script file and run: # nvim-cmp — Completion Engine for Neovim Written in Lua ## Quick Use Install via lazy.nvim: `{ "hrsh7th/nvim-cmp" }` along with source plugins such as `cmp-nvim-lsp`, `cmp-buffer`, `cmp-path`, and a snippet engine like LuaSnip. Call `cmp.setup({})` in your Neovim config to activate. ## Introduction nvim-cmp is a completion engine for Neovim written entirely in Lua. It provides a flexible, extensible framework for autocompletion that integrates with Neovim's built-in LSP client and supports a wide range of completion sources through a plugin architecture. The repository is hrsh7th/nvim-cmp on GitHub with approximately 9,472 stars. ## What nvim-cmp Does nvim-cmp collects completion candidates from multiple configurable sources—LSP servers, buffer words, file paths, snippets—and presents them in a unified popup menu. Users can navigate, filter, and confirm completions with customizable key mappings. The plugin handles fuzzy matching, sorting, and deduplication of candidates across sources. ## Architecture Overview The core engine manages the completion pipeline: triggering, source collection, filtering, sorting, and rendering. Each completion source is a separate plugin that implements a simple interface. The matching system supports fuzzy, substring, and exact modes. A formatting layer lets users customize how each candidate appears in the menu. The snippet integration layer connects with engines like LuaSnip or vsnip for expand-and-jump behavior. ## Self-Hosting & Configuration nvim-cmp runs locally inside Neovim. Install the core plugin and desired source plugins via your package manager. Configuration is done through `cmp.setup()` in Lua, where you specify sources, mappings, snippet expansion, formatting, and sorting. Separate `cmp.setup.cmdline()` calls configure command-line completion. No external servers or services are required. ## Key Features - Extensible source plugin system (LSP, buffer, path, snippets, cmdline) - Fuzzy matching with configurable sorting and filtering - Custom formatting for completion menu items - Ghost text preview of selected completions - Native LSP integration via cmp-nvim-lsp - Snippet expand-and-jump support through multiple engines - Command-line completion for search and Ex commands ## Comparison with Similar Tools Compared to coc.nvim, nvim-cmp is Lua-native and does not require Node.js, resulting in lower overhead. Unlike Neovim's built-in omnifunc, nvim-cmp provides asynchronous multi-source completion with a richer UI. coq_nvim offers a similar Lua-based approach but uses a SQLite backend for matching, while nvim-cmp relies on in-memory filtering. nvim-cmp's modular source system makes it straightforward to add or remove completion providers. ## FAQ **Q: Does nvim-cmp require an LSP server?** A: No. LSP is one source among many. You can use buffer, path, or snippet sources without any LSP server configured. **Q: How do I add snippet support?** A: Install a snippet engine plugin (e.g., LuaSnip) and its corresponding cmp source (cmp_luasnip), then configure the snippet.expand function in cmp.setup. **Q: Can I use nvim-cmp for command-line completion?** A: Yes. Use cmp.setup.cmdline() with the cmp-cmdline source to get completion in Neovim's command line. ## Sources - GitHub repository: https://github.com/hrsh7th/nvim-cmp - Wiki and documentation: https://github.com/hrsh7th/nvim-cmp/wiki --- Source: https://tokrepo.com/en/workflows/asset-19121dab Author: Script Depot