Personal vimrc

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
set encoding=utf8

colorscheme elflord
syntax enable

set number
set numberwidth=2
highlight CursorLineNr ctermfg=3

set cursorline
set hlsearch
set cmdheight=1
set wildmenu

set tabstop=4
set softtabstop=4
set shiftwidth=4

set backspace=2
set updatetime=100

" tab map key
nmap <F5> :tabfirst<CR>
nmap <F6> :tablast<CR>
nmap <F7> :tabprevious<CR>
nmap <F8> :tabnext<CR>

" windows size control map key
nmap <F9> :vertical resize +2<CR>
nmap <F10> :vertical resize -2<CR>
nmap <F11> :resize +2<CR>
nmap <F12> :resize -2<CR>

nmap <leader>z gg=G<C-o><C-o>
nmap <leader>j :%!python -m json.tool

" StatusLine and TabLine
" ------------------------------------------------
" StatusLine
set laststatus=2
set statusline=%f\ %#CgMf#%m%*%=%y\ %{&fileencoding!=''?'['.&fileencoding.']':''}\ %{'['.&fileformat.']'}\ %10(%l,%c%)\ =%L\ %P

" TabLine
set showtabline=2

function MyTabLine()
let s = ''
for i in range(tabpagenr('$'))
if i + 1 == tabpagenr()
let s .= '%#TabLineSel#'
else
let s .= '%#TabLine#'
endif

let s .= ' (' . tabpagewinnr((i + 1),'$') . ')'
let s .= ' %{MyTabLabel(' . (i + 1) . ')} '
endfor

let s .= '%#TabLineFill#'
let s .= "%=[%{tabpagenr()}/%{tabpagenr('$')}]"

return s
endfunction

function MyTabLabel(n)
let buflist = tabpagebuflist(a:n)
let winnr = tabpagewinnr(a:n)
return pathshorten(bufname(buflist[winnr - 1]))
endfunction

set tabline=%!MyTabLine()

" StatusLine and TabLine highlight
if &t_Co > 8
" 16 or 256 color
"
" StatusLine
highlight StatusLine cterm=bold ctermfg=0 ctermbg=10
highlight StatusLineNc cterm=NONE ctermfg=0 ctermbg=7
highlight CgMf cterm=bold ctermfg=0 ctermbg=11
" TabLine
highlight TabLineSel cterm=bold ctermfg=0 ctermbg=10
highlight TabLine cterm=NONE ctermfg=7 ctermbg=8
highlight TabLineFill cterm=bold ctermfg=0 ctermbg=7
else
" 8 color
"
" StatusLine
highlight StatusLine cterm=NONE ctermfg=0 ctermbg=2
highlight StatusLineNc cterm=NONE ctermfg=0 ctermbg=7
highlight CgMf cterm=NONE ctermfg=0 ctermbg=3
" TabLine
highlight TabLineSel cterm=NONE ctermfg=0 ctermbg=2
highlight TabLine cterm=NONE ctermfg=0 ctermbg=7
highlight TabLineFill cterm=NONE ctermfg=0 ctermbg=7
endif


" list of plugins
" ------------------------------------------------
call plug#begin('~/.vim/plugged')
" basic
"
" 文件资源树
Plug 'scrooloose/nerdtree'
" 注释
Plug 'tpope/vim-commentary'
" 符号成对补全
Plug 'jiangmiao/auto-pairs'

" develop
"
" 文件git状态
Plug 'airblade/vim-gitgutter'
" html快速编写
Plug 'mattn/emmet-vim'
" js高亮及格式化
Plug 'pangloss/vim-javascript'
call plug#end()
" ------------------------------------------------

" plugin options
" ------------------------------------------------
" scrooloose/nerdtree
nmap <F3> :NERDTreeToggle<CR>

" airblade/vim-gitgutter
let g:gitgutter_sign_removed_first_line = '^'

highlight GitGutterAdd ctermfg=2
highlight GitGutterChange ctermfg=3
highlight GitGutterDelete ctermfg=1