Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
710 lines (606 sloc) 21.9 KB
" Maintainer: nouh: the vim hacker
" Version: 5.0 - 11/03/2016
"" => General
let mapleader=','
let maplocalleader='\'
set timeoutlen=500
autocmd BufWritePost $MYVIMRC source $MYVIMRC
nnoremap <Leader>e :edit $MYVIMRC<CR>
set title
set titlestring=%t%(\ %m%)%(\ (%{expand('%:p:h')})%)%(\ %a%)
set autoread " Set autoread when a file is changed outside
set autowrite " Write on make/shell commands
set hidden " Turn on hidden"
set history=1000 " Increase the lines of history
set modeline " Turn on modeline
set completeopt+=longest " Optimize auto complete
set completeopt-=preview " Optimize auto complete
set noerrorbells
set novisualbell
set mouse=a
set number
set ruler "Always show current position
set cmdheight=1 "The commandbar height
set backspace=eol,start,indent
set whichwrap+=<,>,h,l
set nolazyredraw "Don't redraw while executing macros
set mat=2 "How many tenths of a second to blink
" Set directories
function! InitializeDirectories()
let parent=$HOME
let prefix='.vim'
let dir_list={
\ 'backup': 'backupdir',
\ 'view': 'viewdir',
\ 'swap': 'directory',
\ 'undo': 'undodir',
\ 'cache': '',
\ 'session': ''}
for [dirname, settingname] in items(dir_list)
let directory=parent.'/'.prefix.'/'.dirname.'/'
if !isdirectory(directory)
if exists('*mkdir')
call mkdir(directory, 'p')
echo 'Warning: Unable to create directory: '.directory
if settingname!=''
exec 'set '.settingname.'='.directory
call InitializeDirectories()
if has('win32') || has('win64')
set runtimepath=$HOME/.vim,$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after,$HOME/.vim/after
let g:bundle_groups=['ui', 'enhance', 'move', 'navigate',
\'complete', 'compile', 'git', 'language']
if has('vim_starting')
set nocompatible
set runtimepath+=~/.vim/bundle/neobundle.vim/
call neobundle#begin(expand('~/.vim/bundle/'))
NeoBundleFetch 'shougo/neobundle.vim'
if count(g:bundle_groups, 'ui') " UI setting
NeoBundle 'w0ng/vim-hybrid' " Colorscheme hybrid
NeoBundle 'altercation/vim-colors-solarized' " Colorscheme solarized
NeoBundle 'chriskempson/base16-vim' " Colorscheme base16
NeoBundle 'bling/vim-airline' " Status line
NeoBundle 'vim-airline/vim-airline-themes'
NeoBundle 'bling/vim-bufferline' " Buffer line
NeoBundle 'nathanaelkane/vim-indent-guides' " Indent guides
NeoBundle 'mhinz/vim-startify' " Start page
if count(g:bundle_groups, 'enhance') " Vim enhancement
NeoBundle 'rizzatti/dash.vim'
NeoBundle 'jiangmiao/auto-pairs'
NeoBundle 'tpope/vim-vinegar'
NeoBundle 'tpope/vim-obsession'
NeoBundle 'ryanoasis/vim-devicons'
NeoBundle 'tpope/vim-eunuch' "helps for Unix
NeoBundle 'tpope/vim-rsi'
" NeoBundle 'Raimondi/delimitMate' " Closing of quotes
NeoBundle 'scrooloose/nerdcommenter' " NERD commenter
NeoBundle 'tpope/vim-commentary' "commentary
NeoBundle 'tpope/vim-abolish' " Abolish
NeoBundle 'tpope/vim-speeddating' " Speed dating
NeoBundle 'tpope/vim-repeat' " Repeat
NeoBundle 'terryma/vim-multiple-cursors' " Multiple cursors
NeoBundle 'mbbill/undotree' " Undo tree
NeoBundle 'tpope/vim-surround' " Surround
NeoBundle 'godlygeek/tabular' " Tabular
NeoBundle 'AndrewRadev/splitjoin.vim' " Splitjoin
NeoBundle 'sickill/vim-pasta' " Vim pasta
NeoBundle 'Keithbsmiley/investigate.vim' " Helper
NeoBundle 'wikitopian/hardmode' " Hard mode
NeoBundle 'wellle/targets.vim' " Text objects
NeoBundle 'roman/golden-ratio' " Resize windows
if count(g:bundle_groups, 'move') " Moving
NeoBundle 'tpope/vim-unimpaired' " Pairs of mappings
NeoBundle 'Lokaltog/vim-easymotion' " Easy motion
NeoBundle 'bkad/CamelCaseMotion' " Camel case motion
NeoBundle 'majutsushi/tagbar' " Tag bar
NeoBundle 'edsono/vim-matchit' " Match it
NeoBundle 'Shougo/unite.vim' " Search engine
NeoBundle 'Shougo/unite-outline' " Unite outline
NeoBundle 'Shougo/vimproc', {
\ 'build' : {
\ 'windows' : 'make -f make_mingw32.mak',
\ 'cygwin' : 'make -f make_cygwin.mak',
\ 'mac' : 'make -f make_mac.mak',
\ 'unix' : 'make -f make_unix.mak',
\ },
\ }
if count(g:bundle_groups, 'navigate') " Navigation
NeoBundle 'kien/ctrlp.vim' "Ctrlp
NeoBundle 'scrooloose/nerdtree' " NERD tree
NeoBundle 'Xuyuanp/nerdtree-git-plugin'
if count(g:bundle_groups, 'complete') " Completion
if has('lua')
NeoBundle 'Shougo/neocomplete.vim' " Auto completion framework
let g:completion_engine='neocomplete'
NeoBundle 'Shougo/neocomplcache.vim' " Auto completion framework
let g:completion_engine='neocomplcache'
NeoBundle 'Shougo/neosnippet.vim' " Snippet engine
NeoBundle 'Shougo/neosnippet-snippets' " Snippets
NeoBundle 'honza/vim-snippets' " Snippets
if count(g:bundle_groups, 'compile') " Compiling
NeoBundle 'scrooloose/syntastic' " Syntax checking
if count(g:bundle_groups, 'git') " Git
NeoBundle 'tpope/vim-fugitive' " Git wrapper
NeoBundle 'tpope/vim-git' "Git runtime
NeoBundle 'gregsexton/gitv' " Gitk clone
if has('signs')
NeoBundle 'airblade/vim-gitgutter' " Git diff sign
if count(g:bundle_groups, 'language') " Language Specificity
"NeoBundle 'matthias-guenther/hammer.vim' " Markup
NeoBundle 'tpope/vim-rails' " Rails
NeoBundle 'tpope/vim-endwise' "add end for ruby
NeoBundle 'mattn/emmet-vim' " Emmet
NeoBundle 'LaTeX-Box-Team/LaTeX-Box' " LaTex
NeoBundle 'sheerun/vim-polyglot' " Language Support
call neobundle#end()
filetype plugin indent on
function! MySys()
if has("win32") || has("win64")
return "windows"
elseif has("x11")
return "linux"
return "mac"
set langmenu=en_US
let $LANG = 'en_US'
source $VIMRUNTIME/delmenu.vim
source $VIMRUNTIME/menu.vim
" Encoding
filetype indent on
lang en_US
set encoding=utf-8 " Set utf-8 encoding
set termencoding=utf-8
set fileencoding=utf-8
set fileencodings=ucs-bom,utf-8,cp936,gb18030,big5,euc-jp,euc-kr,latin1
" Searching and Replacing
set ignorecase
set smartcase
set gdefault
set incsearch
set showmatch
set hlsearch
set pastetoggle=<F10>
" Use sane regexes
nnoremap / /\v
vnoremap / /\v
cnoremap s/ s/\v
nnoremap ? ?\v
vnoremap ? ?\v
cnoremap s? s?\v
" Keep search matches in the middle of the window
nnoremap n nzzzv
nnoremap N Nzzzv
nnoremap * *zzzv
nnoremap # #zzzv
nnoremap g* g*zzzv
nnoremap g# g#zzzv
nnoremap <Leader><Space> :set hlsearch!<CR>
" => Colors and Fonts and UI
syntax enable "Enable syntax hl
set background=dark
" Set font according to system
if count(g:bundle_groups, 'ui')
colorscheme hybrid
colorscheme desert
if has("gui_running")
if(MySys() == "mac")
set guifont=Inconsolata\ for\ Powerline\:h15
elseif MySys() == "windows"
set guifont=Consolas:h11
elseif MySys() == "linux"
set gfn=DejaVu\ Sans\ Mono\ 11
set guioptions=
set t_Co=256
set ffs=unix,dos,mac "Default file types
set laststatus=2 " Show the statusline
set noshowmode " Hide the default mode text
set ttimeoutlen=50
autocmd WinLeave * set nocursorline
autocmd WinEnter * set cursorline
autocmd InsertEnter * set nocursorline
autocmd InsertLeave * set cursorline
set wildmenu " Show list instead of just completing
set wildmode=list:longest,full " Use powerful wildmenu
set shortmess=at " Avoids hit enter
set showcmd " Show cmd
set backspace=indent,eol,start " Make backspaces delete sensibly
set whichwrap+=h,l,<,>,[,] " Backspace and cursor keys wrap to
set virtualedit=block,onemore " Allow for cursor beyond last character
set scrolljump=5 " Lines to scroll when cursor leaves screen
set scrolloff=3 " Minimum lines to keep above and below cursor
set sidescroll=1 " Minimal number of columns to scroll horizontally
set sidescrolloff=10 " Minimal number of screen columns to keep away from cursor
set showmatch " Show matching brackets/parenthesis
set matchtime=2 " Decrease the time to blink
" => backups and undo
" Turn backup off, since most stuff is in SVN, git anyway...
set nobackup
set nowb
set noswapfile
set undofile
set undodir=$HOME/.vim/undo
set undoreload=1000
set undolevels=10000
" => Indentation and list and wrap
set autoindent
set smartindent
set expandtab
set shiftwidth=2
set tabstop=2
set softtabstop=2
set smarttab
set formatoptions+=rnlmM " Optimize format options
set textwidth=500
set wrap
set list " Show these tabs and spaces and so on
set listchars=tab:▸\ ,eol:¬,extends:❯,precedes: " Change listchars
set linebreak " Wrap long lines at a blank
set showbreak= " Change wrap line break
set fillchars=diff:⣿,vert:│ " Change fillchars
augroup trailing " Only show trailing whitespace when not in insert mode
autocmd InsertEnter * :set listchars-=trail:
autocmd InsertLeave * :set listchars+=trail:
augroup END
" => Fold Related
set foldlevelstart=0 " Start with all folds closed
set foldcolumn=1 " Set fold column
" Space to toggle and create folds.
nnoremap <silent> <Space> @=(foldlevel('.') ? 'za' : '\<Space>')<CR>
vnoremap <Space> zf
" Set foldtext
function! MyFoldText()
let line=getline(v:foldstart)
let nucolwidth=&foldcolumn+&number*&numberwidth
let windowwidth=winwidth(0)-nucolwidth-3
let foldedlinecount=v:foldend-v:foldstart+1
let onetab=strpart(' ', 0, &tabstop)
let line=substitute(line, '\t', onetab, 'g')
let line=strpart(line, 0, windowwidth-2-len(foldedlinecount))
let fillcharcount=windowwidth-len(line)-len(foldedlinecount)
return line.''.repeat(' ',fillcharcount).foldedlinecount.'L'.' '
set foldtext=MyFoldText()
" => Command mode related
" Bash like keys for the command line
cnoremap <C-A> <Home>
cnoremap <C-E> <End>
cnoremap <C-K> <C-U>
cnoremap <C-P> <Up>
cnoremap <C-N> <Down>
func! DeleteTillSlash()
let g:cmd = getcmdline()
if MySys() == "linux" || MySys() == "mac"
let g:cmd_edited = substitute(g:cmd, "\\(.*\[/\]\\).*", "\\1", "")
let g:cmd_edited = substitute(g:cmd, "\\(.*\[\\\\]\\).*", "\\1", "")
if g:cmd == g:cmd_edited
if MySys() == "linux" || MySys() == "mac"
let g:cmd_edited = substitute(g:cmd, "\\(.*\[/\]\\).*/", "\\1", "")
let g:cmd_edited = substitute(g:cmd, "\\(.*\[\\\\\]\\).*\[\\\\\]", "\\1", "")
return g:cmd_edited
" => Useful mappings
nnoremap 0 ^
nnoremap \ $
omap \ $
"Quick Escaping
inoremap jk <ESC>
cnoremap jk <ESC>
"Operator mapping
omap t it
omap " i"
omap w iw
"Useful when moving accross long lines
nnoremap j gj
nnoremap k gk
vnoremap j gj
vnoremap k gk
" Smart way to move between windows
nnoremap <C-j> <C-W>j
nnoremap <C-k> <C-W>k
nnoremap <C-h> <C-W>h
nnoremap <C-l> <C-W>l
nnoremap = <c-w>>
nnoremap - <c-w><
nnoremap + <c-w>+
nnoremap _ <c-w>-
nnoremap <leader>v <C-w>v<C-w>l
nnoremap <leader>s <C-w>s<C-w>j
" Reselect visual block after indent/outdent
vnoremap < <gv
vnoremap > >gv
nnoremap J mzJ`z
" When pressing <leader>cd switch to the directory of the open buffer
map <leader>cd :cd %:p:h<cr>
cmap w!! w !sudo tee % >/dev/null
" nnoremap <leader><space> <c-^>
" Strip all trailing whitespace in the current file
nnoremap <Leader>q :%s/\s\+$//<CR>:let @/=''<CR>
" See the differences between the current buffer and the file it was loaded from
command! DiffOrig vert new | set bt=nofile | r ++edit # | 0d_
\ | diffthis | wincmd p | diffthis
"nnoremap <leader>P pV`]=
"noremap <leader>y "*y
"noremap <leader>yy "*Y
" => Plugin Setting
" Setting for UI plugins
if count(g:bundle_groups, 'ui')
" -> Indent Guides
if !has('gui_running')
let g:indent_guides_auto_colors=0
autocmd VimEnter,Colorscheme * :hi IndentGuidesOdd ctermbg=235
autocmd VimEnter,Colorscheme * :hi IndentGuidesEven ctermbg=235
let g:indent_guides_enable_on_vim_startup=0
let g:indent_guides_guide_size=1
let g:indent_guides_default_mapping=0
let g:indent_guides_exclude_filetypes=['help', 'nerdtree', 'startify', 'markdown']
" -> Startify
let g:startify_session_dir=$HOME . '/.vim/session'
let g:startify_custom_header=[
\' _ ',
\' __ __(_)___ ___ ',
\' | | / / / __ `__ \ ',
\' | |/ / / / / / / / ',
\' |___/_/_/ /_/ /_/ ',
\' ']
let g:startify_custom_footer=['', ' This configuration is maintained by Zach Zhao <> and other contributors. Thanks!']
if has('gui_running')
hi StartifyHeader guifg=#87afff
hi StartifyFooter guifg=#87afff
hi StartifyBracket guifg=#585858
hi StartifyNumber guifg=#ffaf5f
hi StartifyPath guifg=#8a8a8a
hi StartifySlash guifg=#585858
hi StartifyHeader ctermfg=111
hi StartifyFooter ctermfg=111
hi StartifyBracket ctermfg=240
hi StartifyNumber ctermfg=215
hi StartifyPath ctermfg=245
hi StartifySlash ctermfg=240
let g:bufferline_echo=0
let g:bufferline_modified='[+]'
let g:airline_theme='bubblegum'
let g:airline_powerline_fonts=1
" Setting for enhancement plugins
if count(g:bundle_groups, 'enhance')
" -> NERD Commenter
let NERDCommentWholeLinesInVMode=2
let NERDSpaceDelims=1
let NERDRemoveExtraSpaces=1
" nmap <leader>/ :call NERDComment(0, "invert")<cr>
" vmap <leader>/ :call NERDComment(0, "invert")<cr>
" Map \<Space> to commenting
function! IsWhiteLine()
if (getline('.')=~'^$')
let oldlinenumber=line('.')
call NERDComment('n', 'sexy')
if (line('.')==oldlinenumber)
call NERDComment('n', 'append')
normal! k
normal! A
call NERDComment('n', 'append')
nnoremap <silent> <LocalLeader><Space> :call IsWhiteLine()<CR>
" -> Undo tree
nnoremap <Leader>u :UndotreeToggle<CR>
let g:undotree_WindowLayout = 'botright'
let g:undotree_SetFocusWhenToggle=1
" -> Splitjoin
let g:splitjoin_split_mapping = ',s'
let g:splitjoin_join_mapping = ',j'
let g:splitjoin_normalize_whitespace=1
let g:splitjoin_align=1
" -> investigate.vim
nnoremap K :call investigate#Investigate()<CR>
" setting for moving plugins
if count(g:bundle_groups, 'move')
" -> Tag bar
nnoremap <Leader>t :TagbarToggle<CR>
let g:tagbar_autofocus=1
let g:tagbar_expand=1
let g:tagbar_foldlevel=2
let g:tagbar_autoshowtag=1
" Matchit
" Use Tab instead of % to switch
nmap <Tab> %
vmap <Tab> %
" -> Unite
let g:unite_data_directory=$HOME . '/.vim/cache/unite'
let g:unite_source_history_yank_enable=1
let g:unite_source_rec_max_cache_files=100
let g:unite_prompt='» '
nnoremap <leader>a :Ack!<space>
if executable('ag')
" Use ag in unite grep source.
let g:unite_source_grep_command='ag'
let g:unite_source_grep_default_opts='--line-numbers --nocolor --nogroup --hidden'
let g:unite_source_grep_recursive_opt=''
elseif executable('ack-grep')
" Use ack-grep in unite grep source.
let g:unite_source_grep_command='ack-grep'
let g:unite_source_grep_default_opts='--no-heading --no-color -a -H'
let g:unite_source_grep_recursive_opt=''
elseif executable('ack')
" Use ack in unite grep source.
let g:unite_source_grep_command='ack'
let g:unite_source_grep_default_opts='--no-heading --no-color -a -H'
let g:unite_source_grep_recursive_opt=''
function! s:unite_settings() " Use ESC to exit, and use C-J and C-K to move
nmap <buffer> <ESC> <plug>(unite_exit)
imap <buffer> <ESC> <plug>(unite_exit)
imap <buffer> <C-J> <Plug>(unite_select_next_line)
imap <buffer> <C-K> <Plug>(unite_select_previous_line)
autocmd filetype unite call s:unite_settings()
nnoremap <silent> <Space>f :<C-U>Unite -start-insert -auto-resize -buffer-name=files file_rec/async<CR><C-U>
nnoremap <silent> <Space>y :<C-U>Unite -start-insert -buffer-name=yanks history/yank<CR>
nnoremap <silent> <Space>l :<C-U>Unite -start-insert -auto-resize -buffer-name=line line<CR>
nnoremap <silent> <Space>o :<C-U>Unite -auto-resize -buffer-name=outline outline<CR>
nnoremap <silent> <Space>b :<C-U>Unite -quick-match buffer<CR>
nnoremap <silent> <Space>t :<C-U>Unite -quick-match tab<CR>
nnoremap <silent> <Space>/ :<C-U>Unite -auto-resize -buffer-name=search grep:.<CR>
" Setting for navigation plugins
if count(g:bundle_groups, 'navigate')
" -> NERD Tree
nnoremap <Leader>n :NERDTreeToggle<CR>
nnoremap <Leader>f :NERDTreeFind<CR>
let NERDTreeChDirMode=2
let NERDTreeShowBookmarks=1
let NERDTreeShowHidden=1
let NERDTreeShowLineNumbers=1
let NERDTreeDirArrows=1
let g:nerdtree_open_on_gui_startup=0
" -> Ctrlp
let g:ctrlp_cmd = 'CtrlP'
let g:ctrlp_map = '<leader>p'
let g:ctrlp_working_path_mode = 2
let g:ctrlp_custom_ignore = {
\ 'dir': '\.git$\|\.hg$\|\.svn$\|node_modules$',
\ 'file': '\.exe$\|\.so$\|\.dll$' }
let g:ctrlp_reuse_window = 'netrw\|help\|quickfix'
nnoremap <leader>b :CtrlPBuffer<cr>
nnoremap <leader>m :CtrlPMRU<cr>
" Setting for completion plugins
if count(g:bundle_groups, 'complete')
" -> Neocomplete & Neocomplcache
" Use Tab and S-Tab to select candidate
inoremap <expr><Tab> pumvisible() ? "\<C-N>" : "\<Tab>"
inoremap <expr><S-Tab> pumvisible() ? "\<C-P>" : "\<S-Tab>"
if g:completion_engine=='neocomplete'
let g:neocomplete#enable_at_startup=1
let g:neocomplete#data_directory=$HOME . '/.vim/cache/neocomplete'
let g:neocomplete#enable_auto_delimiter=1
" Use <C-E> to close popup
inoremap <expr><C-E> neocomplete#cancel_popup()
let g:neocomplcache_enable_at_startup=1
let g:neocomplcache_temporary_dir=$HOME . '/.vim/cache/neocomplcache'
let g:neocomplcache_enable_auto_delimiter=1
let g:neocomplcache_enable_fuzzy_completion=1
" Use <C-E> to close popup
inoremap <expr><C-E> neocomplcache#cancel_popup()
inoremap <expr><CR> delimitMate#WithinEmptyPair() ?
\ "\<C-R>=delimitMate#ExpandReturn()\<CR>" :
\ pumvisible() ? neocomplcache#close_popup() : "\<CR>"
" -> Neosnippet
" Set information for snippets
let g:neosnippet#enable_snipmate_compatibility=1
" Use <C-K> to expand or jump snippets in insert mode
imap <C-K> <Plug>(neosnippet_expand_or_jump)
" Use <C-K> to replace TARGET within snippets in visual mode
xmap <C-K> <Plug>(neosnippet_start_unite_snippet_target)
" For snippet_complete marker
if has('conceal')
set conceallevel=2 concealcursor=i
" Setting for compiling plugins
if count(g:bundle_groups, 'compile')
" -> Syntastic
set statusline+=%#warningmsg#
set statusline+=%{SyntasticStatuslineFlag()}
set statusline+=%*
let g:syntastic_always_populate_loc_list = 1
let g:syntastic_auto_loc_list = 1
let g:syntastic_check_on_open = 1
let g:syntastic_check_on_wq = 0
" let g:syntastic_check_on_open=1
" let g:syntastic_aggregate_errors=1
" let g:syntastic_auto_jump=1
" let g:syntastic_auto_loc_list=1
" let g:syntastic_error_symbol = '✗'
" let g:syntastic_style_error_symbol = '✠'
" let g:syntastic_warning_symbol = '∆'
" let g:syntastic_style_warning_symbol = '≈'
" Setting for git plugins
if count(g:bundle_groups, 'git')
" -> Fugitive
nnoremap <silent> <leader>gs :Gstatus<CR>
nnoremap <silent> <leader>gd :Gdiff<CR>
nnoremap <silent> <leader>gc :Gcommit<CR>
nnoremap <silent> <leader>gb :Gblame<CR>
nnoremap <silent> <leader>gl :Glog<CR>
nnoremap <silent> <leader>gp :Git push<CR>
autocmd QuickFixCmdPost *grep* cwindow
" Setting for language specificity
if count(g:bundle_groups, 'language')
autocmd BufNewFile,BufReadPost *.md set filetype=markdown
" -> Emmet
" let g:user_emmet_leader_key='<C-E>'
let g:user_emmet_settings={'indentation':' '}
let g:use_emmet_complete_tag=1