tessl install tessl/npm-coc-nvim@0.0.0LSP based intellisense engine for neovim & vim8.
Complexity: Intermediate | Category: Reference | Keywords: variables, config, state, global, buffer
Common Tasks: Configure startup | Customize UI | Set buffer options | Check service state
Complete reference for all configuration and state variables in coc.nvim. These variables control behavior, appearance, and provide runtime state information.
autocmd FileType markdown let b:coc_enabled = 0Prevents coc.nvim from activating in markdown files.
let g:coc_global_extensions = ['coc-json', 'coc-tsserver']Extensions will be automatically installed on startup.
let g:coc_status_error_sign = '✗'
let g:coc_status_warning_sign = '⚠'Changes error and warning signs in statusline.
let g:coc_node_args = ['--max-old-space-size=8192']Allocates more memory to Node.js process for large projects.
if get(g:, 'coc_service_initialized', 0)
echo 'Coc is ready'
endifVerifies coc.nvim has finished initializing.
let g:coc_start_at_startup = 1Start coc.nvim service automatically when Vim starts.
Type: Number
Default: 1
Values: 1 (enabled), 0 (disabled)
Example:
" Disable auto-start for faster Vim startup
let g:coc_start_at_startup = 0
" Start manually with :CocStart when neededlet g:coc_global_extensions = []List of extensions to auto-install on startup.
Type: List
Default: []
Example:
let g:coc_global_extensions = [
\ 'coc-json',
\ 'coc-tsserver',
\ 'coc-eslint',
\ 'coc-prettier',
\ 'coc-python'
\ ]let g:coc_user_config = {}Configuration overrides applied on top of coc-settings.json.
Type: Dictionary
Default: {}
Example:
let g:coc_user_config = {
\ 'suggest.noselect': v:true,
\ 'diagnostic.errorSign': '✗',
\ 'diagnostic.warningSign': '⚠',
\ 'suggest.timeout': 500
\ }let g:node_client_debug = 0Enable debug mode for Node.js client.
Type: Number
Default: 0
Values: 1 (enabled), 0 (disabled)
Example:
" Enable for debugging service issues
let g:node_client_debug = 1
" Check :messages for debug outputlet g:coc_config_home = '/path/to/config'Override configuration directory location.
Type: String Default: Auto-detected from standard locations
Example:
" Use custom config location
let g:coc_config_home = expand('~/.config/nvim/coc')let g:coc_data_home = '/path/to/data'Override data directory location.
Type: String Default: Auto-detected from standard locations
Example:
" Use custom data location
let g:coc_data_home = expand('~/.local/share/coc')let g:coc_node_path = '/path/to/node'Path to Node.js executable.
Type: String
Default: 'node'
Example:
" Use specific Node.js version
let g:coc_node_path = '/usr/local/bin/node'
" Or use nvm
let g:coc_node_path = expand('~/.nvm/versions/node/v16.0.0/bin/node')let g:coc_node_args = []Additional arguments for Node.js process.
Type: List
Default: []
Example:
" Increase memory for large projects
let g:coc_node_args = ['--max-old-space-size=8192']
" Enable Node inspector
let g:coc_node_args = ['--inspect']let g:coc_filetype_map = {}Map Vim filetypes to language identifiers.
Type: Dictionary
Default: {}
Example:
let g:coc_filetype_map = {
\ 'yaml.ansible': 'ansible',
\ 'javascript.jsx': 'javascriptreact',
\ 'typescript.tsx': 'typescriptreact',
\ 'markdown.mdx': 'mdx'
\ }let g:coc_uri_prefix_replace_patterns = {}URI prefix replacement patterns for remote development.
Type: Dictionary
Default: {}
Example:
" Map remote paths to local paths
let g:coc_uri_prefix_replace_patterns = {
\ 'file:///remote/project/': 'file:///home/user/project/'
\ }let g:coc_enable_locationlist = 1Use location list for jump operations.
Type: Number
Default: 1
Example:
" Disable location list, use quickfix instead
let g:coc_enable_locationlist = 0let g:coc_snippet_next = '<C-j>'Key for jumping to next snippet placeholder.
Type: String
Default: '<C-j>'
Example:
" Use Tab to jump to next placeholder
let g:coc_snippet_next = '<Tab>'let g:coc_snippet_prev = '<C-k>'Key for jumping to previous snippet placeholder.
Type: String
Default: '<C-k>'
Example:
" Use Shift-Tab to jump to previous placeholder
let g:coc_snippet_prev = '<S-Tab>'let g:coc_selectmode_mapping = 1Enable select mode mappings for snippets.
Type: Number
Default: 1
Example:
" Disable if conflicts with other plugins
let g:coc_selectmode_mapping = 0let g:coc_status_error_sign = 'E'Error sign for statusline.
Type: String
Default: 'E'
Example:
let g:coc_status_error_sign = '✗'
let g:coc_status_error_sign = ''let g:coc_status_warning_sign = 'W'Warning sign for statusline.
Type: String
Default: 'W'
Example:
let g:coc_status_warning_sign = '⚠'
let g:coc_status_warning_sign = ''let g:coc_borderchars = ['─', '│', '─', '│', '┌', '┐', '┘', '└']Border characters for floating windows.
Type: List of 8 strings Default: Unicode box-drawing characters
Example:
" ASCII borders
let g:coc_borderchars = ['-', '|', '-', '|', '+', '+', '+', '+']
" Rounded borders
let g:coc_borderchars = ['─', '│', '─', '│', '╭', '╮', '╯', '╰']let g:coc_border_joinchars = ['┬', '┤', '┴', '├']Border join characters for complex layouts.
Type: List of 4 strings Default: Unicode box-drawing join characters
Example:
" ASCII joins
let g:coc_border_joinchars = ['+', '+', '+', '+']let g:coc_quickfix_open_command = 'copen'Command to open quickfix window.
Type: String
Default: 'copen'
Example:
" Open quickfix in bottom 10 lines
let g:coc_quickfix_open_command = 'copen 10'
" Open in new tab
let g:coc_quickfix_open_command = 'tab copen'let g:coc_notify_error_icon = ''Error notification icon.
Type: String
Default: ''
Example:
let g:coc_notify_error_icon = '✗'
let g:coc_notify_error_icon = ''let g:coc_notify_warning_icon = '⚠'Warning notification icon.
Type: String
Default: '⚠'
Example:
let g:coc_notify_warning_icon = ''
let g:coc_notify_warning_icon = '!'let g:coc_notify_info_icon = ''Info notification icon.
Type: String
Default: ''
Example:
let g:coc_notify_info_icon = ''
let g:coc_notify_info_icon = 'ℹ'let g:coc_max_treeview_width = 40Maximum width for tree view windows.
Type: Number
Default: 40
Example:
" Wider tree views
let g:coc_max_treeview_width = 60let g:coc_prompt_win_width = 32Prompt window width.
Type: Number
Default: 32
Example:
" Wider prompts for longer text
let g:coc_prompt_win_width = 50let g:coc_terminal_height = 8Terminal window height in lines.
Type: Number
Default: 8
Example:
" Taller terminal window
let g:coc_terminal_height = 15let g:coc_markdown_disabled_languages = []Disabled languages in markdown code blocks.
Type: List
Default: []
Example:
" Disable syntax highlighting for specific languages
let g:coc_markdown_disabled_languages = ['vim', 'python']let g:coc_highlight_maximum_count = 100Maximum highlights before grouping.
Type: Number
Default: 100
Example:
" Increase for better highlighting in large files
let g:coc_highlight_maximum_count = 200let g:coc_default_semantic_highlight_groups = 1Create default semantic highlight groups.
Type: Number
Default: 1
Example:
" Disable if using custom semantic highlighting
let g:coc_default_semantic_highlight_groups = 0g:coc_service_initializedIndicates if coc.nvim service has initialized.
Type: Number (read-only)
Values: 1 when initialized, undefined otherwise
Example:
if get(g:, 'coc_service_initialized', 0)
echo 'Coc is ready'
else
echo 'Coc is starting...'
endifg:coc_process_pidCoc service process PID.
Type: Number (read-only)
Example:
let pid = get(g:, 'coc_process_pid', 0)
if pid > 0
echo 'Coc process: ' . pid
endifg:did_coc_loadedPlugin loaded flag.
Type: Number (read-only)
Example:
if exists('g:did_coc_loaded')
echo 'Coc plugin is loaded'
endifg:coc_statusStatus string for statusline integration.
Type: String (read-only)
Example:
" Add to statusline
set statusline+=%{get(g:,'coc_status','')}
" Or in airline/lightline
let g:airline_section_x = '%{get(g:,"coc_status","")}'g:coc_last_float_winLast created floating window ID.
Type: Number (read-only)
Example:
let winid = get(g:, 'coc_last_float_win', 0)
if winid > 0 && nvim_win_is_valid(winid)
echo 'Float window is open'
endifg:coc_last_hover_messageLast hover message displayed.
Type: String (read-only)
Example:
echo get(g:, 'coc_last_hover_message', 'No hover message')g:WorkspaceFoldersCurrent workspace folders.
Type: List (read-only)
Example:
let folders = get(g:, 'WorkspaceFolders', [])
echo 'Workspace folders: ' . join(folders, ', ')g:coc_jump_locationsLocations from last jump operation.
Type: List (read-only)
Example:
let locations = get(g:, 'coc_jump_locations', [])
echo 'Found ' . len(locations) . ' locations'g:coc_selected_textLast selected text in operations.
Type: String (read-only)
Example:
echo 'Last selection: ' . get(g:, 'coc_selected_text', '')g:coc_vim_commandsRegistered Vim commands from extensions.
Type: List (read-only)
Example:
let commands = get(g:, 'coc_vim_commands', [])
for cmd in commands
echo cmd
endforlet b:coc_enabled = 0Disable coc.nvim for buffer.
Type: Number
Default: 1
Example:
" Disable for specific filetypes
autocmd FileType markdown,text let b:coc_enabled = 0
" Disable for large files
autocmd BufReadPre * if line('$') > 10000 | let b:coc_enabled = 0 | endif
" Disable for remote files
autocmd BufReadPre * if expand('%:p') =~# '^scp:' | let b:coc_enabled = 0 | endiflet b:coc_suggest_disable = 1Disable completion for buffer.
Type: Number
Default: 0
Example:
" Disable completion in specific filetypes
autocmd FileType markdown,text let b:coc_suggest_disable = 1
" Toggle completion
function! ToggleCompletion()
let b:coc_suggest_disable = !get(b:, 'coc_suggest_disable', 0)
echo 'Completion: ' . (b:coc_suggest_disable ? 'OFF' : 'ON')
endfunction
nnoremap <leader>tc :call ToggleCompletion()<CR>let b:coc_diagnostic_disable = 1Disable diagnostics for buffer.
Type: Number
Default: 0
Example:
" Disable diagnostics for specific files
autocmd BufReadPre */generated/* let b:coc_diagnostic_disable = 1
" Toggle diagnostics
function! ToggleDiagnostics()
let b:coc_diagnostic_disable = !get(b:, 'coc_diagnostic_disable', 0)
call CocActionAsync('diagnosticRefresh')
echo 'Diagnostics: ' . (b:coc_diagnostic_disable ? 'OFF' : 'ON')
endfunction
nnoremap <leader>td :call ToggleDiagnostics()<CR>let b:coc_disabled_sources = []Disabled completion sources for buffer.
Type: List
Default: []
Example:
" Disable specific sources
let b:coc_disabled_sources = ['buffer', 'around']
" Disable sources in markdown
autocmd FileType markdown let b:coc_disabled_sources = ['buffer']let b:coc_suggest_blacklist = []Words that won't trigger completion.
Type: List
Default: []
Example:
" Don't complete common words
let b:coc_suggest_blacklist = ['TODO', 'FIXME', 'NOTE']
" Add issue tracker keywords
autocmd FileType gitcommit let b:coc_suggest_blacklist = ['#', 'closes', 'fixes']let b:coc_additional_keywords = []Additional keyword characters for completion.
Type: List
Default: []
Example:
" Include dash in CSS keywords
autocmd FileType css let b:coc_additional_keywords = ['-']
" Include dot in Python imports
autocmd FileType python let b:coc_additional_keywords = ['.']let b:coc_root_patterns = []Root patterns for buffer workspace.
Type: List
Example:
" Custom root patterns for JavaScript
autocmd FileType javascript,typescript let b:coc_root_patterns = [
\ 'package.json',
\ 'tsconfig.json',
\ 'jsconfig.json',
\ '.git'
\ ]
" Python root patterns
autocmd FileType python let b:coc_root_patterns = [
\ 'setup.py',
\ 'pyproject.toml',
\ 'requirements.txt',
\ '.git'
\ ]b:coc_diagnostic_infoDiagnostic counts for buffer.
Type: Dictionary (read-only)
Keys: error, warning, information, hint
Example:
let info = get(b:, 'coc_diagnostic_info', {})
echo 'Errors: ' . get(info, 'error', 0)
echo 'Warnings: ' . get(info, 'warning', 0)
" Use in statusline
function! DiagnosticStatus()
let info = get(b:, 'coc_diagnostic_info', {})
let msgs = []
if get(info, 'error', 0)
call add(msgs, 'E:' . info.error)
endif
if get(info, 'warning', 0)
call add(msgs, 'W:' . info.warning)
endif
return join(msgs, ' ')
endfunctionb:coc_current_functionCurrent function name containing cursor.
Type: String (read-only)
Example:
" Add to statusline
set statusline+=%{get(b:,'coc_current_function','')}
" Show in airline
let g:airline_section_c = '%{get(b:,"coc_current_function","")}'b:coc_snippet_activeSnippet session active flag.
Type: Number (read-only)
Example:
if get(b:, 'coc_snippet_active', 0)
echo 'In snippet mode'
endifb:coc_cursors_activatedMulti-cursor mode active flag.
Type: Number (read-only)
Example:
if get(b:, 'coc_cursors_activated', 0)
echo 'Multi-cursor active'
endiflet b:coc_trim_trailing_whitespace = 1Trim trailing whitespace on save.
Type: Number
Default: 0
Example:
" Enable for specific filetypes
autocmd FileType javascript,python let b:coc_trim_trailing_whitespace = 1let b:coc_trim_final_newlines = 1Trim final newlines on save.
Type: Number
Default: 0
Example:
" Enable for all files
autocmd BufWritePre * let b:coc_trim_final_newlines = 1Complete statusline function:
function! CocStatusline() abort
let status = get(g:, 'coc_status', '')
let info = get(b:, 'coc_diagnostic_info', {})
let func = get(b:, 'coc_current_function', '')
let msgs = []
" Add diagnostic counts
if get(info, 'error', 0)
call add(msgs, 'E:' . info.error)
endif
if get(info, 'warning', 0)
call add(msgs, 'W:' . info.warning)
endif
" Add current function
if !empty(func)
call add(msgs, func)
endif
" Add service status
if !empty(status)
call add(msgs, status)
endif
return join(msgs, ' ')
endfunction
set statusline=%f\ %{CocStatusline()}\ %=%l,%cSmart feature toggling based on context:
function! ConfigureCocForBuffer() abort
let ft = &filetype
let lines = line('$')
let size = getfsize(expand('%'))
" Disable for large files
if lines > 10000 || size > 1000000
let b:coc_enabled = 0
echo 'Coc disabled: file too large'
return
endif
" Disable completion in certain filetypes
if index(['markdown', 'text', 'help'], ft) >= 0
let b:coc_suggest_disable = 1
endif
" Custom root patterns
if index(['javascript', 'typescript'], ft) >= 0
let b:coc_root_patterns = ['package.json', 'tsconfig.json', '.git']
elseif ft ==# 'python'
let b:coc_root_patterns = ['setup.py', 'pyproject.toml', '.git']
endif
" Additional keywords for CSS
if ft ==# 'css' || ft ==# 'scss'
let b:coc_additional_keywords = ['-']
endif
endfunction
autocmd BufReadPost,FileType * call ConfigureCocForBuffer()Debug helper to inspect all coc variables:
function! InspectCocVars() abort
echo '=== Global Variables ==='
echo 'Service initialized: ' . get(g:, 'coc_service_initialized', 0)
echo 'Process PID: ' . get(g:, 'coc_process_pid', 0)
echo 'Status: ' . get(g:, 'coc_status', '')
echo 'Plugin loaded: ' . exists('g:did_coc_loaded')
echo '\n=== Buffer Variables ==='
echo 'Buffer: ' . bufnr('%') . ' (' . bufname('%') . ')'
echo 'Coc enabled: ' . get(b:, 'coc_enabled', 1)
echo 'Suggest disabled: ' . get(b:, 'coc_suggest_disable', 0)
echo 'Diagnostic disabled: ' . get(b:, 'coc_diagnostic_disable', 0)
echo 'Current function: ' . get(b:, 'coc_current_function', 'none')
echo 'Snippet active: ' . get(b:, 'coc_snippet_active', 0)
echo '\n=== Diagnostics ==='
let info = get(b:, 'coc_diagnostic_info', {})
echo 'Errors: ' . get(info, 'error', 0)
echo 'Warnings: ' . get(info, 'warning', 0)
echo 'Info: ' . get(info, 'information', 0)
echo 'Hints: ' . get(info, 'hint', 0)
echo '\n=== Configuration ==='
echo 'Global extensions: ' . join(get(g:, 'coc_global_extensions', []), ', ')
echo 'Node path: ' . get(g:, 'coc_node_path', 'default')
echo 'Config home: ' . get(g:, 'coc_config_home', 'default')
endfunction
command! CocVars call InspectCocVars()Per-project workspace detection:
function! SetProjectRoots() abort
let ft = &filetype
if ft ==# 'javascript' || ft ==# 'typescript'
let b:coc_root_patterns = [
\ 'package.json',
\ 'tsconfig.json',
\ 'jsconfig.json',
\ '.git'
\ ]
elseif ft ==# 'python'
let b:coc_root_patterns = [
\ 'setup.py',
\ 'pyproject.toml',
\ 'requirements.txt',
\ '.git'
\ ]
elseif ft ==# 'go'
let b:coc_root_patterns = [
\ 'go.mod',
\ '.git'
\ ]
elseif ft ==# 'rust'
let b:coc_root_patterns = [
\ 'Cargo.toml',
\ '.git'
\ ]
endif
endfunction
autocmd FileType * call SetProjectRoots()Check before using state variables:
function! SafeGetStatus() abort
if !get(g:, 'coc_service_initialized', 0)
return 'Coc starting...'
endif
return get(g:, 'coc_status', '')
endfunctionAlways provide defaults:
" Good - with default
let enabled = get(b:, 'coc_enabled', 1)
" Bad - may error if undefined
let enabled = b:coc_enabledValidate variable types:
function! SetGlobalExtensions(extensions) abort
if type(a:extensions) != v:t_list
echoerr 'extensions must be a list'
return
endif
let g:coc_global_extensions = a:extensions
endfunctionProblem: Setting variables doesn't change behavior.
Solutions:
Set variables before plugin loads:
" In .vimrc, BEFORE plugins load
let g:coc_global_extensions = ['coc-json']Restart service for config changes:
:CocRestartUse coc#config() for runtime changes:
call coc#config('suggest.noselect', v:true)Problem: Buffer variables reset after buffer reload.
Solutions:
Set in autocmd that runs on buffer events:
autocmd BufReadPost * let b:coc_enabled = 1Use FileType event for filetype-specific settings:
autocmd FileType markdown let b:coc_suggest_disable = 1Problem: Statusline doesn't reflect current state.
Solutions:
Force statusline refresh:
autocmd User CocStatusChange,CocDiagnosticChange let &ro = &roUse plugin statusline integration:
" Lightline
autocmd User CocStatusChange,CocDiagnosticChange call lightline#update()
" Airline
autocmd User CocStatusChange,CocDiagnosticChange call airline#update_statusline()Problem: Extensions in g:coc_global_extensions don't install.
Solutions:
Check list format:
" Correct
let g:coc_global_extensions = ['coc-json', 'coc-tsserver']
" Wrong
let g:coc_global_extensions = 'coc-json coc-tsserver'Manual install to verify:
:CocInstall coc-jsonCheck for errors:
:CocCommand workspace.showOutputProblem: Service crashes on large projects.
Solutions:
Increase Node memory:
let g:coc_node_args = ['--max-old-space-size=8192']Restart service:
:CocRestartVerify setting:
echo g:coc_node_args