VimPlugin: Coc.nvim: Difference between revisions

From wikinotes
No edit summary
 
(7 intermediate revisions by the same user not shown)
Line 1: Line 1:
coc.nvim aims to be intellisense (visualstudio) for vim.
coc.nvim aims to be intellisense for vim. It provides:
 
* autocompletion
* autocompletion
* outliner
* outliner
Line 6: Line 5:
* goto
* goto
* show-references
* show-references
{{ WARNING |
coc.nvim '''DOES NOT''' play nice with other autocompleters. }}




Line 38: Line 34:
</blockquote><!-- Locations -->
</blockquote><!-- Locations -->


= Languages =
= Notes =
<blockquote>
<blockquote>
== Extensions ==
{|
Language Servers may have a wrapper built for COC. These are called extensions.
 
You may install them dynamically with <code>:CocInstall coc-python</code><br>
and ''sometimes'' automatically like <code>Plug 'neoclide/coc-tsserver', {'do': 'yarn install --frozen-lockfile'}</code>.
 
{| class="wikitable"
|-
| python || unmaintained || [[coc-python]]
|-
|-
| python || active || [[coc-pyright]]
| [[coc.nvim install]]
|-
|-
| sh/bash || active || [[coc-sh]]
| [[coc.nvim language servers]]
|-
|-
| ruby/rails || active || [[coc-solargraph]]
| [[coc.nvim configuration]]
|-
|-
| ruby/rails || active || [[ruby sorbet]]
| [[coc.nvim usage]]
|-
|-
| graphql || active || [[coc-graphql]]
| [[coc.nvim troubleshooting]]
|-
|-
|}
|}
 
</blockquote><!-- Notes -->
== Custom Language Servers ==
Some programs may be able to function as an LSP, and can be registered to do so.<br>
see https://github.com/neoclide/coc.nvim/wiki/Language-servers#register-custom-language-servers
 
<source lang="json">
{
  "languageserver": {
      "sorbet": {
        "command": "srb",
        "args": ["tc", "--lsp"],
        "filetypes": ["ruby"]
      }
  }
}
</source>
</blockquote><!-- languages -->
 
= Install =
<blockquote>
<syntaxhighlight lang="vim">
# archlinux
sudo pacman -S \
  nodejs \
  npm
 
# macos
brew install
  node.js \
  npm
 
npm install -g neovim
</syntaxhighlight>
 
<syntaxhighlight lang="vim">
" install coc
Plug "https://github.com/neoclide/coc.nvim", {'branch': 'release'}
 
" install coc languages
 
" NOTE: technically this is supposed to work, but it doesn't for all languages
" Plug 'https://github.com/neoclide/coc-tsserver', {'do': 'yarn install --frozen-lockfile'}
 
if !(isdirectory($HOME."/.config/coc/extensions/node_modules/coc-sh"))
  CocInstall coc-sh
endif
 
</syntaxhighlight>
 
{{ NOTE |
Officially, installing servers can be done from vim-plug, but I have not had success with this.
 
<code>CocInstall</code> works every time. It's probably best to check for files on disk.
}}
</blockquote><!-- Install -->
 
= Configuration =
<blockquote>
== Keybindings ==
<blockquote>
coc.nvim does not provide function calls, they direct you to bind hotkeys instead.
<syntaxhighlight lang="vim">
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)
</syntaxhighlight>
</blockquote><!-- keybindings -->
</blockquote><!-- Configuration -->
 
= Usage =
<blockquote>
Builtin Commands
<syntaxhighlight lang="vim">
CocInstall coc-python  " install a language
CocUninstall coc-python " uninstall a language
CocOutline              " tagbar-like outliner
</syntaxhighlight>
 
Custom Commands (derived from plug functions)
<syntaxhighlight lang="vim">
" ex: command CocRename silent exec "normal \<Plug>(coc-rename)"
 
" Introspection (src, packages)
CocDefinition          " go to where variable assigned
CocTypeDefinition      " go to where variable type defined
CocImplementation
CocReferences          " show uses of variable
CocShowdocumentation  " show docs
 
" Formatting
CocFormatBuffer        " format file
CocFormatSelected      " format selection
CocOrganizeImports    " sort imports
 
" Debugging
CocInfo                " show nvim, coc, lsp info
CocOpenLog            " show log
</syntaxhighlight>
</blockquote><!-- Usage -->
 
= Troubleshooting =
<blockquote>
<source lang="vim">
:CocInfo  " print debug info
</source>
</blockquote><!-- troubleshooting -->

Latest revision as of 15:39, 28 December 2021

coc.nvim aims to be intellisense for vim. It provides:

  • autocompletion
  • outliner
  • refactor-rename
  • goto
  • show-references


Documentation

:h coc-nvim https://github.com/neoclide/coc.nvim/blob/master/doc/coc.txt
github https://github.com/neoclide/coc.nvim
wiki https://github.com/neoclide/coc.nvim/wiki
extension list https://github.com/neoclide/coc.nvim/wiki/Using-coc-extensions#implemented-coc-extensions

Locations

~/.config/nvim/coc-settings.json config
~/.config/coc/extensions/node_modules/${plugin} plugins installed here
~/.config/coc/memos.json persisted plugin data

Notes

coc.nvim install
coc.nvim language servers
coc.nvim configuration
coc.nvim usage
coc.nvim troubleshooting