tessl install tessl/npm-coc-nvim@0.0.0LSP based intellisense engine for neovim & vim8.
Complexity: Intermediate | Category: UI
Common Tasks: Highlight symbols | Pick colors | Customize highlights | Semantic tokens
Document highlighting, semantic highlighting, color management, and all highlight groups used by coc.nvim.
autocmd CursorHold * silent call CocActionAsync('highlight')Automatically highlight symbol under cursor.
call CocAction('pickColor')Open system color picker dialog.
call CocAction('colorPresentation')Show different color representations (hex, rgb, hsl).
highlight CocErrorSign ctermfg=Red guifg=#ff0000
highlight CocWarningSign ctermfg=Yellow guifg=#ffcc00CocAction('highlight')Highlight symbol under cursor and all its occurrences in the document.
Example:
autocmd CursorHold * silent call CocActionAsync('highlight')
set updatetime=300CocAction('semanticHighlight')Update semantic highlights for the current buffer.
Example:
call CocAction('semanticHighlight')CocAction('inspectSemanticToken')Inspect semantic token information at cursor position.
Example:
nnoremap <silent> <leader>hi :call CocAction('inspectSemanticToken')<CR>CocAction('pickColor')Open system color picker to select a color.
Example:
nnoremap <silent> <leader>cp :call CocAction('pickColor')<CR>CocAction('colorPresentation')Show different representations of color under cursor (hex, rgb, hsl, etc.).
Example:
nnoremap <silent> <leader>cc :call CocAction('colorPresentation')<CR>coc#highlight#buffer_update(bufnr, key, highlights, [start], [end])Update buffer highlights.
Parameters:
bufnr: Buffer numberkey: Highlight key/namespacehighlights: List of highlight itemsstart: Optional start lineend: Optional end linecoc#highlight#update_highlights(bufnr, key, highlights, [start], [end])Update highlights incrementally.
Parameters:
bufnr: Buffer numberkey: Highlight keyhighlights: Highlight itemsstart: Optional start lineend: Optional end linecoc#highlight#set(bufnr, key, highlights, priority)Set highlights for buffer with priority.
Parameters:
bufnr: Buffer numberkey: Highlight keyhighlights: Highlight itemspriority: Highlight prioritycoc#highlight#clear(bufnr, key, lnums)Clear highlights from buffer.
Parameters:
bufnr: Buffer numberkey: Highlight keylnums: Line numbers to clearcoc#highlight#ranges(bufnr, key, hlGroup, ranges, [priority])Highlight specific ranges.
Parameters:
bufnr: Buffer numberkey: Highlight keyhlGroup: Highlight group nameranges: List of rangespriority: Optional prioritycoc#highlight#add_highlight(bufnr, src_id, hl_group, line, col_start, col_end)
" Returns: numberAdd single highlight.
Parameters:
bufnr: Buffer numbersrc_id: Source IDhl_group: Highlight groupline: Line number (0-based)col_start: Start column (0-based)col_end: End column (-1 for end of line)Returns: Source ID.
coc#highlight#clear_highlight(bufnr, key, start_line, end_line)Clear highlight range.
Parameters:
bufnr: Buffer numberkey: Highlight keystart_line: Start lineend_line: End linecoc#highlight#clear_all()Clear all coc highlights.
coc#highlight#create_namespace(key)
" Returns: numberCreate highlight namespace.
Parameters:
key: Namespace keyReturns: Namespace ID.
coc#highlight#get_syntax_name(lnum, col)
" Returns: stringGet syntax name at position.
Parameters:
lnum: Line numbercol: ColumnReturns: Syntax name.
coc#color#rgb2term(rgb)
" Returns: numberConvert RGB hex color to terminal color code.
Parameters:
rgb: RGB hex color (e.g., '#ff0000')Returns: Terminal color code.
Example:
let term_color = coc#color#rgb2term('#ff0000')
echo 'Terminal color: ' . term_colorcoc#color#pick_color(default_color)
" Returns: list or falseOpen system color picker.
Parameters:
default_color: Default color to showReturns: List [r, g, b] or v:false if cancelled.
Example:
let color = coc#color#pick_color('#ffffff')
if color isnot v:false
echo 'Selected: ' . color
endifcoc#util#semantic_hlgroups()
" Returns: listGet list of semantic highlight groups.
Returns: List of highlight group names.
Example:
let groups = coc#util#semantic_hlgroups()
for group in groups
echo group
endforcoc#util#synname()
" Returns: stringGet syntax name under cursor.
Returns: Syntax/highlight group name.
Example:
nnoremap <silent> <F10> :echo coc#util#synname()<CR>let g:coc_default_semantic_highlight_groups = 1Create default semantic highlight groups.
Type: Number
Default: 1
Example:
" Disable default semantic highlight groups
let g:coc_default_semantic_highlight_groups = 0let g:coc_highlight_maximum_count = 100Maximum number of highlights before grouping.
Type: Number
Default: 100
Example:
let g:coc_highlight_maximum_count = 200CocBoldBold text in documentation and UI elements.
Example:
highlight CocBold cterm=bold gui=boldCocItalicItalic text in documentation and UI elements.
Example:
highlight CocItalic cterm=italic gui=italicCocUnderlineUnderlined text.
Example:
highlight CocUnderline cterm=underline gui=underlineCocStrikeThroughStrikethrough text for deprecated items.
Example:
highlight CocStrikeThrough cterm=strikethrough gui=strikethroughCocFadeOutFaded out text for inactive elements.
Example:
highlight CocFadeOut ctermfg=245 guifg=#928374CocDisabledDisabled UI items.
Example:
highlight CocDisabled ctermfg=240 guifg=#585858CocMarkdownCodeInline code in markdown documentation.
Example:
highlight CocMarkdownCode ctermfg=109 guifg=#83a598CocMarkdownHeaderMarkdown headers in documentation.
Example:
highlight CocMarkdownHeader ctermfg=214 guifg=#fabd2f cterm=bold gui=boldCocMarkdownLinkMarkdown links.
Example:
highlight CocMarkdownLink ctermfg=109 guifg=#83a598 cterm=underline gui=underlineCocErrorSignError signs in sign column.
Example:
highlight CocErrorSign ctermfg=Red guifg=#ff0000CocWarningSignWarning signs in sign column.
Example:
highlight CocWarningSign ctermfg=Yellow guifg=#ffcc00CocInfoSignInformation signs in sign column.
Example:
highlight CocInfoSign ctermfg=Blue guifg=#0088ffCocHintSignHint signs in sign column.
Example:
highlight CocHintSign ctermfg=Cyan guifg=#00ffaaCocErrorVirtualTextError virtual text at end of line.
Example:
highlight CocErrorVirtualText ctermfg=Red guifg=#ff0000CocWarningVirtualTextWarning virtual text.
Example:
highlight CocWarningVirtualText ctermfg=Yellow guifg=#ffcc00CocInfoVirtualTextInfo virtual text.
Example:
highlight CocInfoVirtualText ctermfg=Blue guifg=#0088ffCocHintVirtualTextHint virtual text.
Example:
highlight CocHintVirtualText ctermfg=Cyan guifg=#00ffaaCocErrorHighlightError code range highlighting.
Example:
highlight CocErrorHighlight ctermbg=52 guibg=#5f0000 cterm=undercurl gui=undercurl guisp=#ff0000CocWarningHighlightWarning code range highlighting.
Example:
highlight CocWarningHighlight ctermbg=58 guibg=#5f5f00 cterm=undercurl gui=undercurl guisp=#ffcc00CocInfoHighlightInfo code range highlighting.
Example:
highlight CocInfoHighlight ctermbg=17 guibg=#00005f cterm=undercurl gui=undercurl guisp=#0088ffCocHintHighlightHint code range highlighting.
Example:
highlight CocHintHighlight ctermbg=23 guibg=#005f5f cterm=undercurl gui=undercurl guisp=#00ffaaCocDeprecatedHighlightDeprecated code highlighting.
Example:
highlight CocDeprecatedHighlight cterm=strikethrough gui=strikethrough guisp=#888888CocUnusedHighlightUnused code highlighting.
Example:
highlight CocUnusedHighlight ctermfg=240 guifg=#585858CocErrorLineFull line highlight for errors.
Example:
highlight CocErrorLine ctermbg=52 guibg=#3f0000CocWarningLineFull line highlight for warnings.
Example:
highlight CocWarningLine ctermbg=58 guibg=#3f3f00CocInfoLineFull line highlight for info.
Example:
highlight CocInfoLine ctermbg=17 guibg=#00003fCocHintLineFull line highlight for hints.
Example:
highlight CocHintLine ctermbg=23 guibg=#003f3fCocHighlightTextDefault symbol highlight (read/write).
Example:
highlight CocHighlightText ctermbg=237 guibg=#3a3a3aCocHighlightReadSymbol read occurrence highlight.
Example:
highlight CocHighlightRead ctermbg=22 guibg=#2a4a2aCocHighlightWriteSymbol write occurrence highlight.
Example:
highlight CocHighlightWrite ctermbg=52 guibg=#4a2a2aCocHoverRangeHovered symbol range.
Example:
highlight CocHoverRange ctermbg=237 guibg=#3a3a3aCocCursorRangeCursor range for multi-cursor.
Example:
highlight CocCursorRange ctermbg=237 guibg=#3a3a3aCocLinkedEditingLinked editing ranges.
Example:
highlight CocLinkedEditing ctermbg=237 guibg=#3a3a3aCocSelectedRangeSelected ranges.
Example:
highlight CocSelectedRange ctermbg=237 guibg=#3a3a3aCocFloatingDefault floating window background.
Example:
highlight CocFloating ctermbg=235 guibg=#1e1e1eCocErrorFloatError text in floating windows.
Example:
highlight CocErrorFloat ctermfg=Red guifg=#ff0000CocWarningFloatWarning text in floating windows.
Example:
highlight CocWarningFloat ctermfg=Yellow guifg=#ffcc00CocInfoFloatInfo text in floating windows.
Example:
highlight CocInfoFloat ctermfg=Blue guifg=#0088ffCocHintFloatHint text in floating windows.
Example:
highlight CocHintFloat ctermfg=Cyan guifg=#00ffaaCocNotificationProgressProgress notification line.
Example:
highlight CocNotificationProgress ctermfg=109 guifg=#83a598CocNotificationButtonAction buttons in notifications.
Example:
highlight CocNotificationButton ctermbg=237 guibg=#3a3a3aCocNotificationErrorError notification border.
Example:
highlight CocNotificationError ctermfg=Red guifg=#ff0000CocNotificationWarningWarning notification border.
Example:
highlight CocNotificationWarning ctermfg=Yellow guifg=#ffcc00CocNotificationInfoInfo notification border.
Example:
highlight CocNotificationInfo ctermfg=Blue guifg=#0088ffCocListLineCurrent selected line in list.
Example:
highlight CocListLine ctermbg=237 guibg=#3a3a3aCocListSearchMatched search characters in list.
Example:
highlight CocListSearch ctermfg=214 guifg=#fabd2f cterm=bold gui=boldCocListModeMode indicator text in list.
Example:
highlight CocListMode ctermfg=109 guifg=#83a598CocListPathFile path text in list.
Example:
highlight CocListPath ctermfg=245 guifg=#928374CocSelectedTextSign for selected text.
Example:
highlight CocSelectedText ctermfg=214 guifg=#fabd2fCocSelectedLineSelected line background.
Example:
highlight CocSelectedLine ctermbg=237 guibg=#3a3a3aCocSearchGeneral search result highlight.
Example:
highlight CocSearch ctermfg=214 guifg=#fabd2f ctermbg=237 guibg=#3a3a3aCocTreeTitleTree view title.
Example:
highlight CocTreeTitle ctermfg=214 guifg=#fabd2f cterm=bold gui=boldCocTreeDescriptionTree item descriptions.
Example:
highlight CocTreeDescription ctermfg=245 guifg=#928374CocTreeOpenCloseTree expand/collapse icons.
Example:
highlight CocTreeOpenClose ctermfg=109 guifg=#83a598CocTreeSelectedSelected tree item.
Example:
highlight CocTreeSelected ctermbg=237 guibg=#3a3a3aCocPumSearchMatched input characters in completion menu.
Example:
highlight CocPumSearch ctermfg=214 guifg=#fabd2f cterm=bold gui=boldCocPumMenuCompletion menu background.
Example:
highlight CocPumMenu ctermbg=235 guibg=#262626CocPumShortcutSource shortcut in completion.
Example:
highlight CocPumShortcut ctermfg=245 guifg=#928374CocPumDeprecatedDeprecated completion items.
Example:
highlight CocPumDeprecated cterm=strikethrough gui=strikethroughCocPumVirtualTextVirtual text in completion menu.
Example:
highlight CocPumVirtualText ctermfg=245 guifg=#928374CocMenuSelSelected completion item.
Example:
highlight CocMenuSel ctermbg=237 guibg=#3a3a3aAll symbol kind highlights follow the pattern CocSymbol{Kind}:
CocSymbolDefaultDefault symbol kind.
CocSymbolText
CocSymbolMethod
CocSymbolFunction
CocSymbolConstructor
CocSymbolField
CocSymbolVariable
CocSymbolClass
CocSymbolInterface
CocSymbolModule
CocSymbolProperty
CocSymbolUnit
CocSymbolValue
CocSymbolEnum
CocSymbolKeyword
CocSymbolSnippet
CocSymbolColor
CocSymbolFile
CocSymbolReference
CocSymbolFolder
CocSymbolEnumMember
CocSymbolConstant
CocSymbolStruct
CocSymbolEvent
CocSymbolOperator
CocSymbolTypeParameter
CocSymbolNamespace
CocSymbolPackage
CocSymbolString
CocSymbolNumber
CocSymbolBoolean
CocSymbolArray
CocSymbolObject
CocSymbolKey
CocSymbolNullExample:
highlight CocSymbolClass ctermfg=214 guifg=#fabd2f
highlight CocSymbolFunction ctermfg=109 guifg=#83a598
highlight CocSymbolVariable ctermfg=142 guifg=#b8bb26All semantic token highlights follow the pattern CocSem{TokenType}:
CocSemNamespace
CocSemType
CocSemClass
CocSemEnum
CocSemInterface
CocSemStruct
CocSemTypeParameter
CocSemParameter
CocSemVariable
CocSemProperty
CocSemEnumMember
CocSemEvent
CocSemFunction
CocSemMethod
CocSemMacro
CocSemKeyword
CocSemModifier
CocSemComment
CocSemString
CocSemNumber
CocSemBoolean
CocSemRegexp
CocSemOperator
CocSemDecorator
CocSemDeprecatedExample:
highlight CocSemClass ctermfg=214 guifg=#4ec9b0
highlight CocSemFunction ctermfg=109 guifg=#dcdcaa
highlight CocSemVariable ctermfg=142 guifg=#9cdcfeCocCodeLensCodeLens virtual text.
Example:
highlight CocCodeLens ctermfg=245 guifg=#999999CocSnippetVisualSnippet visual selection.
Example:
highlight CocSnippetVisual ctermbg=237 guibg=#3a3a3aCocInlayHintInlay hint virtual text.
Example:
highlight CocInlayHint ctermfg=245 guifg=#999999Highlight settings in coc-settings.json:
{
"semanticTokens.enable": true,
"semanticTokens.filetypes": ["*"],
"colors.enable": true,
"suggest.completionItemKindLabels": {
"keyword": "ξ",
"variable": "ψ",
"value": "λ"
}
}" Highlight symbol under cursor on hold
autocmd CursorHold * silent call CocActionAsync('highlight')
set updatetime=300
" Clear highlights on cursor move
autocmd CursorMoved * silent call coc#highlight#clear_all()function! PickColorAndInsert() abort
let color = coc#color#pick_color('#000000')
if color isnot v:false
let hex = printf('#%02x%02x%02x', color[0], color[1], color[2])
execute "normal! a" . hex
echo 'Inserted color: ' . hex
endif
endfunction
nnoremap <silent> <leader>cp :call PickColorAndInsert()<CR>function! ConvertColorFormat() abort
" Show different color representations
call CocAction('colorPresentation')
endfunction
nnoremap <silent> <leader>cf :call ConvertColorFormat()<CR>function! ShowSyntaxInfo() abort
let synname = coc#util#synname()
let lnum = line('.')
let col = col('.')
let hlname = coc#highlight#get_syntax_name(lnum, col)
echo 'Syntax: ' . synname
echo 'Highlight: ' . hlname
endfunction
nnoremap <silent> <F10> :call ShowSyntaxInfo()<CR>function! HighlightCurrentWord() abort
let word = expand('<cword>')
let ranges = []
let lnum = 1
while lnum <= line('$')
let line = getline(lnum)
let col = 0
while 1
let col = match(line, '\<' . word . '\>', col)
if col == -1
break
endif
call add(ranges, {
\ 'start': {'line': lnum - 1, 'character': col},
\ 'end': {'line': lnum - 1, 'character': col + len(word)}
\ })
let col += 1
endwhile
let lnum += 1
endwhile
call coc#highlight#ranges(bufnr('%'), 'word', 'CocHighlightText', ranges, 10)
endfunction
nnoremap <silent> <leader>hw :call HighlightCurrentWord()<CR>function! InspectToken() abort
call CocAction('inspectSemanticToken')
endfunction
nnoremap <silent> <leader>it :call InspectToken()<CR>let g:semantic_highlights_enabled = 1
function! ToggleSemanticHighlights() abort
if g:semantic_highlights_enabled
let g:semantic_highlights_enabled = 0
call coc#config('semanticTokens.enable', v:false)
echo 'Semantic highlighting disabled'
else
let g:semantic_highlights_enabled = 1
call coc#config('semanticTokens.enable', v:true)
call CocAction('semanticHighlight')
echo 'Semantic highlighting enabled'
endif
endfunction
command! ToggleSemanticHighlights call ToggleSemanticHighlights()function! PreviewColorUnderCursor() abort
let line = getline('.')
let col = col('.')
" Match hex color
let hex = matchstr(line, '#\x\{6}', col - 7)
if !empty(hex)
" Show color preview (could use terminal colors or float window)
echo 'Color: ' . hex
" Convert to RGB
let r = str2nr(hex[1:2], 16)
let g = str2nr(hex[3:4], 16)
let b = str2nr(hex[5:6], 16)
echo 'RGB: ' . r . ', ' . g . ', ' . b
endif
endfunction
nnoremap <silent> <leader>pc :call PreviewColorUnderCursor()<CR>" Customize symbol highlight colors
highlight CocHighlightText guibg=#3a3a3a ctermbg=237
highlight CocHighlightRead guibg=#2a4a2a ctermbg=22
highlight CocHighlightWrite guibg=#4a2a2a ctermbg=52
" Customize semantic token colors
highlight CocSemClass guifg=#4ec9b0
highlight CocSemFunction guifg=#dcdcaa
highlight CocSemVariable guifg=#9cdcfe
highlight CocSemParameter guifg=#9cdcfe
highlight CocSemProperty guifg=#9cdcfefunction! ClearAllHighlights() abort
call coc#highlight#clear_all()
echo 'Cleared all highlights'
endfunction
command! ClearHighlights call ClearAllHighlights()
nnoremap <silent> <leader>ch :ClearHighlights<CR>function! ListSemanticHighlights() abort
let groups = coc#util#semantic_hlgroups()
echo '=== Semantic Highlight Groups ==='
for group in groups
echo group
endfor
endfunction
command! SemanticGroups call ListSemanticHighlights()function! RgbToHex(r, g, b) abort
return printf('#%02x%02x%02x', a:r, a:g, a:b)
endfunction
function! HexToRgb(hex) abort
let hex = substitute(a:hex, '^#', '', '')
return [
\ str2nr(hex[0:1], 16),
\ str2nr(hex[2:3], 16),
\ str2nr(hex[4:5], 16)
\ ]
endfunction
" Usage
echo RgbToHex(255, 0, 0) " #ff0000
echo HexToRgb('#ff0000') " [255, 0, 0]" Diagnostics
highlight CocErrorSign ctermfg=Red guifg=#e06c75
highlight CocWarningSign ctermfg=Yellow guifg=#e5c07b
highlight CocInfoSign ctermfg=Blue guifg=#61afef
highlight CocHintSign ctermfg=Cyan guifg=#56b6c2
highlight CocErrorHighlight cterm=undercurl gui=undercurl guisp=#e06c75
highlight CocWarningHighlight cterm=undercurl gui=undercurl guisp=#e5c07b
" Document highlights
highlight CocHighlightText ctermbg=237 guibg=#3e4452
highlight CocHighlightRead ctermbg=22 guibg=#2a4a2a
highlight CocHighlightWrite ctermbg=52 guibg=#4a2a2a
" Float windows
highlight CocFloating ctermbg=235 guibg=#282c34
" List
highlight CocListLine ctermbg=237 guibg=#3e4452
highlight CocListSearch ctermfg=214 guifg=#e5c07b cterm=bold gui=bold
" Completion
highlight CocMenuSel ctermbg=237 guibg=#3e4452
highlight CocPumSearch ctermfg=214 guifg=#e5c07b cterm=bold gui=bold
" Symbols
highlight CocSymbolClass ctermfg=214 guifg=#e5c07b
highlight CocSymbolFunction ctermfg=109 guifg=#61afef
highlight CocSymbolVariable ctermfg=142 guifg=#98c379let color = coc#color#pick_color('#000000')
if color is v:false
echo "Color picker was cancelled"
else
" Process color
endiftry
highlight link MyGroup CocInvalidGroup
catch
echohl Error
echo "Invalid highlight group"
echohl None
endtryif !CocHasProvider('semanticTokens')
echohl WarningMsg
echo "Semantic tokens not available for this buffer"
echohl None
else
call CocAction('semanticHighlight')
endif:hi CocSemClasshighlight! link CocErrorSign ErrorMsg
highlight! link CocWarningSign WarningMsgupdatetime is set appropriately (300ms recommended)g:coc_highlight_maximum_count"semanticTokens.enable": false