if empty(glob('~/.vim/autoload/plug.vim'))
  silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs
    \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
  autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif

set nocompatible              " be iMproved, required

" set the runtime path to include Vundle and initialize
if has("win32")
    call plug#begin('~/vimfiles/bundle')
else
    call plug#begin('~/.vim/bundle')
endif
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')


" The following are examples of different formats supported.
" Keep Plugin commands between vundle#begin/end.
" plugin on GitHub repo
" If you need Vim help for vim-plug itself (e.g. :help plug-options), register
" vim-plug as a plugin.
Plug 'junegunn/vim-plug'
Plug 'easymotion/vim-easymotion'
"Plug 'tpope/vim-fugitive'
Plug 'tpope/vim-repeat'
Plug 'tpope/vim-surround'
" Plugin 'vim-perl/vim-perl'
" markdown
Plug 'godlygeek/tabular'
Plug 'plasticboy/vim-markdown'
Plug 'scrooloose/nerdtree'
Plug 'scrooloose/nerdcommenter'
" 目录树美化
" Plug 'tiagofumo/vim-nerdtree-syntax-highlight'
Plug 'davidhalter/jedi-vim'
" Plug 'ervandew/supertab'
Plug 'Raimondi/delimitMate'
Plug 'tomasr/molokai'
Plug 'terryma/vim-multiple-cursors'

"show tabs
Plug 'nathanaelkane/vim-indent-guides'
Plug 'vim-scripts/taglist.vim'
Plug 'WolfgangMehner/vim-plugins'
" Plugin 'powerline/powerline', {'rtp': 'powerline/bindings/vim/'}
" Plugin 'Lokaltog/vim-powerline'
" Plugin 'bling/vim-airline'

" plugin from http://vim-scripts.org/vim/scripts.html
Plug 'vim-scripts/L9'
Plug 'christoomey/vim-tmux-navigator'
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
" syntax highlight for Dockerfile
" Plug 'ekalinin/Dockerfile.vim'
Plug 'hotoo/pangu.vim'
" Plug 'chr4/nginx.vim'
Plug 'mileszs/ack.vim'
" Plug 'jlanzarotta/bufexplorer'

" Plug 'mikelue/vim-maven-plugin'
" Plug 'w0rp/ale'
Plug 'mattn/emmet-vim', { 'for': ['html', 'javascript'] }
Plug 'MarcWeber/vim-addon-mw-utils'
Plug 'tomtom/tlib_vim'
" Plug 'garbas/vim-snipmate'
Plug 'ntpeters/vim-better-whitespace'
Plug '907th/vim-auto-save'
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': '.install -all'}
Plug 'junegunn/fzf.vim'
Plug 'Valloric/YouCompleteMe', { 'do': 'python3 install.py --all' }
Plug 'nathangrigg/vim-beancount'
Plug 'hashivim/vim-terraform'

" Git plugin not hosted on GitHub
Plug 'git://git.wincent.com/command-t.git'

call plug#end()


" Plugin settings

" plasticboy/vim-markdown
" disable folding
let g:vim_markdown_folding_disabled=1
" Highlight YAML frontmatter as used by Jekyll
let g:vim_markdown_frontmatter=1

" intend guides
let g:indent_guides_enable_on_vim_startup = 1

" jedi-vim plugin config
let g:jedi#completions_command = "<C-N>"
let g:jedi#popup_on_dot = 0

" syntastic setting
set statusline+=%#warningmsg#

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

" nerd comment
" Add spaces after comment delimiters by default
let g:NERDSpaceDelims = 1

" Use compact syntax for prettified multi-line comments
let g:NERDCompactSexyComs = 1

" Align line-wise comment delimiters flush left instead of following code indentation
let g:NERDDefaultAlign = 'left'

" Set a language to use its alternate delimiters by default
let g:NERDAltDelims_java = 1

" Add your own custom formats or override the defaults
let g:NERDCustomDelimiters = { 'c': { 'left': '/**','right': '*/' } }

" Allow commenting and inverting empty lines (useful when commenting a region)
let g:NERDCommentEmptyLines = 1

" Enable trimming of trailing whitespace when uncommenting
let g:NERDTrimTrailingWhitespace = 1

" Highlight Cursor line
let g:NERDTreeHighlightCursorline = 1
" Show hidden files
let NERDTreeShowHidden=1
" NERDTree will recursively open dirs with only one child
let NERDTreeCascadeOpenSingleChildDir=1


"" airline settings.
let g:airline_theme = 'luna'
let g:airline_powerline_fonts = 1

if !exists('g:airline_symbols')
  let g:airline_symbols = {}
endif

let g:airline_left_sep = ''
let g:airline_left_alt_sep = ''
let g:airline_right_sep = ''
let g:airline_right_alt_sep = ''
let g:airline_symbols.branch = ''
let g:airline_symbols.readonly = ''
let g:airline_symbols.linenr = ''
let g:airline#extensions#tabline#enabled = 1
" show absolute file path in status line
let g:airline_section_c = '%<%F%m %#__accent_red#%{airline#util#wrap(airline#parts#readonly(),0)}%#__restore__#'
" show tab number in tab line
let g:airline#extensions#tabline#tab_nr_type = 1

" Write all buffers before navigating from Vim to tmux pane
let g:tmux_navigator_save_on_switch = 2

" Disable tmux navigator when zooming the Vim pane
let g:tmux_navigator_disable_when_zoomed = 1

" ack.vim
" 使用 leader + a search
cnoreabbrev Ack Ack!
nnoremap <Leader>a :Ack!<Space>

if executable('ag')
  let g:ackprg = 'ag --vimgrep --nogroup --column'
endif

" 高亮搜索关键词
let g:ackhighlight = 1
" 修改预览窗口高度
let g:ack_qhandler = "botright copen 10"
" 在QuickFix窗口使用快捷键以后,自动关闭QuickFix窗口
let g:ack_autoclose = 1
" 使用ack的空白搜索,即不添加任何参数时对光标下的单词进行搜索,默认值为1,表示开启,置0以后使用空白搜索将返回错误信息
let g:ack_use_cword_for_empty_search = 1
" 部分功能受限,对大项目搜索速度较慢时可以尝试开启
let g:ack_use_dispatch = 1
" autofold results
let g:ack_autofold_results = 1

let g:auto_save = 1  " enable AutoSave on Vim startup

" An action can be a reference to a function that processes selected lines
function! s:build_quickfix_list(lines)
  call setqflist(map(copy(a:lines), '{ "filename": v:val }'))
  copen
  cc
endfunction

let g:fzf_action = {
  \ 'ctrl-q': function('s:build_quickfix_list'),
  \ 'ctrl-t': 'tab split',
  \ 'ctrl-x': 'split',
  \ 'ctrl-v': 'vsplit' }

" Default fzf layout
" - down / up / left / right
let g:fzf_layout = { 'down': '~40%' }

let g:fzf_history_dir = '~/.local/share/fzf-history'

" https://github.com/tiagofumo/vim-nerdtree-syntax-highlight
let g:WebDevIconsDisableDefaultFolderSymbolColorFromNERDTreeDir = 1
let g:WebDevIconsDisableDefaultFileSymbolColorFromNERDTreeFile = 1

let g:NERDTreeDisableFileExtensionHighlight = 1
let g:NERDTreeDisableExactMatchHighlight = 1
let g:NERDTreeDisablePatternMatchHighlight = 1

" you can add these colors to your .vimrc to help customizing
let s:brown = "905532"
let s:aqua =  "3AFFDB"
let s:blue = "689FB6"
let s:darkBlue = "44788E"
let s:purple = "834F79"
let s:lightPurple = "834F79"
let s:red = "AE403F"
let s:beige = "F5C06F"
let s:yellow = "F09F17"
let s:orange = "D4843E"
let s:darkOrange = "F16529"
let s:pink = "CB6F6F"
let s:salmon = "EE6E73"
let s:green = "8FAA54"
let s:lightGreen = "31B53E"
let s:white = "FFFFFF"
let s:rspec_red = 'FE405F'
let s:git_orange = 'F54D27'

let g:NERDTreeExtensionHighlightColor = {} " this line is needed to avoid error
let g:NERDTreeExtensionHighlightColor['css'] = s:blue " sets the color of css files to blue

let g:NERDTreeExactMatchHighlightColor = {} " this line is needed to avoid error
let g:NERDTreeExactMatchHighlightColor['.gitignore'] = s:git_orange " sets the color for .gitignore files

let g:NERDTreePatternMatchHighlightColor = {} " this line is needed to avoid error
let g:NERDTreePatternMatchHighlightColor['.*_spec\.rb$'] = s:rspec_red " sets the color for files ending with _spec.rb

let g:WebDevIconsDefaultFolderSymbolColor = s:beige " sets the color for folders that did not match any rule
let g:WebDevIconsDefaultFileSymbolColor = s:blue " sets the color for files that did not match any rule

let g:snipMate = {'snippet_version': 1}

" beancount
filetype plugin on
set omnifunc=syntaxcomplete#Complete
let g:beancount_root = "~/Sync/beancount/main.bean"
let g:beancount_account_completion = 'chunks'
let g:beancount_detailed_first = 1
autocmd FileType bean inoremap . .<c-o>:AlignCommodity<cr>
autocmd FileType bean inoremap <Tab> <c-x><c-o>

let b:beancount_root = '~/Sync/beancount/main.bean'