Statusline & Winbar
Add coc.nvim status and diagnostic information to Vim or Neovim statuslines, including direct statusline and lightline.vim integration examples.
Use a built-in function
coc status (TypeScript version and reported issues)
Add section %{coc#status()} to your statusline option.
The coc#status() function includes diagnostic status information of the current buffer and all status messages received from extensions.
Current function symbol
If you want to display the name of the current enclosing symbol (eg. function name), you can use the b:coc_current_function buffer-bound variable.
To update its value automatically (updated on CursorMove), you need to set "coc.preferences.currentFunctionSymbolAutoUpdate": true in your config.
Alternatively, if you want to handle the updates manually, you can call CocAction("getCurrentFunctionSymbol"), which will return the symbol name and update the b:coc_current_function variable.
Use a manual function
You can use b:coc_diagnostic_info and g:coc_status to build your own status function, like:
| 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
It just works.
Integration with vim-airline
airline now works out of the box.
Check out :h airline-coc for customization details.
Integration with lightline.vim
Use configuration like:
| 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 | \ } |