Github url

coc.nvim

by neoclide

neoclide /coc.nvim

Intellisense engine for Vim8 & Neovim, full language server protocol support as VSCode

11.7K Stars 440 Forks Last release: 3 months ago (v0.0.78) MIT License 3.1K Commits 78 Releases

Available items

No Items, yet!

The developer of this repository has not created any items for sale yet. Need a bug fixed? Help with integration? A different license? Create a request here:

Coc Logo

Make your Vim/Neovim as smart as VSCode.

Software LicenseActionsDocGitter


Gif

True snippet and additional text editing support

Why?

Quick Start

Install nodejs >= 10.12:

curl -sL install-node.now.sh/lts | bash

For vim-plug users:

" Use release branch (recommend) Plug 'neoclide/coc.nvim', {'branch': 'release'} " Or build from source code by using yarn: https://yarnpkg.com Plug 'neoclide/coc.nvim', {'do': 'yarn install --frozen-lockfile'}

in your

.vimrc

or

init.vim

, then restart Vim and run

:PlugInstall

.

Checkout Install coc.nvim for more info.

You have to install coc extension or configure language servers for LSP support.

Install extensions like:

:CocInstall coc-json coc-tsserver

Or configure language server in

coc-settings.json

opened by

:CocConfig

, like:

{ "languageserver": { "go": { "command": "gopls", "rootPatterns": ["go.mod"], "trace.server": "verbose", "filetypes": ["go"] } } }

Checkout wiki for more details:

Checkout

:h coc-nvim

for vim interface.

Example vim configuration

Configuration is required to make coc.nvim easier to work with, since it doesn't change your key-mappings or Vim options. This is done as much as possible to avoid conflict with your other plugins.

❗️Important: Some Vim plugins could change key mappings. Please use

:verbose imap <tab></tab>

to make sure that your keymap has taken effect.

" TextEdit might fail if hidden is not set. set hidden " Some servers have issues with backup files, see #649. set nobackup set nowritebackup " Give more space for displaying messages. set cmdheight=2 " Having longer updatetime (default is 4000 ms = 4 s) leads to noticeable " delays and poor user experience. set updatetime=300 " Don't pass messages to |ins-completion-menu|. set shortmess+=c " Always show the signcolumn, otherwise it would shift the text each time " diagnostics appear/become resolved. if has("patch-8.1.1564") " Recently vim can merge signcolumn and number column into one set signcolumn=number else set signcolumn=yes endif " Use tab for trigger completion with characters ahead and navigate. " NOTE: Use command ':verbose imap <tab>' to make sure tab is not mapped by
" other plugin before putting this into your config.
inoremap <silent><expr> <tab>
      \ pumvisible() ? "\<c-n>" :
      \ <sid>check_back_space() ? "\<tab>" :
      \ coc#refresh()
inoremap <expr><s-tab> pumvisible() ? "\<c-p>" : "\<c-h>"

function! s:check_back_space() abort
  let col = col('.') - 1
  return !col || getline('.')[col - 1] =~# '\s'
endfunction

" Use <c-space> to trigger completion.
inoremap <silent><expr> <c-space> coc#refresh()

" Use <cr> to confirm completion, `<c-g>u` means break undo chain at current
" position. Coc only does snippet and additional edit on confirm.
" <cr> could be remapped by other vim plugin, try `:verbose imap <cr>`.
if exists('*complete_info')
  inoremap <expr> <cr> complete_info()["selected"] != "-1" ? "\<c-y>" : "\<c-g>u\<cr>"
else
  inoremap <expr> <cr> pumvisible() ? "\<c-y>" : "\<c-g>u\<cr>"
endif

" Use `[g` and `]g` to navigate diagnostics
" Use `:CocDiagnostics` to get all diagnostics of current buffer in location list.
nmap <silent> [g <plug>(coc-diagnostic-prev)
nmap <silent> ]g <plug>(coc-diagnostic-next)

" GoTo code navigation.
nmap <silent> gd <plug>(coc-definition)
nmap <silent> gy <plug>(coc-type-definition)
nmap <silent> gi <plug>(coc-implementation)
nmap <silent> gr <plug>(coc-references)

" Use K to show documentation in preview window.
nnoremap <silent> K :call <sid>show_documentation()<cr>

function! s:show_documentation()
  if (index(['vim','help'], &amp;filetype) &gt;= 0)
    execute 'h '.expand('<cword>')
  else
    call CocAction('doHover')
  endif
endfunction

" Highlight the symbol and its references when holding the cursor.
autocmd CursorHold * silent call CocActionAsync('highlight')

" Symbol renaming.
nmap <leader>rn <plug>(coc-rename)

" Formatting selected code.
xmap <leader>f <plug>(coc-format-selected)
nmap <leader>f <plug>(coc-format-selected)

augroup mygroup
  autocmd!
  " Setup formatexpr specified filetype(s).
  autocmd FileType typescript,json setl formatexpr=CocAction('formatSelected')
  " Update signature help on jump placeholder.
  autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp')
augroup end

" Applying codeAction to the selected region.
" Example: `<leader>aap` for current paragraph
xmap <leader>a <plug>(coc-codeaction-selected)
nmap <leader>a <plug>(coc-codeaction-selected)

" Remap keys for applying codeAction to the current buffer.
nmap <leader>ac <plug>(coc-codeaction)
" Apply AutoFix to problem on the current line.
nmap <leader>qf <plug>(coc-fix-current)

" Map function and class text objects
" NOTE: Requires 'textDocument.documentSymbol' support from the language server.
xmap if <plug>(coc-funcobj-i)
omap if <plug>(coc-funcobj-i)
xmap af <plug>(coc-funcobj-a)
omap af <plug>(coc-funcobj-a)
xmap ic <plug>(coc-classobj-i)
omap ic <plug>(coc-classobj-i)
xmap ac <plug>(coc-classobj-a)
omap ac <plug>(coc-classobj-a)

" Use CTRL-S for selections ranges.
" Requires 'textDocument/selectionRange' support of LS, ex: coc-tsserver
nmap <silent> <c-s> <plug>(coc-range-select)
xmap <silent> <c-s> <plug>(coc-range-select)

" Add `:Format` command to format current buffer.
command! -nargs=0 Format :call CocAction('format')

" Add `:Fold` command to fold current buffer.
command! -nargs=? Fold :call CocAction('fold', <f-args>)

" Add `:OR` command for organize imports of the current buffer.
command! -nargs=0 OR :call CocAction('runCommand', 'editor.action.organizeImport')

" Add (Neo)Vim's native statusline support.
" NOTE: Please see `:h coc-status` for integrations with external plugins that
" provide custom statusline: lightline.vim, vim-airline.
set statusline^=%{coc#status()}%{get(b:,'coc_current_function','')}

" Mappings for CoCList
" Show all diagnostics.
nnoremap <silent><nowait> <space>a :<c-u>CocList diagnostics<cr>
" Manage extensions.
nnoremap <silent><nowait> <space>e :<c-u>CocList extensions<cr>
" Show commands.
nnoremap <silent><nowait> <space>c :<c-u>CocList commands<cr>
" Find symbol of current document.
nnoremap <silent><nowait> <space>o :<c-u>CocList outline<cr>
" Search workspace symbols.
nnoremap <silent><nowait> <space>s :<c-u>CocList -I symbols<cr>
" Do default action for next item.
nnoremap <silent><nowait> <space>j :<c-u>CocNext<cr>
" Do default action for previous item.
nnoremap <silent><nowait> <space>k :<c-u>CocPrev<cr>
" Resume latest coc list.
nnoremap <silent><nowait> <space>p :<c-u>CocListResume<cr>
</cr></c-u></space></nowait></silent></cr></c-u></space></nowait></silent></cr></c-u></space></nowait></silent></cr></c-u></space></nowait></silent></cr></c-u></space></nowait></silent></cr></c-u></space></nowait></silent></cr></c-u></space></nowait></silent></cr></c-u></space></nowait></silent></f-args></plug></c-s></silent></plug></c-s></silent></plug></plug></plug></plug></plug></plug></plug></plug></plug></leader></plug></leader></plug></leader></plug></leader></leader></plug></leader></plug></leader></plug></leader></cword></cr></sid></silent></plug></silent></plug></silent></plug></silent></plug></silent></plug></silent></plug></silent></cr></c-g></c-y></cr></expr></cr></c-g></c-y></cr></expr></cr></cr></c-g></cr></c-space></expr></silent></c-space></c-h></c-p></s-tab></expr></tab></sid></c-n></tab></expr></silent></tab>

Articles

Trouble shooting

Try these steps when you have problem with coc.nvim.

  • Make sure your Vim version >= 8.0 by command
    :version
    .
  • If service failed to start, use command
    :CocInfo
    or
    :checkhealth
    on Neovim.
  • Checkout the log of coc.nvim by command
    :CocOpenLog
    .
  • When you have issues with the language server, it's recommended to checkout the output.

Feedback

License

MIT

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.