Configuring VIM
By Diwanshu Shekhar
- 3 minutes read - 527 wordsGenerally, vim installation comes with a .vim
diectory and .vimrc
file in your home directory. If these are not present in your directory, please feel free to create them manually.
Configurations for vim goes in the .vimrc file
and the plugins are stored in the .vim
directory.
Here is what my current .vimrc
configurations look like:
1 "Vundle Setup
2 set nocompatible " required
3 filetype off " required
4
5 " set the runtime path to include Vundle and initialize
6 set rtp+=~/.vim/bundle/Vundle.vim
7 call vundle#begin()
8 "
9 " " alternatively, pass a path where Vundle should
10 install plugins call vundle#begin('~/.vim/plugins')
11 "
12 " " let Vundle manage Vundle, required
13 Plugin 'gmarik/Vundle.vim'
14 "
15 " " Add all your plugins here (note older versions of Vundle
16 " used Bundle instead of Plugin)
17 Plugin 'tmhedberg/SimpylFold'
18 Bundle 'Valloric/YouCompleteMe'
19 Plugin 'jnurmine/Zenburn'
20
21 " All of your Plugins must be added before the following line
22 call vundle#end() " required
23 filetype plugin indent on " required
24
25 "vim native configuratiions
26 "
27 "This allows copy and paste between terminals
28 set clipboard=unnamed
29
30 " enable 256 color mode
31 set t_Co=256
32
33 " enable syntax highlighting
34 syntax on
35
36 " show line numbers
37 set number
38
39 " show the matching part of the pair for [] {} and ()
40 set showmatch
41
42 au BufNewFile,BufRead *.py
43 set tabstop=4
44 set softtabstop=4
45 set shiftwidth=4 " when using the >> or << commands
46 set textwidth=79
47 set expandtab
48 set autoindent
49 set fileformat=unix
50
51 au BufNewFile,BufRead *.js, *.html, *.css
52 set tabstop=2
53 set softtabstop=2
54 set shiftwidth=2
55
56 " plugin specific configs
57
58 "automatically load zenburn color scheme
59 colors zenburn
Installing plugins
The easiest way to install plugins in Vim is through Vundle. Its like PIP for Python. The instruction to setup Vundle is given in its github site. If you have git already installed, you can get Vundle by simply cloning the repository:
git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
After you setup Vundle, adding plugins to Vim is a matter of simply adding one line to your .vimrc
. For example,
Plugin 'tmhedberg/SimpylFold')
and relaunching vim and calling this command :PluginInstall
Some useful plugins
SimplyFold: This plugin is a really simple plugin for correctly folding your python code. Once installed, you can fold and unfold your python code by the commands: zc
(close) and zo
(open)
YouCompleteMe: This is a very extensive plugin that has auto-complete engines for various programming languages such as C, C++, JavaScript, Python among others. You can use ctrl+space
to trigger the completion suggestions anywhere and use tab to scroll through the suggestions.
Zenburn: This is a nice low-contrast color scheme for Vim. It’s easy for your eyes and designed to keep you in the zone for long programming sessions. If your vim doesn’t automatically load this color schema, you can activate it by command - :colors zenburn
and turn off by :colors default
. You may also need to set up 256 color in your .bashrc
or bash_profile
using export TERM=xterm-256color