Neovim Customization

Post Details
This is an old post and I dont use this config anymore. I have made a better version which you can copy from my github.

Why use vim and neovim over other text editors and IDEs?

For me, I’ve always loved minimalism and performance over ease of use and other flashy bloat no one really uses and cares about. This why I personally use Terminal-based text editors. Preferably VIM or Neovim. Tho I currently, am running Neovim, but both of them are basically the same. NeoVIM is a little bit more extensible than VIM and easy to manage imo. But enough talking, lets start configuring our VIM/NVIM to make it more like an actual developing environment.

IMPORTANT: Since I mainly use Neovim, some of the stuff written in this blog might not work for vim users, for them just avoid the once that are not compatible, if I find any alternatives to those plugins and setting, I will update the blogs with the details.

Step 1: Setting up the config files and directory for vim and neovim1

Follow the commands given below to make all the necessary files and directories for neovim

1cd
2mkdir -p ~/.config/nvim
3touch ~/.config/nvim/init.vim

The init.vim file is the config file that we will edit in this post to make our base neovim to look and act like an actual IDE.

Step 2: Editing the init.vim file

To edit this init.vim open the file with the text editor of your choice and paste the following text

1:set number
2:set relativenumber
3:set autoindent
4:set expandtab
5:set tabstop = 4
6:set shiftwidth = 4
7:set smarttab
8:set softtabstop = 4

These parameters set basic functionality for vim such as number lines, auto indentation, amd smart tabs. By default vim doesnt support mouse and its kinda normal to not use mouse since everything in vim can be done using the keyboard but if you are a soy and want to use mouse type this this too

1:set mouse = a

For now we have done all the basic settings.

Step 3: Adding a Plug-In Manager

For this setup we will use Vim-Plug to manage our plugins.

  1. Install Curl
    Debian-based

    1apt install curl
    

    Gentoo

    1emerge curl
    

    OpenBSD

    1pkg_add curl
    

    Arch-based

    1pacman -S curl
    

    Void

    1xbps-install -S curl
    
  2. Create the installation directories, download, and install Vim-Plug.

1 curl -fLo ~/.vim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim

Step 4: Installing Plug-ins

In your init.vim file, add these lines at the bottom of what we previously wrote.

1call plug#begin()
2
3
4
5call plug#end()

We will be able to add plugins in between the two commands.

Now we will add our first plug-in

Find the desireable plug-ins from VIM Awesome this is one of the best places to find vim and neovim plugins.
For this tutorial we will add couple of plug-ins to make our neovim look good and work like an ide.

 1Plug 'tpope/vim-fugitive'                   " Git integration in to nvim
 2Plug 'Yggdroot/indentLine'                  " Line Indentations
 3Plug 'farmergreg/vim-lastplace'             " Continue from where you left last time
 4Plug 'raimondi/delimitmate'                 " Provides insert mode auto-completion for special-characters
 5Plug 'tpope/vim-markdown'                   " Markdown runtime files
 6Plug 'tpope/vim-surround'                   " Change paranthesis and quotes into other forms quickly
 7Plug 'scrooloose/nerdtree'                  " File navigator
 8Plug 'vim-scripts/indentpython.vim'         " Indentation script for python
 9Plug 'alvan/vim-closetag'                   " Makes a close tag for html quickly
10Plug 'luochen1990/rainbow'                  " Provides different colors to different paranthesis
11Plug 'airblade/vim-gitgutter'               " Shows git diffs in the sign columns
12Plug 'lilydjwg/colorizer'                   " Provides color for the #rrggbb or #rgb color format in files
13Plug 'vim-airline/vim-airline'              " Powerline Theme / Status line
14Plug 'vim-airline/vim-airline-themes'       " Themes for vim-airline
15Plug 'rafi/awesome-vim-colorschemes'        " Change colorschemes on the fly for vim and nvim
16Plug 'ryanoasis/vim-devicons'               " Icons
17Plug 'SirVer/ultisnips'                     " Code completion using snippets from vim-snippets and custom snippets
18Plug 'honza/vim-snippets'                   " Provides snippets for ultisnips

First of all add few keybinding to open up NERDTree and make vertical and horizontal splits in your init.nvim.

1nnoremap <C-f> :NERDTreeFocus<CR>
2nnoremap <C-n> :NERDTree<CR>
3nnoremap <C-t> :NERDTreeToggle<CR>
4nnoremap <A-h> :vsplit<CR>
5nnoremap <A-k> :split<CR>

After you’ve saved and exited the file now open up neovim run :PlugInstall. This will install all the plugins in the plugged directory in .local/share/nvim/plugged/.

Since we installed vim airline and vim colorschemes we can change the look and feel of neovim/vim. Find your favorite vim colorscheme here also find your favorite airline theme here
For this blog, we will use the gruvbox theme along with the base16 airline theme. To make this permanent write these in your nvim config.

1colorscheme gruvbox
2
3let g:airline_left_sep = ''
4let g:airline_left_alt_sep = ''
5let g:airline_right_sep = ''
6let g:airline_right_alt_sep = ''
7let g:airline_theme='base16'

Since we also have a plugin for autoindentation and indent lines. We have to add these lines to the config too.

1let g:indentLine_fileTypeExclude = ["help", "nerdtree", "diff"]
2let g:indentLine_fileTypeExclude = ["help", "nerdtree", "diff", "markdown"]
3let g:indentLine_bufTypeExclude = ["help", "terminal"]
4let g:indentLine_showFirstIndentLevel = 1
5let g:indentLine_indentLevel = 7
6let g:indentLine_char_list = ['|', '¦', '┆', '┊']

(OPTIONAL)Adding Code-suggestions

This section is a bit tidious and is only available for neovim users so if you use vim this section is irrelevnet to you.
Add this plug-in in your init.vim file.

1Plug 'neoclide/coc.nvim'                    " Code suggestions and completion

Now this plugin wont run without nodejs in your machine so follow these steps to make it work.

  1. Install Nodejs and npm

    Debian

    1apt install nodejs npm
    

    Arch

    1pacman -S nodejs npm
    

    Gentoo

    1emerge nodejs
    

    OpenBSD

    1pkg_add node
    

    Void

    1xbps-install nodejs
    

    For Other Distos and operating systems visit https://nodejs.org/en/download/package-manager/

  2. Additional Packages Install yarn

    1npm install yarn
    

    After yarn is finished installing, execute the following command

    1cd ~/.local/share/nvim/plugged/coc.nvim/
    2yarn install
    3yarn build
    

    Now open up an nvim install and check if any error is shown, if not then it is successfully installed. Otherwise check online for errors.

    From here on out check this github repository to find your desired language to use and ways to download the language server. This is a bit tidious process but here is one example.

(EXAMPLE)Installing the python language server

  1. Install python3 and python3-pip
  2. Install jedi from the pip repository
1pip install jedi
  1. Open up and nvim instance and run :CocInstall coc-python this will install the python module for Coc.

Follow this type of procedure to install all of your favorite language servers and have fun coding


  1. Jump back to the top ↩︎