LSP based intellisense engine for neovim & vim8 that transforms your editor into a VSCode-like development environment. coc.nvim provides comprehensive Language Server Protocol support, intelligent completion, diagnostics, code actions, navigation, and an extensive extension ecosystem.
Plug 'neoclide/coc.nvim', {'branch': 'release'}Plugin is automatically loaded after installation. Core functionality is accessed through:
" Global functions available after plugin load
CocAction({action} [, ...args])
CocActionAsync({action} [, ...args] [, {callback}])
CocHasProvider({feature})
" Autoload functions (called automatically or explicitly)
coc#start([{option}])
coc#refresh()
coc#status()" Basic setup in .vimrc or init.vim
" Set updatetime for better experience
set updatetime=300
" Always show signcolumn
set signcolumn=yes
" Use tab for completion navigation
inoremap <silent><expr> <TAB>
\ coc#pum#visible() ? coc#pum#next(1) :
\ CheckBackspace() ? "\<Tab>" :
\ coc#refresh()
inoremap <expr><S-TAB> coc#pum#visible() ? coc#pum#prev(1) : "\<C-h>"
function! CheckBackspace() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~# '\s'
endfunction
" Use <CR> to confirm completion
inoremap <silent><expr> <CR> coc#pum#visible() ? coc#pum#confirm()
\: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"
" Basic key mappings
nmap <silent> gd <Plug>(coc-definition)
nmap <silent> gy <Plug>(coc-type-definition)
nmap <silent> gi <Plug>(coc-implementation)
nmap <silent> gr <Plug>(coc-references)
" Install extensions
:CocInstall coc-json coc-tsserver coc-python
" Configure language servers in coc-settings.json
:CocConfigcoc.nvim uses a multi-process architecture with several key components:
The plugin bridges Vim's interface with modern LSP servers through efficient IPC communication, providing real-time code intelligence without blocking the editor.
Core service lifecycle management including starting, stopping, restarting the coc.nvim service, and checking service status. Essential for maintaining the LSP connection and troubleshooting.
" Commands
:CocStart " Start the coc service
:CocRestart " Restart the coc service
:CocDisable " Disable coc temporarily
:CocEnable " Re-enable coc
:CocInfo " Show service information
" Functions
CocAction({action} [, ...args]) " Execute synchronous action
CocActionAsync({action} [, ...args]) " Execute asynchronous actionIntelligent code completion with LSP integration, snippet support, and customizable completion behavior. Provides VSCode-like completion experience with automatic triggering and context-aware suggestions.
" Functions
coc#start([{option}]) " Start completion manually
coc#refresh() " Refresh completion
coc#expandable() " Check if snippet expandable
coc#jumpable() " Check if snippet jumpable
coc#pum#visible() " Check if popup menu visible
coc#pum#next({insert}) " Select next completion item
coc#pum#prev({insert}) " Select previous completion itemReal-time error detection, warning display, and diagnostic navigation. Integrates with language servers to provide immediate feedback on code issues with customizable display options.
" Commands
:CocDiagnostics [height] " Open diagnostics in location list
" Key mappings
<Plug>(coc-diagnostic-info) " Show diagnostic info
<Plug>(coc-diagnostic-next) " Jump to next diagnostic
<Plug>(coc-diagnostic-prev) " Jump to previous diagnostic
<Plug>(coc-diagnostic-next-error) " Jump to next error
<Plug>(coc-diagnostic-prev-error) " Jump to previous errorLSP-powered navigation including go-to-definition, find references, type definitions, and implementations. Provides semantic code understanding for efficient codebase exploration.
" Key mappings
<Plug>(coc-definition) " Jump to definition
<Plug>(coc-declaration) " Jump to declaration
<Plug>(coc-implementation) " Jump to implementation
<Plug>(coc-type-definition) " Jump to type definition
<Plug>(coc-references) " Find references
<Plug>(coc-references-used) " Find used references
" Functions
CocLocations({id}, {method} [, {params}]) " Get locations from LSP
CocLocationsAsync({id}, {method} [, {params}]) " Get locations asyncCode refactoring, formatting, renaming, and automated fixes. Integrates with language servers to provide context-aware code transformations and style formatting.
" Key mappings
<Plug>(coc-codeaction) " Trigger code actions
<Plug>(coc-codeaction-line) " Code actions for line
<Plug>(coc-codeaction-selected) " Code actions for selection
<Plug>(coc-format) " Format document
<Plug>(coc-format-selected) " Format selection
<Plug>(coc-rename) " Rename symbol
<Plug>(coc-fix-current) " Quick fix current issue
<Plug>(coc-refactor) " Trigger refactoringInstalling, updating, and managing coc.nvim extensions. Provides NPM-based extension ecosystem with automatic dependency management and VSCode extension compatibility.
" Commands
:CocInstall [{option}] {name} ... " Install extensions
:CocUninstall {name} " Uninstall extension
:CocUpdate " Update all extensions
:CocUpdateSync " Update extensions synchronously
:CocRebuild " Rebuild extensions
" Variables
g:coc_global_extensions " List of global extensionsJSON-based configuration system compatible with VSCode settings. Supports both global and workspace-specific configurations with live reloading and schema validation.
" Commands
:CocConfig " Edit global config
:CocLocalConfig " Edit workspace config
" Functions
coc#config({section}, {value}) " Change configuration programmatically
" Variables
g:coc_user_config " User configuration dictionaryFuzzy finder and list interface for files, buffers, symbols, and more. Provides unified interface for various data sources with filtering, sorting, and preview capabilities.
" Commands
:CocList [{options}] " Open list interface
:CocListResume [{name}] " Resume list
:CocListCancel [{name}] " Cancel list
:CocPrev [{name}] " Go to previous item
:CocNext [{name}] " Go to next item
:CocFirst [{name}] " Go to first item
:CocLast [{name}] " Go to last itemModern floating window interface for documentation, completion details, and other informational displays. Provides non-intrusive overlay windows with rich content rendering.
" Key mappings
<Plug>(coc-float-hide) " Hide floating windows
<Plug>(coc-float-jump) " Jump to floating window
" Functions
coc#float#has_float([{winid}]) " Check if float window exists
coc#float#close_all([{exclude}]) " Close all float windows
coc#float#jump() " Jump to float window
coc#float#scroll({forward}) " Scroll float window" Core configuration
g:coc_enabled " Enable/disable coc (default: 1)
g:coc_start_at_startup " Start at Vim startup (default: 1)
g:coc_disable_startup_warning " Disable startup warnings (default: 0)
g:coc_node_path " Custom Node.js path (default: 'node')
" Extension configuration
g:coc_global_extensions " Global extensions to install (default: [])
g:coc_user_config " User configuration dictionary (default: {})
" Service state
g:coc_service_initialized " Service initialization status
g:coc_selected_text " Currently selected text
g:coc_vim_leaving " Set during Vim exit process
g:coc_workspace_initialized " Workspace initialization status" Configuration types (JSON format in coc-settings.json)
{
"suggest.autoTrigger": "always" | "none" | "trigger",
"suggest.selection": "recentlyUsed" | "none" | "recentlyUsedByPrefix",
"diagnostic.enable": boolean,
"languageserver": {
"{server-name}": {
"command": string,
"args": string[],
"filetypes": string[],
"rootPatterns": string[],
"settings": {}
}
}
}