tessl install tessl/npm-coc-nvim@0.0.0LSP based intellisense engine for neovim & vim8.
Complexity: Basic | Category: Core
Common Tasks: Start service | Restart service | Check status | View logs
Management of the coc.nvim service lifecycle including starting, stopping, restarting, viewing logs, and checking service status.
:CocStartManually start the coc.nvim service.
:CocRestartRestart the service to resolve issues or apply changes.
if coc#rpc#ready()
echo "Service is ready"
endifCheck if service is ready to accept requests.
:CocInfoDisplay version, platform, extensions, and status information.
:CocOpenLogView detailed service logs for debugging.
:CocStartStart the coc.nvim service. The service is automatically started when Vim loads if g:coc_start_at_startup is enabled (default: 1). Use this command to manually start the service if it was stopped or if auto-start is disabled.
Example:
:CocStart
" Map to key
nnoremap <silent> <leader>cs :CocStart<CR>:CocRestartRestart the coc.nvim service. This stops the current Node.js process and starts a new one. Useful when extensions are misbehaving or after updating coc.nvim itself.
Example:
:CocRestart
" Quick restart mapping
nmap <silent> <leader>cr :CocRestart<CR>:CocDisableTemporarily disable coc.nvim for the current Vim session. This stops the service and prevents it from running until :CocEnable is called.
Example:
:CocDisable
" Disable for large files
autocmd BufReadPre * if getfsize(expand('%')) > 1000000 | CocDisable | endif:CocEnableRe-enable coc.nvim after it has been disabled with :CocDisable.
Example:
:CocEnable:CocInfoDisplay diagnostic information about the coc.nvim service including:
Example:
:CocInfo
" Map to key
nnoremap <silent> <leader>ci :CocInfo<CR>:CocOpenLogOpen the coc.nvim log file in a new buffer. The log contains detailed information about service operations, extension loading, LSP communication, and errors.
Example:
:CocOpenLog
" Quick access to logs
nnoremap <silent> <leader>cl :CocOpenLog<CR>coc#rpc#start_server()Start the coc.nvim RPC server. This is called internally by :CocStart.
Example:
call coc#rpc#start_server()coc#rpc#started()
" Returns: booleanCheck if the RPC server has been started (process spawned).
Returns: 1 if started, 0 otherwise.
Example:
if coc#rpc#started()
echo "RPC server is running"
endifcoc#rpc#ready()
" Returns: booleanCheck if the RPC server is ready to accept requests (initialized and connected).
Returns: 1 if ready, 0 otherwise.
Example:
if coc#rpc#ready()
echo "Service is ready"
else
echo "Service not ready, starting..."
CocStart
endifcoc#rpc#stop()Stop the RPC server gracefully.
Example:
call coc#rpc#stop()coc#rpc#restart()Restart the RPC server. Equivalent to calling coc#rpc#stop() followed by coc#rpc#start_server().
Example:
call coc#rpc#restart()coc#rpc#kill()Forcefully kill the RPC process. Use this if the service is unresponsive and :CocRestart doesn't work.
Example:
" Force kill if hung
call coc#rpc#kill()coc#rpc#get_errors()
" Returns: listGet a list of RPC errors that have occurred.
Returns: List of error messages.
Example:
let errors = coc#rpc#get_errors()
if len(errors) > 0
echo "Errors detected:"
for err in errors
echo err
endfor
endifcoc#rpc#set_channel(chan_id)Set the RPC channel ID. This is used internally for communication.
Parameters:
chan_id: Channel identifiercoc#client#open_log()Open the coc.nvim debug log file. Equivalent to :CocOpenLog.
Example:
call coc#client#open_log()coc#client#is_running(name)
" Returns: booleanCheck if a specific language client is running.
Parameters:
name: Name of the language clientReturns: 1 if running, 0 otherwise.
Example:
if coc#client#is_running('tsserver')
echo "TypeScript server is running"
endifcoc#client#stop(name)
" Returns: booleanStop a specific language client.
Parameters:
name: Name of the language client to stopReturns: 1 if successfully stopped, 0 otherwise.
Example:
call coc#client#stop('tsserver')coc#client#restart(name)Restart a specific language client.
Parameters:
name: Name of the language client to restartExample:
call coc#client#restart('tsserver')coc#client#restart_all()Restart all language clients.
Example:
call coc#client#restart_all()CocAction('services')
" Returns: listGet a list of all language services with their status.
Returns: List of service objects containing name, state, and other metadata.
Example:
let services = CocAction('services')
for service in services
echo service.id . ': ' . service.state
endforCocAction('toggleService', name)Toggle a language service on or off.
Parameters:
name: Service name to toggleExample:
call CocAction('toggleService', 'tsserver')let g:coc_start_at_startup = 1Control whether coc.nvim starts automatically when Vim loads.
Type: Number
Default: 1
Values:
1: Auto-start enabled0: Auto-start disabledExample:
" Disable auto-start
let g:coc_start_at_startup = 0
" Start only for specific filetypes
autocmd FileType javascript,typescript,python CocStartlet g:coc_node_path = '/path/to/node'Path to the Node.js executable. Coc.nvim will use this path instead of searching PATH.
Type: String
Default: 'node'
Example:
" Use a specific Node.js version
let g:coc_node_path = '/usr/local/bin/node'
" Use version manager path
let g:coc_node_path = expand('~/.nvm/versions/node/v16.14.0/bin/node')let g:coc_node_args = ['--max-old-space-size=4096']Additional arguments to pass to the Node.js process.
Type: List
Default: []
Example:
" Increase memory limit for large projects
let g:coc_node_args = ['--max-old-space-size=8192']
" Enable Node.js debugging
let g:coc_node_args = ['--inspect=9229']let g:node_client_debug = 1Enable debug mode for the Node.js client. This increases log verbosity.
Type: Number
Default: 0
Values:
1: Debug enabled0: Debug disabledExample:
" Enable debug logging
let g:node_client_debug = 1g:coc_service_initializedRuntime variable that is set to 1 when the coc.nvim service has fully initialized.
Type: Number (read-only)
Example:
if exists('g:coc_service_initialized') && g:coc_service_initialized
echo "Coc service is ready"
endifg:coc_process_pidProcess ID of the coc.nvim Node.js service.
Type: Number (read-only)
Example:
if exists('g:coc_process_pid')
echo "Coc process ID: " . g:coc_process_pid
endifcoc#status()
" Returns: stringGet formatted status information for use in the Vim statusline. Returns diagnostic information including error and warning counts from the current buffer.
Returns: String containing formatted status (e.g., "E 2 W 1 ") or empty string if no diagnostics.
Configuration:
g:coc_status_error_sign - Custom error sign (default: "E ")g:coc_status_warning_sign - Custom warning sign (default: "W ")g:coc_status - Additional custom status textExample:
" Add coc status to statusline
set statusline=%{coc#status()}%{get(b:,'coc_current_function','')}
" Customize status signs
let g:coc_status_error_sign = '✗ '
let g:coc_status_warning_sign = '⚠ '
" Lightline integration
let g:lightline = {
\ 'active': {
\ 'right': [['coc_status'], ['lineinfo']]
\ },
\ 'component_function': {
\ 'coc_status': 'coc#status'
\ }
\ }coc#util#api_version()
" Returns: numberGet the coc.nvim API version.
Returns: API version number.
Example:
let api_ver = coc#util#api_version()
echo 'Coc API version: ' . api_vercoc#util#version()
" Returns: stringGet the coc.nvim version string.
Returns: Version string (e.g., "0.0.82").
Example:
let version = coc#util#version()
echo 'Coc version: ' . versionautocmd User CocNvimInit {command}Triggered when coc.nvim has finished initializing. Use this to run commands that depend on coc.nvim being ready.
Example:
autocmd User CocNvimInit call s:CocInitialized()
function! s:CocInitialized() abort
echo "Coc initialized with version: " . coc#util#version()
" Setup statusline
set statusline=%{coc#status()}
" Configure extensions
let services = CocAction('services')
echo "Loaded " . len(services) . " services"
endfunction" Check if service is running
if coc#rpc#ready()
echo "Coc service is ready"
else
" Start the service
CocStart
endif
" Restart when needed
nmap <silent> <leader>cr :CocRestart<CR>" View service information
:CocInfo
" Open log file
:CocOpenLog
" Check for errors
let errors = coc#rpc#get_errors()
if len(errors) > 0
echo "Service errors detected:"
for err in errors
echo err
endfor
endif" Wait for coc to initialize before running commands
autocmd User CocNvimInit call s:CocInitialized()
function! s:CocInitialized() abort
" Your initialization code here
echo "Coc initialized with version: " . coc#util#version()
" Load extensions
let services = CocAction('services')
echo "Loaded " . len(services) . " services"
endfunction" Disable auto-start
let g:coc_start_at_startup = 0
" Start only for specific filetypes
autocmd FileType javascript,typescript,python CocStartfunction! CheckCocHealth() abort
if !coc#rpc#ready()
echohl WarningMsg
echo "Coc service is not ready"
echohl None
return
endif
let services = CocAction('services')
let active = 0
for service in services
if service.state == 'running'
let active += 1
endif
endfor
echo "Coc version: " . coc#util#version()
echo "Active services: " . active . "/" . len(services)
endfunction
command! CocHealth call CheckCocHealth()" Disable coc for files larger than 1MB
function! s:DisableForLargeFile() abort
let size = getfsize(expand('%'))
if size > 1000000 || size == -2
silent! CocDisable
echo "Coc disabled for large file"
endif
endfunction
autocmd BufReadPre * call s:DisableForLargeFile()function! ToggleCocService() abort
if coc#rpc#ready()
CocDisable
echo "Coc service disabled"
else
CocEnable
echo "Coc service enabled"
endif
endfunction
nnoremap <silent> <leader>ct :call ToggleCocService()<CR>function! MonitorCocService() abort
let status = {
\ 'version': coc#util#version(),
\ 'started': coc#rpc#started(),
\ 'ready': coc#rpc#ready(),
\ 'errors': len(coc#rpc#get_errors())
\ }
if exists('g:coc_process_pid')
let status.pid = g:coc_process_pid
endif
echo 'Coc Status:'
for [key, val] in items(status)
echo ' ' . key . ': ' . string(val)
endfor
endfunction
command! CocStatus call MonitorCocService()If the service fails to start, check:
" Check Node.js availability
:!node --version
" Check for errors
let errors = coc#rpc#get_errors()
for err in errors
echo err
endfor
" View logs
:CocOpenLogIf the service crashes frequently:
" Increase Node.js memory
let g:coc_node_args = ['--max-old-space-size=8192']
" Enable debug logging
let g:node_client_debug = 1
" Restart to apply changes
:CocRestartIf the service becomes unresponsive:
" Force kill the process
call coc#rpc#kill()
" Start fresh
:CocStart
" Or use restart
:CocRestartProblem: Coc doesn't start when Vim opens.
Solutions:
echo g:coc_start_at_startuplet g:coc_start_at_startup = 1:CocInfo:CocOpenLog:!node --versionProblem: Service repeatedly crashes and restarts.
Solutions:
:CocOpenLog:CocUpdate:CocRebuildlet g:coc_node_args = ['--max-old-space-size=8192']Problem: Coc commands don't execute or show "Not an editor command".
Solutions:
if coc#rpc#ready() | echo "Ready" | endif:CocStartProblem: Coc service uses excessive memory.
Solutions:
let g:coc_node_args = ['--max-old-space-size=4096']:CocRestartProblem: Coc uses incorrect Node.js version.
Solutions:
let g:coc_node_path = '/path/to/correct/node'echo g:coc_node_path:!node --version:CocRestartg:coc_node_args with --max-old-space-size to limit memory consumptionb:coc_enabled = 0