" Chuan's vim config
" Part are adopted from the example config at:
" /usr/share/vim/vim64/vimrc_example.vim
" Last modifid: Nov 2015

" First install Vundle via the following command
" Vundle depends on 'git' and 'curl' to work
"git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim

" Use Vim settings, rather then Vi settings (much better!).
" This must be first, because it changes other options as a side effect.
" Also required by Vundle
set nocompatible

" Turn off filetype as required by Vundle
filetype off

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

" The NERD tree: file explorer
Plugin 'scrooloose/nerdtree'
map <C-n> :NERDTreeToggle<CR>

" vim-colors-solarized
Plugin 'altercation/vim-colors-solarized'

" vim-aireline: enhanced status bar
Plugin 'bling/vim-airline'

" EasyMotion
Plugin 'easymotion/vim-easymotion'

" fugitive.vim: git wrapper
Plugin 'tpope/vim-fugitive'

" ctrlp.vim
Plugin 'kien/ctrlp.vim'

" ack.vim
if executable('ag')
  Plugin 'mileszs/ack.vim'
  let g:ackprg = 'ag --nogroup --nocolor --column --smart-case'
endif

call vundle#end()

" Enable filetype setting
filetype plugin on
filetype indent on

" Enable highlight
syntax on

" No backup files with ~ suffix
set nobackup

" Use utf8 as default
set encoding=utf-8 " vim internal encoding
set fileencoding=utf-8 " new file encoding

" Get function usage help automatically
set showfulltag
" Show matching parentheses/brackets
set showmatch
" Show current vim mode
set showmode

" Set backgoud
set background=dark

" Allow backspacing over everything in insert mode
set bs=2
" Don't include character under cursor in selection
set selection=exclusive
" Use a scrollable menu for filename completions
set wildmenu
" Case-insensitive searching
set ignorecase

" Indentation
set et
set ts=2
set sw=2
set autoindent
set smartindent

" Buffer Switching:
"   F2 = next buffer
"   F3 = previous buffer
"   F4 = kill buffer
inoremap <F2> <Esc>:bn<CR>
inoremap <F3> <Esc>:bp<CR>
inoremap <F4> <Esc>:bd<CR>
noremap <F2> <Esc>:bn<CR>
noremap <F3> <Esc>:bp<CR>
noremap <F4> <Esc>:bd<CR>

" Show line numbers
"   F12 = turn on/off line numbers
map <F12> :set nu!<CR>

" Allow backspacing over everything in insert mode
set backspace=indent,eol,start

set history=50    " keep 50 lines of command line history
set ruler   " show the cursor position all the time
set showcmd   " display incomplete commands
set incsearch   " do incremental searching

" Don't use Ex mode, use Q for formatting
map Q gq

" Switch syntax highlighting on, when the terminal has colors
" Also switch on highlighting the last used search pattern.
if &t_Co > 2 || has("gui_running")
  set hlsearch
endif

colorscheme solarized
if has("gui_running") && has("win32")
  set fileencodings=ucs-bom,utf-8,latin1
  set guifont=Consolas:h10:cANSI
endif