or run

tessl search
Log in

Version

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/coc.nvim@0.0.x

docs

index.md
tile.json

tessl/npm-coc-nvim

tessl install tessl/npm-coc-nvim@0.0.0

LSP based intellisense engine for neovim & vim8.

variables.mddocs/reference/

Variables and State [Intermediate]

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.

Table of Contents

Common Tasks

Disable Coc for Specific Filetypes

autocmd FileType markdown let b:coc_enabled = 0

Prevents coc.nvim from activating in markdown files.

Configure Auto-Install Extensions

let g:coc_global_extensions = ['coc-json', 'coc-tsserver']

Extensions will be automatically installed on startup.

Customize Status Signs

let g:coc_status_error_sign = '✗'
let g:coc_status_warning_sign = '⚠'

Changes error and warning signs in statusline.

Increase Node Memory

let g:coc_node_args = ['--max-old-space-size=8192']

Allocates more memory to Node.js process for large projects.

Check Service Status

if get(g:, 'coc_service_initialized', 0)
  echo 'Coc is ready'
endif

Verifies coc.nvim has finished initializing.

Global Configuration Variables

Service Configuration

g:coc_start_at_startup

let g:coc_start_at_startup = 1

Start 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 needed

g:coc_global_extensions

let 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'
  \ ]

g:coc_user_config

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
  \ }

g:node_client_debug

let g:node_client_debug = 0

Enable 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 output

Path Configuration

g:coc_config_home

let 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')

g:coc_data_home

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')

g:coc_node_path

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')

g:coc_node_args

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']

Filetype Mapping

g:coc_filetype_map

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'
  \ }

g:coc_uri_prefix_replace_patterns

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/'
  \ }

g:coc_enable_locationlist

let g:coc_enable_locationlist = 1

Use location list for jump operations.

Type: Number Default: 1

Example:

" Disable location list, use quickfix instead
let g:coc_enable_locationlist = 0

UI Configuration Variables

Snippet Navigation

g:coc_snippet_next

let 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>'

g:coc_snippet_prev

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>'

g:coc_selectmode_mapping

let g:coc_selectmode_mapping = 1

Enable select mode mappings for snippets.

Type: Number Default: 1

Example:

" Disable if conflicts with other plugins
let g:coc_selectmode_mapping = 0

Status Indicators

g:coc_status_error_sign

let 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 = ''

g:coc_status_warning_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 = ''

Floating Window Appearance

g:coc_borderchars

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 = ['─', '│', '─', '│', '╭', '╮', '╯', '╰']

g:coc_border_joinchars

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 = ['+', '+', '+', '+']

g:coc_quickfix_open_command

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'

Notification Icons

g:coc_notify_error_icon

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 = ''

g:coc_notify_warning_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 = '!'

g:coc_notify_info_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 = 'ℹ'

Window Dimensions

g:coc_max_treeview_width

let g:coc_max_treeview_width = 40

Maximum width for tree view windows.

Type: Number Default: 40

Example:

" Wider tree views
let g:coc_max_treeview_width = 60

g:coc_prompt_win_width

let g:coc_prompt_win_width = 32

Prompt window width.

Type: Number Default: 32

Example:

" Wider prompts for longer text
let g:coc_prompt_win_width = 50

g:coc_terminal_height

let g:coc_terminal_height = 8

Terminal window height in lines.

Type: Number Default: 8

Example:

" Taller terminal window
let g:coc_terminal_height = 15

Highlighting

g:coc_markdown_disabled_languages

let 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']

g:coc_highlight_maximum_count

let g:coc_highlight_maximum_count = 100

Maximum highlights before grouping.

Type: Number Default: 100

Example:

" Increase for better highlighting in large files
let g:coc_highlight_maximum_count = 200

g:coc_default_semantic_highlight_groups

let g:coc_default_semantic_highlight_groups = 1

Create default semantic highlight groups.

Type: Number Default: 1

Example:

" Disable if using custom semantic highlighting
let g:coc_default_semantic_highlight_groups = 0

Runtime State Variables

Service State

g:coc_service_initialized

g:coc_service_initialized

Indicates 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...'
endif

g:coc_process_pid

g:coc_process_pid

Coc service process PID.

Type: Number (read-only)

Example:

let pid = get(g:, 'coc_process_pid', 0)
if pid > 0
  echo 'Coc process: ' . pid
endif

g:did_coc_loaded

g:did_coc_loaded

Plugin loaded flag.

Type: Number (read-only)

Example:

if exists('g:did_coc_loaded')
  echo 'Coc plugin is loaded'
endif

Current State

g:coc_status

g:coc_status

Status 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_win

g:coc_last_float_win

Last 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'
endif

g:coc_last_hover_message

g:coc_last_hover_message

Last hover message displayed.

Type: String (read-only)

Example:

echo get(g:, 'coc_last_hover_message', 'No hover message')

g:WorkspaceFolders

g:WorkspaceFolders

Current workspace folders.

Type: List (read-only)

Example:

let folders = get(g:, 'WorkspaceFolders', [])
echo 'Workspace folders: ' . join(folders, ', ')

Jump State

g:coc_jump_locations

g:coc_jump_locations

Locations from last jump operation.

Type: List (read-only)

Example:

let locations = get(g:, 'coc_jump_locations', [])
echo 'Found ' . len(locations) . ' locations'

g:coc_selected_text

g:coc_selected_text

Last selected text in operations.

Type: String (read-only)

Example:

echo 'Last selection: ' . get(g:, 'coc_selected_text', '')

g:coc_vim_commands

g:coc_vim_commands

Registered Vim commands from extensions.

Type: List (read-only)

Example:

let commands = get(g:, 'coc_vim_commands', [])
for cmd in commands
  echo cmd
endfor

Buffer Variables

Feature Toggles

b:coc_enabled

let b:coc_enabled = 0

Disable 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 | endif

b:coc_suggest_disable

let b:coc_suggest_disable = 1

Disable 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>

b:coc_diagnostic_disable

let b:coc_diagnostic_disable = 1

Disable 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>

Completion Configuration

b:coc_disabled_sources

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']

b:coc_suggest_blacklist

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']

b:coc_additional_keywords

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 = ['.']

Workspace Configuration

b:coc_root_patterns

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'
  \ ]

Buffer State

b:coc_diagnostic_info

b:coc_diagnostic_info

Diagnostic 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, ' ')
endfunction

b:coc_current_function

b:coc_current_function

Current 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_active

b:coc_snippet_active

Snippet session active flag.

Type: Number (read-only)

Example:

if get(b:, 'coc_snippet_active', 0)
  echo 'In snippet mode'
endif

b:coc_cursors_activated

b:coc_cursors_activated

Multi-cursor mode active flag.

Type: Number (read-only)

Example:

if get(b:, 'coc_cursors_activated', 0)
  echo 'Multi-cursor active'
endif

Formatting Options

b:coc_trim_trailing_whitespace

let b:coc_trim_trailing_whitespace = 1

Trim trailing whitespace on save.

Type: Number Default: 0

Example:

" Enable for specific filetypes
autocmd FileType javascript,python let b:coc_trim_trailing_whitespace = 1

b:coc_trim_final_newlines

let b:coc_trim_final_newlines = 1

Trim final newlines on save.

Type: Number Default: 0

Example:

" Enable for all files
autocmd BufWritePre * let b:coc_trim_final_newlines = 1

Usage Examples

Statusline Integration

Complete 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,%c

Conditional Feature Enabling

Smart 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()

Variable Inspection

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()

Custom Root Patterns

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()

Error Handling

Service Not Initialized

Check before using state variables:

function! SafeGetStatus() abort
  if !get(g:, 'coc_service_initialized', 0)
    return 'Coc starting...'
  endif
  return get(g:, 'coc_status', '')
endfunction

Buffer Variable Defaults

Always provide defaults:

" Good - with default
let enabled = get(b:, 'coc_enabled', 1)

" Bad - may error if undefined
let enabled = b:coc_enabled

Type Checking

Validate 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
endfunction

Troubleshooting

Problem: Variable Changes Not Taking Effect

Problem: Setting variables doesn't change behavior.

Solutions:

  1. Set variables before plugin loads:

    " In .vimrc, BEFORE plugins load
    let g:coc_global_extensions = ['coc-json']
  2. Restart service for config changes:

    :CocRestart
  3. Use coc#config() for runtime changes:

    call coc#config('suggest.noselect', v:true)

Problem: Buffer Variables Lost

Problem: Buffer variables reset after buffer reload.

Solutions:

  1. Set in autocmd that runs on buffer events:

    autocmd BufReadPost * let b:coc_enabled = 1
  2. Use FileType event for filetype-specific settings:

    autocmd FileType markdown let b:coc_suggest_disable = 1

Problem: Status Not Updating

Problem: Statusline doesn't reflect current state.

Solutions:

  1. Force statusline refresh:

    autocmd User CocStatusChange,CocDiagnosticChange let &ro = &ro
  2. Use plugin statusline integration:

    " Lightline
    autocmd User CocStatusChange,CocDiagnosticChange call lightline#update()
    
    " Airline
    autocmd User CocStatusChange,CocDiagnosticChange call airline#update_statusline()

Problem: Global Extensions Not Installing

Problem: Extensions in g:coc_global_extensions don't install.

Solutions:

  1. Check list format:

    " Correct
    let g:coc_global_extensions = ['coc-json', 'coc-tsserver']
    
    " Wrong
    let g:coc_global_extensions = 'coc-json coc-tsserver'
  2. Manual install to verify:

    :CocInstall coc-json
  3. Check for errors:

    :CocCommand workspace.showOutput

Problem: Node Memory Issues

Problem: Service crashes on large projects.

Solutions:

  1. Increase Node memory:

    let g:coc_node_args = ['--max-old-space-size=8192']
  2. Restart service:

    :CocRestart
  3. Verify setting:

    echo g:coc_node_args

See Also

  • Configuration - Managing coc-settings.json
  • Service Management - Start, stop, restart service
  • Diagnostics - Using diagnostic info
  • Highlights - Customizing appearance
  • Autocmds - Integration events