Statusline & Winbar
Add coc.nvim status and diagnostic information to Vim or Neovim statuslines, including direct statusline and lightline.vim integration examples.
coc.nvim project documentation · Content sources and maintainers
Edit this pageUse a built-in function
coc status (TypeScript version and reported issues)
Add %{coc#status()} to your statusline option.
The coc#status() function includes diagnostic status information for the current buffer and all status messages received from extensions.
Current function symbol
To display the name of the enclosing symbol (for example, a function), use the buffer-local variable b:coc_current_function.
To update its value automatically on CursorMove, set "coc.preferences.currentFunctionSymbolAutoUpdate": true in your config.
To update it manually, call CocAction("getCurrentFunctionSymbol"). This returns the symbol name and updates b:coc_current_function.
Use a manual function
You can use b:coc_diagnostic_info and g:coc_status to build your own status function. For example:
| 1 | function! StatusDiagnostic() abort |
| 2 | let info = get(b:, 'coc_diagnostic_info', {}) |
| 3 | if empty(info) | return '' | endif |
| 4 | let msgs = [] |
| 5 | if get(info, 'error', 0) |
| 6 | call add(msgs, 'E' . info['error']) |
| 7 | endif |
| 8 | if get(info, 'warning', 0) |
| 9 | call add(msgs, 'W' . info['warning']) |
| 10 | endif |
| 11 | return join(msgs, ' '). ' ' . get(g:, 'coc_status', '') |
| 12 | endfunction |
Then add %{StatusDiagnostic()} to your statusline option.
Integration with eleline.vim
eleline.vim supports coc.nvim out of the box.
Integration with vim-airline
vim-airline supports coc.nvim out of the box.
See :h airline-coc for customization details.
Integration with lightline.vim
Use a configuration like this:
| 1 | function! CocCurrentFunction() |
| 2 | return get(b:, 'coc_current_function', '') |
| 3 | endfunction |
| 4 | |
| 5 | let g:lightline = { |
| 6 | \ 'colorscheme': 'wombat', |
| 7 | \ 'active': { |
| 8 | \ 'left': [ [ 'mode', 'paste' ], |
| 9 | \ [ 'cocstatus', 'currentfunction', 'readonly', 'filename', 'modified' ] ] |
| 10 | \ }, |
| 11 | \ 'component_function': { |
| 12 | \ 'cocstatus': 'coc#status', |
| 13 | \ 'currentfunction': 'CocCurrentFunction' |
| 14 | \ }, |
| 15 | \ } |