" function
" The following are commented out as they cause vim to behave a lot
" differently from regular Vi. They are highly recommended though.
if has("syntax")
  syntax on
endif
if has("autocmd")
  filetype plugin indent on
endif
set encoding=utf-8                       " 编码设置
set expandtab                            " 用space替代tab的输入
set showcmd		" Show (partial) command in status line.
set showmatch		" Show matching brackets.
" set ignorecase		" Do case insensitive matching
" set smartcase		" Do smart case matching
set incsearch		" Incremental search
set autowrite		" Automatically save before commands like :next and :make
set hidden		" Hide buffers when they are abandoned
set mouse=a		" Enable mouse usage (all modes)
set clipboard=unnamed "share clip

setlocal noswapfile " 不要生成swap文件
set bufhidden=hide " 当buffer被丢弃的时候隐藏它
set number " 显示行号
" set relativenumber                       " 显示相对行号
" set cursorline " 突出显示当前行
set ruler " 打开状态栏标尺
set shiftwidth=2 " 设定 << 和 >> 命令移动时的宽度为 2
set tabstop=2 " 设定 tab 长度为 2
set nobackup " 覆盖文件时不备份
set autochdir " 自动切换当前目录为当前文件所在的目录
set backupcopy=yes " 设置备份时的行为为覆盖
set hlsearch " 搜索时高亮显示被找到的文本
set noerrorbells " 关闭错误信息响铃
set novisualbell " 关闭使用可视响铃代替呼叫
set t_vb= " 置空错误铃声的终端代码
set matchtime=2 " 短暂跳转到匹配括号的时间
set magic " 设置魔术
set backspace=indent,eol,start " 不设定在插入状态无法用退格键和 Delete 键删除回车符
set cmdheight=1 " 设定命令行的行数为 1
set laststatus=2 " 显示状态栏 (默认值为 1, 无法显示状态栏)
set cul       " hilight curse line
set cuc       " hilight curse 
" set foldenable " 开始折叠
" set foldmethod=syntax " 设置语法折叠
" set foldcolumn=0 " 设置折叠区域的宽度
" setlocal foldlevel=1 " 设置折叠层数为 1
" nnoremap <space> @=((foldclosed(line('.')) < 0) ? 'zc' : 'zo')<CR> " 用空格键来开关折叠

autocmd vimenter * hi Normal guibg=NONE ctermbg=0 " transparent bg
autocmd vimenter * hi Terminal guibg=NONE ctermbg=0 " transparent bg
set guifont=Source_Han_Sans:h11

" ------------------------Map----------------------------
" 窗口移动快捷键
noremap <TAB>w <C-w>w
noremap <TAB>W <C-w>w
noremap <TAB><left> <C-w><left>
noremap <TAB><right> <C-w><right>
noremap <TAB><up> <C-w><up>
noremap <TAB><down> <C-w><down>

" toggle buffer 
map <S-TAB> :bn<CR>
" map <C-TAB> :bp<CR>
" 使用方括号切换tab
noremap <Leader>] :tabnext<CR>
noremap <Leader>[ :tabprevious<CR>

noremap <Leader>s :wa<CR>
noremap <Leader>q :qa<CR>
" noremap q :qa<CR>
nnoremap <space>e :NERDTreeToggle<CR>
noremap <C-n> :call ToggleComment()<CR>
noremap <C-p> :call SummerSplit()<CR>

:autocmd BufNewFile *.cc,*.h exec ":call CopyRight()"

:iab main( #include<iostream><cr>using namespace std;<cr><cr>int main(int argc, char* argv[], char* env[])<cr>{<cr><cr>  return 0;<cr>}
:iab _xtime <C-R>=strftime('To %H:%M')
:iab _summerTime <C-R>=strftime('%c Summer')<cr><cr>----------------------------------------<cr>
:iab __copyRight__ <C-R>=InsertCopyRight()<C-R> 

" markdown
let g:markdown_fenced_languages =['c', 'cpp', 'python', 'javascript']
" ------------------------function-------------------------------------------------
" split
function SummerSplit()
  :Vex 10
  :wincmd l 
  :45sp
  :110vsp
  :wincmd l 
  :25sp
  :wincmd j 
  :wincmd j 
"  :term ++curwin
endfunction


" for process c++'s log file
function ProcessLog()
  :%s/
//g
  :%s/\[[0-9]*m//g
  :%s/\[[0-9]*;[0-9]*m//g
  :w
endfunction
