call plug#begin('~/.vim/plugged')

Plug 'altercation/vim-colors-solarized'
Plug 'tpope/vim-fugitive'
Plug 'vim-perl/vim-perl'
Plug 'nvie/vim-flake8'
Plug 'tpope/vim-surround'
Plug 'mileszs/ack.vim'
Plug 'xolox/vim-misc'
Plug 'xolox/vim-notes'
Plug 'scrooloose/nerdtree'
" Plug 'jistr/vim-nerdtree-tabs'
Plug 'mkitt/tabline.vim'
Plug 'majutsushi/tagbar'
Plug 'bling/vim-airline'
Plug 'pangloss/vim-javascript'
Plug 'mxw/vim-jsx'
Plug 'terryma/vim-multiple-cursors'
Plug 'ryanss/vim-hackernews'
Plug 'benmills/vimux'
Plug 'ivanov/vim-ipython'

" On-demand
" Plug 'bufexplorer.zip', { 'on':  'BufExplorer' }
Plug 'kien/ctrlp.vim', { 'on':  'CtrlP' }
Plug 'airblade/vim-gitgutter', { 'on': 'GitGutterToggle' }
Plug 'scrooloose/syntastic', { 'for': 'python' }

call plug#end()

" BMS =========================================================================
let g:Powerline_symbols='fancy'

set hidden      " Hides buffers instead of closing
set nowrap      " don't wrap lines
set tabstop=4
set backspace=indent,eol,start  " Prevent weird characters when hit backspace
set autoindent  " copy indent from current line when starting new line
set copyindent  " copy the structure of existing lines indent when autoindenting
set shiftwidth=4
set expandtab
set showmatch

set ignorecase  " Ignore case in patter match
set smartcase   " Cancel Ignore case if pattern contains upper case char
set smarttab    " When using backspace delete's de blanks according to settings

set hlsearch
set incsearch
set history=1000
set undolevels=1000
set wildignore=*.swp,*.bal,*.pyc,*.class " ignore this files when autocomplete

set title   " set terminal window title

set visualbell
set noerrorbells    " no bells on errors

set nowritebackup
set nobackup
set noswapfile

set nocompatible

set pastetoggle=<F2>
set ruler

" When calculating completion, C-n, don't process include files
set complete-=i

" To avoid "Hit ENTER to continue"
set shortmess=at
set cmdheight=2

" Show the status line always
set laststatus=2

set list
set listchars=eol:$,tab:→.,extends:»,precedes:«
noremap <leader>lc :set list!<CR>

" Toggle column numbers
set relativenumber
nmap <silent> <leader>n :set invrelativenumber<CR>

" Set path to search in directory tree
set path+=**
set wildmenu

" Integration with tmux+iterm2
" https://evertpot.com/osx-tmux-vim-copy-paste-clipboard/
set clipboard=unnamed

" VimuxPromptCommand
 map <Leader>vp :VimuxPromptCommand<CR>
 map <Leader>vl :VimuxRunLastCommand<CR>
 map <Leader>vi :VimuxInspectRunner<CR>
 map <Leader>vz :VimuxZoomRunner<CR>

" Go to tab by number
noremap <leader>1 1gt
noremap <leader>2 2gt
noremap <leader>3 3gt
noremap <leader>4 4gt
noremap <leader>5 5gt
noremap <leader>6 6gt
noremap <leader>7 7gt
noremap <leader>8 8gt
noremap <leader>9 9gt
noremap <leader>0 :tablast<cr>

nmap <silent> <Leader>h :nohlsearch<CR>
nmap <silent> <Leader>b :BufExplorer<CR>
nmap <silent> <Leader>j :%!python -m json.tool<CR>
nmap <silent> <Leader>jd :%!python -c 'import sys, json; print(json.dumps(eval(sys.stdin.read()), indent=2))'<CR>
nmap <F8> :TagbarToggle<CR>
nmap <F9> :GitGutterToggle<CR>

iabbrev ipdb import ipdb; ipdb.set_trace()

nnoremap <M-Space> :NERDTreeToggle<cr>
" nnoremap <M-Space> :NERDTreeTabsToggle<cr>

map <C-h> <C-w>h
map <C-j> <C-w>j
map <C-k> <C-w>k
map <C-l> <C-w>l

vnoremap <silent> <Leader>qs di'<ESC>pa'<ESC>
vnoremap <silent> <Leader>qd di"<ESC>pa"<ESC>
vnoremap <silent> <Leader>q( di(<ESC>pa)<ESC>
vnoremap <silent> <Leader>q[ di[<ESC>pa]<ESC>
vnoremap <silent> <Leader>q{ di{<ESC>pa}<ESC>

set bg=dark
colorscheme solarized

let g:ctrlp_map = '<F3>'
let g:ctrlp_cmd = 'CtrlP'

" let g:bufExplorerSortBy='fullpath'
" let g:bufExplorerSplitOutPathName=0
" let g:bufExplorerShowRelativePath=1

" NETRW configuration
let g:netrw_banner=0
" let g:netrw_browse_split=4
let g:netrw_altv=1
let g:netrw_liststyle=3

autocmd Filetype yaml setlocal ts=2 sw=2 sts=2 expandtab
autocmd Filetype html setlocal ts=2 sw=2 sts=2 expandtab
autocmd Filetype htmldjango setlocal ts=2 sw=2 sts=2 expandtab
autocmd Filetype python setlocal ts=4 sw=4 sts=4 expandtab
autocmd Filetype javascript setlocal ts=2 sw=2 sts=2 expandtab
autocmd Filetype javascript.jsx setlocal ts=2 sw=2 sts=2 expandtab
autocmd BufEnter * :syntax sync fromstart

if has("gui_macvim")
    " set macvim specific stuff
    set macligatures
    set guifont=Fira\ Code:h14
endif

" Also a possibility
" if has("gui_running")
"     " set macvim specific stuff
" endif


" 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
