"                       ███    ██ ██    ██ ██ ███    ███
"                       ████   ██ ██    ██ ██ ████  ████
"                       ██ ██  ██ ██    ██ ██ ██ ████ ██
"                       ██  ██ ██  ██  ██  ██ ██  ██  ██
"                       ██   ████   ████   ██ ██      ██

"                                   Plugins

call plug#begin()
    " File tree
    Plug 'scrooloose/nerdtree'
    " Airline
    Plug 'vim-airline/vim-airline'
    " Better search
    Plug 'haya14busa/incsearch.vim'
    " Commenter
    Plug 'scrooloose/nerdcommenter'
    " Easymotion
    Plug 'easymotion/vim-easymotion'
    " Emmet
    Plug 'mattn/emmet-vim'
    " Colors hightlight
    Plug 'lilydjwg/colorizer'
    " Finder
    Plug 'ctrlpvim/ctrlp.vim'
    " Whitespace hightlight
    Plug 'ntpeters/vim-better-whitespace'
    " Hightlight tag pair
    Plug 'gregsexton/matchtag'

    " Autocomplete
    "
    " Core
    Plug 'Shougo/deoplete.nvim'
    " Vim
    Plug 'Shougo/neco-vim'

    " Language support
    "
    " HTML5
    Plug 'othree/html5.vim'
    " Jade
    Plug 'digitaltoad/vim-jade'
    " CSS3
    Plug 'hail2u/vim-css3-syntax'
    " LESS
    Plug 'groenewege/vim-less'
    " Stylus
    Plug 'wavded/vim-stylus'
    "JS
    Plug 'pangloss/vim-javascript'
    " Coffee script
    Plug 'kchmck/vim-coffee-script'
    " i3 config
    Plug 'PotatoesMaster/i3-vim-syntax'

    " Colorscheme
    "
    " One Dark (Atom colorscheme port)
    Plug 'rakr/vim-one'

call plug#end()

"                               Plugins settings

" Airline
let g:airline_powerline_fonts = 1
let g:airline_theme = 'one'

" Incsearch
let g:incsearch#auto_nohlsearch = 1

" Deoplete
let g:deoplete#enable_at_startup = 1

"                                   Settings

" Plain text automatic line break
set textwidth=80
" Hightlight column
set colorcolumn=80
" Show matches while typing search pattern
set incsearch
" Show previous search pattern
set hlsearch
" Ignorecase while search
set ignorecase
" Remove swapfile (backup)
set noswapfile
set nobackup
" Disable unnecessary redraw
set lazyredraw
" Enable RegExp in search pattern
set magic
" Disable break line
set nowrap
" Show number of line
set number
" Default file encodings
set fileencodings=utf-8,cp1251,koi8-r,cp866
" Show commands completion in bottom menu
set wildmenu
" Enable cursorline
set cursorline
" Invisible chars
set listchars=space:·,tab:│\ ,eol:¬
" Show invisible chars
set list
" Use system clipboard by default
set clipboard=unnamedplus
" Support russian layout
set langmap=ФИСВУАПРШОЛДЬТЩЗЙКЫЕГМЦЧНЯ;ABCDEFGHIJKLMNOPQRSTUVWXYZ
set langmap+=фисвуапршолдьтщзйкыегмцчня;abcdefghijklmnopqrstuvwxyz

" Tab setup
" Tab size in spaces
set tabstop=4
" Tab size in spaces used for >>, << commands
set shiftwidth=4
" Colonum number when hit Tab in insert mode
set softtabstop=4
" Replace tabs with spaces
set expandtab
" Remove spaces like tabs
set smarttab
" Enable automatic indentation
set smartindent

" Color setup
" Enable 24bit color support
set termguicolors
" Use dark version of colorscheme
set background=dark
" Set colorscheme
colorscheme one

"                             Settings by filetype

" HTML
autocmd Filetype html setlocal ts=2 sts=2 sw=2
" CSS
autocmd Filetype css setlocal ts=2 sts=2 sw=2
" JavaScript
autocmd Filetype javascript setlocal ts=2 sts=2 sw=2
" C
autocmd Filetype c setlocal ts=8 sts=8 sw=8 noet

"                                    Binds

" Ctrl-S (save current file)
imap <silent> <C-s> <C-O>:update<CR>
nmap <silent> <C-s> :update<CR>


vmap <silent> <A-k> :m '<-2<CR>gv=gv
vmap <silent> <A-j> :m '>+1<CR>gv=gv

" Buffer switch like with tabs (gt, GT)
nmap <silent> gb :bnext <CR>
nmap <silent> GB :bprevious <CR>

" Move current window
nmap <silent> <A-h> <C-w>h
nmap <silent> <A-j> <C-w>j
nmap <silent> <A-k> <C-w>k
nmap <silent> <A-l> <C-w>l

" Plugins
"
" NERDTree
nmap <silent> <F2> :NERDTreeToggle <CR>

" Incsearch
map /  <Plug>(incsearch-forward)
map ?  <Plug>(incsearch-backward)
map g/ <Plug>(incsearch-stay)
map n  <Plug>(incsearch-nohl-n)
map N  <Plug>(incsearch-nohl-N)
map *  <Plug>(incsearch-nohl-*)
map #  <Plug>(incsearch-nohl-#)
map g* <Plug>(incsearch-nohl-g*)
map g# <Plug>(incsearch-nohl-g#)

" Commenter
nmap <A-/> <leader>c<space>
vmap <A-/> <leader>c<space>

" Easymotion
nmap ; <Plug>(easymotion-overwin-f)

" CtrlP
let g:ctrlp_show_hidden = 1

" Better Whitespace
highlight ExtraWhitespace guibg=#E06C75