Contents

coc.nvim – user-friendly code completion for vim

Code completions are a critical component of software development, providing developers with a faster and more efficient way to write code. They eliminate the need to manually type long, complex code snippets and provide a list of suggestions based on the syntax and context of the code being written. In the Vim text editor, code completions are a powerful feature that can greatly enhance the development experience.

There are several popular code completion plugins for Vim, each with its own unique set of features and benefits. Here are some of the most popular examples:

  1. YouCompleteMe (YCM) - YCM is a fast, powerful code completion engine that provides auto-completion suggestions as you type. It supports a wide range of programming languages and can be customized with additional completion engines.
  2. NeoComplete - NeoComplete is a plugin that uses the neocomplete.vim library to provide code completions for Vim. It is simple to use, highly customizable, and provides a comprehensive set of features for code completion.
  3. Deoplete - Deoplete is a plugin that uses the deoplete.nvim library to provide asynchronous code completion for Vim. It is fast, lightweight, and supports multiple completion sources.

coc.nvim

While these plugins are all excellent choices, the coc.nvim plugin is a great option for developers who are looking for a comprehensive, user-friendly code completion solution. The coc.nvim plugin is built on the Language Server Protocol, which allows for language-agnostic code completions and improved language support. This protocol provides a standard way for code editors to communicate with language servers, allowing them to access language-specific knowledge and provide better code completions.

One of the biggest advantages of the coc.nvim plugin is its ease of use. It is simple to install and configure, and it provides a rich set of features that make it a great choice for both new and experienced Vim users. The plugin supports a wide range of programming languages and provides intelligent code completions based on the context of the code being written.

Another advantage of the coc.nvim plugin is its performance. It is fast and efficient, and it uses an asynchronous architecture that makes it easy to use even on large projects. The plugin also provides an intuitive interface for managing completion sources, allowing users to easily add, remove, or configure completion sources as needed.

Despite its many advantages, there are a few cons to consider when using the coc.nvim plugin. For example, it can be difficult to configure the plugin for specific languages or projects, and some users may find that the plugin is slow or unstable when working with large codebases. Additionally, the plugin may not provide the level of customization and control that some developers need.

How to install

Before install coc-vim make sure you have already installed NodeJS.

To install the coc-vim plugin, you will need to use the Vim Plug plugin manager. If you do not already have Vim Plug installed, you can install it by the instruction.

Once Vim Plug is installed, you can install the coc-vim plugin by adding the following lines to your .vimrc file:

Plug 'neoclide/coc.nvim', {'branch''release'}

After the plugin is installed, you can start using it by restarting Vim or by running the following command:

:PlugInstall

After that you can install extensions for needed languages like this:

:CocInstall coc-json coc-tsserver

You can find the list of available extensions here.

Vim configuration

It’s really helpful to set up some hotkeys for coc.nvim. At the beginning you can use config from coc’s repo. Just place the code somewhere on your filesystem (e.g. ~/.vim/custom/coc.nvim/keymap.vim) and import it in ~/.vimrc like this:

" coc.nvim settings 
source $HOME/.vim/custom/coc.nvim/keymap.vim

You can try coc.nvim now. Start typing something and you’ll see the prompt with available completions. To select another item from the list use <TAB> or <S-TAB>, to choose selected option - <CR>.

In conclusion

Code completions are a critical tool for software development, and the coc-vim plugin provides an excellent solution for Vim users. With its ease of use, comprehensive feature set, and performance, the coc-vim plugin is a great choice for developers of all levels. The plugin supports a wide range of programming languages and provides intelligent code completions based on the context of the code being written. Additionally, the use of the Language Server Protocol allows for language-agnostic code completions and improved language support.