Table of Contents

Introduction

YouCompleteMe is a code completion engine that displays code complete suggestions as you type. It supports various languages: C family languages (C/C++, Objective C/C++), Python, C#, Go, JavaScript/TypeScript, Java, Ruby etc.

Some of the useful features listed below:

  • Fast identifier completion
  • File and path suggestions
  • Detecting common coding errors like mission semi colons, typos etc.
  • Code formatting
  • Display documentation for functions/methods etc..

Press TAb repeatedly to navigate through suggestions and Enter to select.

YouComplete code completion for JavaScript
YouComplete code completion for JavaScript

Installation

Installing YouCompleteMe

YouCompleteMe can be installed with Vundle. Vundle is a Vim plugin manager. First install the required packages, download the Vundle and then install the plugin using Vundle.

Install required packages

sudo apt install build-essential cmake python3-dev git vim

Download Vundle

git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim

Add configuration to vimrc file

Add the following lines to ~/.vimrc file

set nocompatible              " be iMproved, required
filetype off                  " required

" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()

" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'

" plugin on GitHub repo
Plugin 'ycm-core/YouCompleteMe'

" All of your Plugins must be added before the following line
call vundle#end()            " required
filetype plugin indent on    " required

Install YouCompleMe Plugin

Run the following command in terminal

vim +PluginInstall +qall

The installation might take upto a few minutes.

Installing language support for code completion

In this section, the instructions are given for C-family languages and TypeScript/JavaScript. For other languages, visit this.

Add support for C-family languages

Run the following commands in terminal.

cd ~/.vim/bundle/YouCompleteMe
python3 install.py --clangd-completer
Code compeltion for C language
Code compeltion for C language

Add support for JavaScript/TypeScript

Install Nodejs and npm and then run the following commands.

cd ~/.vim/bundle/YouCompleteMe
python3 install.py --ts-completer

Miscellaneous

Disabling the preview window

Sometimes I feel annoying when a preview windlow opens displaying the documentation for the C in-built functions or methods for JS. To disable the preview window, add the following line to ~/.vimrc file.

set completeopt-=preview

For complete documentation regarding YouCompleteMe plugin, visit the official source

-—–x–Happy Coding–x——