" ===main setting commands
let mapleader=" "
syntax on
colorscheme evening
set cursorline
" set cursorcolumn
set background=dark
set lines=30 columns=100
set noeb vb t_vb=
set nobackup
set noundofile
set nohlsearch

set number
set relativenumber
set showcmd
set ignorecase
set smartcase
set tabstop=4
set expandtab
set shiftwidth=4
set autoindent
set fileencodings=utf-8,UTF-8,gbk,ucs-bom,cp936,latin1
set encoding=utf-8
set guifont=Consolas:h10
set clipboard=unnamed

" ===screen split
noremap sk :set nosplitbelow<CR>:split 
noremap sj :set splitbelow<CR>:split 
noremap sh :set nosplitright<CR>:vsplit 
noremap sl :set splitright<CR>:vsplit 

noremap <LEADER>q :q<CR>
noremap <LEADER>w :w<CR>
noremap <C-q> :q!<CR>

noremap K 5k
noremap J 5j
noremap H 5h
noremap L 5l

map <up> <C-w>k
map <down> <C-w>j
map <left> <C-w>h
map <right> <C-w>l

map <C-up> :res +5<CR>
map <C-down> :res -5<CR>
map <C-left> :vertical resize -5<CR>
map <C-right> :vertical resize +5<CR>

inoremap ' ''<ESC>i
inoremap " ""<ESC>i
inoremap [ []<ESC>i
inoremap { {}<ESC>i
inoremap ( ()<ESC>i
inoremap < <><ESC>i

vnoremap ' di''<ESC>hp
vnoremap [ di[]<ESC>hp
vnoremap { di{}<ESC>hp
vnoremap ( di()<ESC>hp
vnoremap < di<><ESC>hp

inoremap <C-l> <ESC>/'\\|"\\|]\\|}\\|)\\|><CR>a
inoremap <C-h> <ESC>i
inoremap <S-CR> <ESC>o
inoremap <C-CR> <ESC>O

autocmd FileType python noremap ma iif<SPACE>__name__<SPACE>==<SPACE>"__main__":<CR>

map <F5> :call Compile()<CR>
map <LEADER><F5> :source $MYVIMRC<CR>
func! Compile()
    exec "w"
    if &filetype == 'python'
        exec "!python %"
    endif
endfunc


" === Vim-Plugs

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

Plug 'junegunn/vim-plug'
Plug 'preservim/nerdtree'
Plug 'gcmt/wildfire.vim'
Plug 'tpope/vim-surround'
Plug 'mg979/vim-visual-multi'

call plug#end()

" === nerdtree config
noremap <C-t> :NERDTreeToggle<CR>
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif
