So you've been using Vim for a while but you feel that you are missing some of the features of modern, hip editors. Or maybe you never used Vim but you're curious to try it out. Either way, this guide will help you get started and by the time we're done you'll have a complete development environment that is accessible anywhere through SSH, quick to start and with a small footprint.
You need a version of Vim that's at least 7.4. It should also be a full version, not the minimal kind of Vim that Ubuntu ships with by default.
Speaking of Ubuntu, its repos are outdated right now so you should use a PPA like this one. You can use homebrew to install MacVim on OS X. I haven't done this on Windows so you'll have to look into it yourself.
Vim Package Management
I feel that one of the most useful features Linux distros have is the package manager. It allows you to easily look for and install packages that enhance the core functionality of your software. Editors like Sublime Text have this as well with the help of plugins. Guess what, there are package management plugins for Vim too.
We'll be using Vundle. To install it, run this command (you'll need
git clone https://github.com/gmarik/vundle.git ~/.vim/bundle/vundle
Now that you have Vundle, I suggest having a config file to store the list of packages you want to use. This will become helpful when you want to duplicate the same Vim setup somewhere else.
Make sure you include it into your
.vimrc file. You can prepend "
source ~/.bundles.vim" to your
.vimrc file and all should be well.
After we set up the bundles file, we can install and/or update all the packages in there using this command:
vim -u ~/.bundles.vim +BundleInstall! +q
I usually have an
upvim alias for it.
Let me share a list of packages that I find useful in my Vim setup. You can install all of them using Vundle. I usually keep them in my
.bundles.vim file and just run the
upvim alias whenever I change something.
Bundle 'kien/ctrlp.vim' link
Provides fuzzy file and symbol matching, similar to what TextMate and Sublime Text have. Really fast.
Bundle 'bitc/vim-bad-whitespace' link
Highlights trailing whitespace.
Bundle 'ciaranm/detectindent' link
Automatically detects indent settings from files.
Bundle 'scrooloose/nerdcommenter' link
Really easy commenting/uncommenting.
Bundle 'scrooloose/nerdtree' link
Project explorer functionality.
Bundle 'scrooloose/syntastic' link
Syntax checks, linting.
Bundle 'majutsushi/tagbar' link
Displays a sidebar with the symbols in the current file (functions, classes etc.)
Bundle 'troydm/easybuffer.vim' link
Easy way to see and switch between open buffers (files).
Bundle 'jnurmine/Zenburn' link
The Zenburn color scheme.
Bundle 'mileszs/ack.vim' link
Friendly way of using ack from
within Vim. You need
ack installed to use this.
Bundle 'Lokaltog/vim-powerline' link
Bundle 'Gundo' link
Helps you use the undo tree Vim provides.
Bundle 'Valloric/YouCompleteMe' link
Smart, fast, fuzzy autocompletion engine for Vim. Please check the docs, after installing it with Vundle there are some extra-steps to do.
Tern for Vim
Bundle 'marijnh/tern_for_vim' link
Great autocompletion + "intellisense" support for JS. Please check the docs, after installing it with Vundle there are some extra-steps to do.
All the packages we talked about have great intro pages and documentation, but maybe you don't want to spend so much time on everything. I suggest starting off with my vimrc and change what doesn't fit your preference.
However, there are some settings that I find really useful and I'd like to mention here.
First, you can use Vim's
cc functionality to display a column in order to keep your line length in check. I use
You can use Zenburn as your color scheme with
CtrlP changes your cwd when selecting a new file. You can change this behavior with
let g:ctrlp_working_path_mode = ''. Also, I want it to search both among open buffers and files on the HDD, which is why I use
let g:ctrlp_cmd = 'CtrlPMixed'. Finally, I really like Sublime's go to symbol keybinding (CTRL+R), so I also use
map <C-R> :CtrlPBufTagAll<CR>.
If you choose to install DetectIndent, you need to turn it on:
" first two lines are up to you let g:detectindent_preferred_expandtab = 1 let g:detectindent_preferred_indent = 4 autocmd BufNewFile,BufReadPost * :DetectIndent autocmd FileType make setlocal noexpandtab
I bound my leader key to comma:
let mapleader = ",". This is useful for me in the NERD Commenter and NERD Tree keybindings:
map <leader>/ <plug>NERDCommenterToggle imap <leader>/ <Esc><plug>NERDCommenterTogglei map <leader>n :NERDTreeToggle<CR> nmap <leader>m :NERDTreeFind<CR>
NERD Commenter lets you comment/uncomment parts of your code and it's compatible with Vim's selection modes. NERD Tree's find functionality helps you locate the current file in the project's tree.
F8 to toggle TagBar and bring it in focus:
nmap <F8> :TagbarToggle<CR> let g:tagbar_autofocus = 1
Last but not least, you might want to check out the Vim Cheatsheet I wrote some time ago.