tessl install tessl/npm-coc-nvim@0.0.0LSP based intellisense engine for neovim & vim8.
Complexity: Basic | Category: Intelligence
Common Tasks: Show documentation | Display function signatures | View type information | Get symbol details
Display hover information, function signatures, and documentation from language servers.
nnoremap <silent> K :call CocAction('doHover')<CR>Display documentation for symbol under cursor.
inoremap <silent> <C-k> <C-r>=CocActionAsync('showSignatureHelp')<CR>Show function signature help while typing.
autocmd CursorHold * silent call CocActionAsync('doHover')
set updatetime=300Automatically display hover info when cursor stops moving.
let hover = CocAction('getHover')Retrieve hover information programmatically.
CocAction('doHover')Show hover information for symbol at cursor position in a floating window.
Example:
nnoremap <silent> K :call CocAction('doHover')<CR>
" Show on cursor hold
autocmd CursorHold * silent call CocActionAsync('doHover')
set updatetime=300CocAction('definitionHover')Show hover information for the definition of the symbol at cursor.
Example:
nnoremap <silent> <leader>K :call CocAction('definitionHover')<CR>CocAction('showSignatureHelp')Show function signature help for the function being called.
Example:
nnoremap <silent> <C-k> :call CocAction('showSignatureHelp')<CR>
" Show signature help in insert mode
autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp')CocAction('getHover')
" Returns: listGet hover information without displaying it.
Returns: List of hover content strings.
Example:
let hover = CocAction('getHover')
if len(hover) > 0
echo join(hover, "\n")
endifCocHasProvider(feature)
" Returns: booleanCheck if a language server provides a specific feature.
Parameters:
feature: Feature name (e.g., 'hover', 'signature', 'rename', 'format')Returns: 1 if provider exists, 0 otherwise.
Example:
if CocHasProvider('hover')
nnoremap <silent> K :call CocAction('doHover')<CR>
else
nnoremap <silent> K :normal! K<CR>
endifcoc#ui#echo_hover(msg)Echo hover message in command line.
Parameters:
msg: Message string to displayExample:
call coc#ui#echo_hover('Documentation text here')coc#ui#echo_signatures(signatures)Echo signature help in command line.
Parameters:
signatures: Signature help dataExample:
let sigs = CocAction('getSignatureHelp')
call coc#ui#echo_signatures(sigs)coc#ui#preview_info(lines, filetype, [bufnr])Show information in preview window.
Parameters:
lines: List of lines to displayfiletype: Filetype for syntax highlightingbufnr: Optional buffer numberExample:
call coc#ui#preview_info(['line 1', 'line 2'], 'markdown')g:coc_last_hover_messageRuntime variable containing the last hover message displayed.
Type: String (read-only)
Example:
if exists('g:coc_last_hover_message')
echo g:coc_last_hover_message
endifHover and signature settings in coc-settings.json:
{
"hover.enable": true,
"hover.target": "float",
"hover.floatConfig": {
"border": true,
"rounded": true,
"maxWidth": 80,
"maxHeight": 20
},
"signature.enable": true,
"signature.target": "float",
"signature.floatConfig": {
"border": true
},
"signature.preferShownAbove": true,
"signature.hideOnTextChange": false
}" Show hover on K
nnoremap <silent> K :call CocAction('doHover')<CR>
" Show signature help
inoremap <silent> <C-k> <C-r>=CocActionAsync('showSignatureHelp')<CR>function! ShowDocumentation() abort
if CocAction('hasProvider', 'hover')
call CocActionAsync('doHover')
else
" Fallback to vim's built-in help
execute '!' . &keywordprg . " " . expand('<cword>')
endif
endfunction
nnoremap <silent> K :call ShowDocumentation()<CR>" Show hover on cursor hold
set updatetime=300
function! s:show_hover_auto() abort
if CocAction('hasProvider', 'hover')
call CocActionAsync('doHover')
endif
endfunction
autocmd CursorHold * silent call s:show_hover_auto()
" Don't show in certain filetypes
autocmd FileType qf,help,fugitive autocmd! CursorHold" Auto-show signature help when typing
function! s:trigger_signature() abort
if CocAction('hasProvider', 'signature')
call CocActionAsync('showSignatureHelp')
endif
endfunction
" Show after typing (
autocmd InsertCharPre * if v:char ==# '(' | call timer_start(100, {-> s:trigger_signature()}) | endif
" Show on demand
inoremap <silent><expr> <C-s> CocActionAsync('showSignatureHelp')function! DisplayHoverInfo() abort
let hover = CocAction('getHover')
if len(hover) == 0
echo "No hover information available"
return
endif
" Display in custom way
echo "=== Hover Information ==="
for line in hover
echo line
endfor
endfunction
nnoremap <silent> <leader>h :call DisplayHoverInfo()<CR>function! HoverInPreview() abort
let hover = CocAction('getHover')
if len(hover) == 0
echo "No documentation available"
return
endif
" Show in preview window
call coc#ui#preview_info(hover, 'markdown')
endfunction
nnoremap <silent> <leader>hp :call HoverInPreview()<CR>" First tap shows hover, second tap jumps to definition
let g:last_hover_time = 0
function! SmartHover() abort
let current_time = localtime()
let time_diff = current_time - g:last_hover_time
if time_diff < 1
" Double tap - jump to definition
call CocAction('jumpDefinition')
let g:last_hover_time = 0
else
" Single tap - show hover
call CocAction('doHover')
let g:last_hover_time = current_time
endif
endfunction
nnoremap <silent> K :call SmartHover()<CR>function! HoverWithTimeout(timeout) abort
" Show hover for specific duration
call CocAction('doHover')
" Close after timeout
call timer_start(a:timeout, {-> execute('call coc#float#close_all()')})
endfunction
nnoremap <silent> <leader>ht :call HoverWithTimeout(3000)<CR>function! YankHover() abort
let hover = CocAction('getHover')
if len(hover) == 0
echo "No hover information"
return
endif
" Join and yank to clipboard
let text = join(hover, "\n")
let @+ = text
let @" = text
echo "Hover information yanked"
endfunction
nnoremap <silent> <leader>yh :call YankHover()<CR>let g:hover_history = []
function! HoverWithHistory() abort
let hover = CocAction('getHover')
if len(hover) > 0
call add(g:hover_history, {
\ 'file': expand('%:p'),
\ 'line': line('.'),
\ 'content': hover
\ })
endif
call CocAction('doHover')
endfunction
function! ShowHoverHistory() abort
if len(g:hover_history) == 0
echo "No hover history"
return
endif
for i in range(len(g:hover_history))
let entry = g:hover_history[i]
echo (i + 1) . '. ' . entry.file . ':' . entry.line
endfor
endfunction
nnoremap <silent> K :call HoverWithHistory()<CR>
nnoremap <silent> <leader>hh :call ShowHoverHistory()<CR>function! SmartSignatureHelp() abort
if !CocAction('hasProvider', 'signature')
return
endif
call CocActionAsync('showSignatureHelp')
endfunction
" Trigger on function call
autocmd User CocJumpPlaceholder call SmartSignatureHelp()
" Trigger in insert mode
inoremap <silent> <C-h> <C-r>=SmartSignatureHelp()<CR>function! ConditionalHover() abort
" Only show hover for specific filetypes
let allowed_fts = ['javascript', 'typescript', 'python', 'rust', 'go']
if index(allowed_fts, &filetype) < 0
echo "Hover disabled for " . &filetype
return
endif
call CocAction('doHover')
endfunction
nnoremap <silent> K :call ConditionalHover()<CR>function! HoverStatusline() abort
if !exists('g:coc_last_hover_message')
return ''
endif
" Truncate to fit statusline
let msg = g:coc_last_hover_message
let max_len = 50
if len(msg) > max_len
return msg[:max_len - 4] . '...'
endif
return msg
endfunction
set statusline+=%{HoverStatusline()}function! MultiHover() abort
" Try hover first
if CocAction('hasProvider', 'hover')
call CocAction('doHover')
return
endif
" Try definition hover
if CocAction('hasProvider', 'definition')
call CocAction('definitionHover')
return
endif
" Fallback
echo "No hover information available"
endfunction
nnoremap <silent> K :call MultiHover()<CR>function! HoverWithSyntax() abort
let hover = CocAction('getHover')
if len(hover) == 0
return
endif
" Detect code blocks and apply syntax
let lines = []
let in_code = 0
let lang = ''
for line in hover
if line =~# '^```'
let in_code = !in_code
if in_code
let lang = matchstr(line, '^```\zs\w\+')
endif
else
call add(lines, line)
endif
endfor
call coc#ui#preview_info(lines, lang)
endfunction
nnoremap <silent> <leader>hs :call HoverWithSyntax()<CR>Problem: Hover command shows no documentation.
Solutions:
" Check if hover provider exists
if CocHasProvider('hover')
echo "Hover supported"
else
echo "No hover provider for " . &filetype
endif
" Verify language server is running
:CocInfo
" Check cursor is on valid symbol
echo expand('<cword>')
" Try definition hover instead
call CocAction('definitionHover')Problem: Signature help doesn't appear when calling functions.
Solutions:
" Check signature provider
if CocHasProvider('signature')
echo "Signature help supported"
endif
" Manually trigger
call CocAction('showSignatureHelp')
" Verify in correct context (inside function call)
" Check language server output
:CocCommand workspace.showOutputProblem: Hover float window disappears too quickly.
Solutions:
" Increase hover delay in settings
{
"hover.autoHide": false
}
" Disable auto-hide
{
"hover.floatConfig": {
"focusable": true
}
}
" Keep window open with custom timeout
function! HoverWithTimeout(ms)
call CocAction('doHover')
call timer_start(a:ms, {-> execute('call coc#float#close_all()')})
endfunctionProblem: Documentation doesn't match the actual symbol.
Solutions:
:CocUpdate:CocRestart:CocList symbolsProblem: Parameter hints don't match function signature.
Solutions:
K on function nameProblem: Float window is positioned awkwardly or off-screen.
Solutions:
" Configure float window position
{
"hover.floatConfig": {
"preferTop": true,
"maxWidth": 80,
"maxHeight": 20
}
}
" Adjust based on screen size
{
"hover.floatConfig": {
"border": true,
"rounded": true
}
}Problem: Multiple hover windows appear simultaneously.
Solutions:
autocmd CursorMoved * call coc#float#close_all()autocmd! CursorHoldProblem: Documentation is cut off or incomplete.
Solutions:
" Increase window size limits
{
"hover.floatConfig": {
"maxWidth": 120,
"maxHeight": 40
}
}
" Use preview window for long content
function! HoverInPreview()
let hover = CocAction('getHover')
call coc#ui#preview_info(hover, 'markdown')
endfunction
" Scroll in hover window
" Use <C-f> and <C-b> if focusableProblem: Hover works in some languages but not others.
Solutions:
:CocList extensions:CocCommand workspace.showOutput:set filetype?:CocConfig