Vim Plugins
We already have a workable environment with vim, but let’s make it feel like home. Vim is popular because it is customizable through plug-ins. There are some options to install plug-ins in vim but let’s stick with one for this tutorial: vim-plug
. To install please enter the following code in the terminal:
curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
Add a vim-plug section to your ~/.vimrc
through the command:
vim ~/.vimrc
Now write the following, begin the section with ‘call plug#begin()’ and list the plugins with ‘Plug’ commands.
call plug#begin('~/.vim/plugged')
Plug 'dracula/vim', { 'as': 'dracula' }
call plug#end()
colorscheme dracula
Here, we are installing the dracula theme for testing our plugin system. Save the file and reload vim. Then use this command to install the plugin.
:PlugInstall
After restarting vim it should look like this:
Under the call plug#end()
line we can configure our vim editor with the set
method.
call plug#begin('~/.vim/plugged')
Plug 'dracula/vim', { 'as': 'dracula' }
call plug#end()
" Vim config vars
colorscheme dracula
set number
set ruler
set tabstop=4
set shiftwidth=4
set smarttab
set expandtab
set laststatus=2
set cursorline
This configuration will add a ruler of number for the code, add an always visible status line, highlight the current cursor line, and set the tab and indentation variables.
Other Plugins
There are plenty of plugins to add to your vim, here I suggest some of them.
Note: tagbar has a dependency that need to be installled through apt-get: exuberant-ctags
. To install this dependency:
sudo apt-get update && sudo apt-get install -y exuberant-ctags
Now, this is the complete .vimrc
config file:
call plug#begin('~/.vim/plugged')
Plug 'dracula/vim', { 'as': 'dracula' }
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
Plug 'scrooloose/nerdtree'
Plug 'majutsushi/tagbar'
Plug 'Townk/vim-autoclose'
call plug#end()
" vim config vars
colorscheme dracula
set number
set ruler
set tabstop=4
set shiftwidth=4
set smarttab
set expandtab
set laststatus=2
set cursorline
" Plugins cofig vars
" Airline
let g:airline#extensions#tabline#enabled = 1
let g:airline_powerline_fonts = 1
let g:airline_theme='hybrid'
let g:hybrid_custom_term_colors = 1
let g:hybrid_reduced_contrast = 1
" NERDTree
map <C-n> :NERDTreeToggle<CR>
map <C-m> :TagbarToggle<CR>
autocmd VimEnter * NERDTree
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif
Let’s see how it looks like in a project. Return to the project previously created and type vim .
That’s it, in the next post we will be adding OmniSharper to the mix.