-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvimrc
More file actions
393 lines (332 loc) · 12 KB
/
vimrc
File metadata and controls
393 lines (332 loc) · 12 KB
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
" vim: ft=vim foldmethod=marker foldcolumn=1
" vim-plug
if empty(glob('~/.vim/autoload/plug.vim'))
silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs
\ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif
call plug#begin('~/.vim/plugged')
Plug 'bling/vim-airline'
Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }
" Plug 'Valloric/YouCompleteMe', { 'do': './install.py' }
Plug 'tpope/vim-fugitive'
Plug 'majutsushi/tagbar'
Plug 'tomtom/tcomment_vim'
Plug 'airblade/vim-gitgutter'
Plug 'rking/ag.vim'
Plug 'bronson/vim-trailing-whitespace'
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
Plug 'junegunn/fzf.vim'
Plug 'chr4/nginx.vim'
" #Other lang
Plug 'elzr/vim-json'
Plug 'python-mode/python-mode', { 'branch': 'develop' }
" Plug 'vim-syntastic/syntastic'
" Plug 'moby/moby' , {'rtp': '/contrib/syntax/vim/'}
Plug 'ekalinin/Dockerfile.vim'
Plug 'fatih/vim-go', { 'do': ':GoInstallBinaries' }
Plug 'avakhov/vim-yaml'
Plug 'jszakmeister/markdown2ctags'
Plug 'morhetz/gruvbox'
call plug#end()
" ==========================================================================
" General setting
" ==========================================================================
set nocompatible " Use vim, no vi defaults
syntax on
colorscheme gruvbox
let g:gruvbox_contrast_dark='hard'
set background=dark
set t_Co=256
set nobackup
set nowritebackup
set noswapfile
set cursorline
set number
set fileencoding=utf-8
set termencoding=utf-8
set fileencodings=ucs-bom,utf-8,gbk,big5,utf8
set history=50 " keep 50 lines of command line history
set laststatus=2" Displaying status line always
set ruler " show the cursor position all the time
set showcmd " display incomplete commands
set autoread " Set to auto read when a file is changed from the outside
set mouse=a
" Tabs and spaces handling
set smarttab " Uses shiftwidth instead of tabstop at start of lines
set expandtab " Replaces a <TAB> with spaces--more portable
set tabstop=4 " 4 space tab
set shiftwidth=4 " The amount to block indent when using < and >
set softtabstop=4 " Makes the spaces feel like real tabs
set backspace=indent,eol,start " allow backspacing over everything in insert mode
" Search
set hlsearch
set incsearch
set ignorecase
set smartcase
" No show command
autocmd VimEnter * set nosc
" ==========================================================================
" Custom Mappings
" ==========================================================================
let mapleader=","
:command W w
:command Q q
:command Qa qa
:command Wa wa
:command Wqa wqa
:command WQa wqa
" Buffer fast save
noremap <leader>w :w<CR>
noremap <Leader>q :q!<CR>
noremap <Leader>x :x<CR>
noremap <Leader>z :w<CR><C-Z>
noremap <Leader>!w :w !sudo tee %:p > /dev/null<CR>
" Quick ESC
imap jj <ESC>
" Tired of clearing highlighted searches
nmap <silent> ,/ :nohlsearch<CR>
" Quickly edit/reload the vimrc file
nmap <silent> <leader>ev :e $MYVIMRC<CR>
nmap <silent> <leader>sv :so $MYVIMRC<CR>
" ,p: toggle paste mode
noremap <silent> <Leader>p :set paste!<CR>:set paste?<CR>
" Yank & paste via OS X clipboard
" map <leader>p "*p
" map <leader>y "*y
" Move cursor by display lines when wrapping
nnoremap j gj
nnoremap k gk
nnoremap <Down> gj
nnoremap <Up> gk
nnoremap gj j
nnoremap gk k
" Format the entire file
nmap <leader>fef ggVG=
" Move around splits window with <c-hjkl>
" nnoremap <c-j> <c-w>j
" nnoremap <c-k> <c-w>k
" nnoremap <c-h> <c-w>h
" nnoremap <c-l> <c-w>l
" Tab between windows
noremap <tab> <c-w><c-w>
" Switch/create tab(s) in quick - Really handy!
" Conflict with move around splits
map <C-l> :tabn<CR>
map <C-h> :tabp<CR>
map <C-t> :tabnew<CR>
map <C-w> :tabclose<CR>
" use ,1 ,2 to go specific tab
for i in range(1, 9)
exec 'nmap <leader>'.i.' '.i.'gt<CR>'
endfor
" Q was to go ex mode
" but ex mode is useless to us, so remap it
noremap Q :qa
" Switch between last two buffers
nnoremap <leader><leader> <C-^>
" CTRL-U in insert mode deletes a lot. Use CTRL-G u to first break undo,
" so that you can undo CTRL-U after inserting a line break.
inoremap <C-U> <C-G>u<C-U>
" TODO and FIXME list in vim
command Todo noautocmd vimgrep /TODO\|FIXME/j * | cw
"command Todo Ack! 'TODO\|FIXME' " If use the ack-vim plugin
" Move visual block
vnoremap J :m '>+1<CR>gv=gv
vnoremap K :m '<-2<CR>gv=gv
" filetype
autocmd BufNewFile,BufReadPost *.md set filetype=markdown
" F-Key
nmap <F2> :NERDTreeToggle<CR>
nmap <F8> :TagbarToggle<CR>
set pastetoggle=<F11>
map <leader><space> :FixWhitespace<cr>
" ==========================================================================
" NERDTree {{{
" ==========================================================================
" let NERDTreeChDirMode=2
let NERDTreeIgnore=['\.vim$', '\~$', '\.pyc$', '\.swp$']
let NERDTreeSortOrder=['^__\.py$', '\/$', '*', '\.swp$', '\~$']
let NERDTreeShowBookmarks=1
" Automatically quit vim if NERDTree is last and only buffer
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif
" }}}
" ==========================================================================
" python-mode {{{
" ==========================================================================
autocmd WinEnter * if winnr('$') == 1 && ! empty(&buftype) && ! &modified | quit | endif
let g:pymode_folding = 0
let g:pymode_rope = 0
let g:pymode_trim_whitespaces = 1
" let g:pymode_options_colorcolumn = 0
" let g:pymode_doc = 0
" let g:pymode_python = 'python'
" let g:pymode_lint=1
" }}}
" ==========================================================================
" Tagbar {{{
" ==========================================================================
" set focus to TagBar when opening it. Conflict with TagbarOpen setting
" let g:tagbar_autofocus = 0
autocmd BufEnter *.py,*.go,*.cpp,*.h,*.c,*.md nested TagbarOpen
" autocmd BufEnter *.js,*.css,*.less nested TagbarOpen
" Add support for markdown files in tagbar.
let g:tagbar_type_markdown = {
\ 'ctagstype': 'markdown',
\ 'ctagsbin' : '~/.vim/plugged/markdown2ctags/markdown2ctags.py',
\ 'ctagsargs' : '-f - --sort=yes',
\ 'kinds' : [
\ 's:sections',
\ 'i:images'
\ ],
\ 'sro' : '|',
\ 'kind2scope' : {
\ 's' : 'section',
\ },
\ 'sort': 0,
\ }
" }}}
" ==========================================================================
" YCM YouCompleteMe {{{
" ==========================================================================
let g:ycm_autoclose_preview_window_after_completion=1
nnoremap <leader>g :YcmCompleter GoToDefinitionElseDeclaration<CR>
" workaround for tern js: https://github.com/Valloric/YouCompleteMe/issues/570
autocmd FileType javascript setlocal omnifunc=tern#Complete
autocmd FileType css set omnifunc=csscomplete#CompleteCSS noci
nnoremap <leader>gl :YcmCompleter GoToDeclaration<CR>
nnoremap <leader>gf :YcmCompleter GoToDefinition<CR>
nnoremap <leader>gg :YcmCompleter GoToDefinitionElseDeclaration<CR>
" }}}
" ==========================================================================
" vim-gitgutter {{{
" ==========================================================================
set signcolumn=yes
" }}}
" ==========================================================================
" vim-go {{{
" ==========================================================================
let g:go_highlight_functions = 1
let g:go_highlight_methods = 1
let g:go_highlight_structs = 1
let g:go_highlight_interfaces = 1
let g:go_highlight_operators = 1
let g:go_highlight_build_constraints = 1
let g:go_fmt_command = "goimports"
" }}}
" ==========================================================================
" gotags {{{
" ==========================================================================
" Manually install: https://github.com/jstemmer/gotags
let g:tagbar_type_go = {
\ 'ctagstype' : 'go',
\ 'kinds' : [
\ 'p:package',
\ 'i:imports:1',
\ 'c:constants',
\ 'v:variables',
\ 't:types',
\ 'n:interfaces',
\ 'w:fields',
\ 'e:embedded',
\ 'm:methods',
\ 'r:constructor',
\ 'f:functions'
\ ],
\ 'sro' : '.',
\ 'kind2scope' : {
\ 't' : 'ctype',
\ 'n' : 'ntype'
\ },
\ 'scope2kind' : {
\ 'ctype' : 't',
\ 'ntype' : 'n'
\ },
\ 'ctagsbin' : 'gotags',
\ 'ctagsargs' : '-sort -silent'
\ }
" }}}
" ==========================================================================
" airline {{{
" ==========================================================================
let g:airline_powerline_fonts = 1
let g:airline#extensions#tabline#enabled = 1
let g:airline#extensions#tabline#left_sep = ' '
let g:airline#extensions#tabline#left_alt_sep = '|'
let g:airline#extensions#tabline#buffer_nr_show = 0
" }}}
" ==========================================================================
" FZF {{{
" ==========================================================================
let g:fzf_colors =
\ { 'fg': ['fg', 'Normal'],
\ 'bg': ['bg', 'Normal'],
\ 'hl': ['fg', 'Comment'],
\ 'fg+': ['fg', 'CursorLine', 'CursorColumn', 'Normal'],
\ 'bg+': ['bg', 'CursorLine', 'CursorColumn'],
\ 'hl+': ['fg', 'Statement'],
\ 'info': ['fg', 'PreProc'],
\ 'border': ['fg', 'Ignore'],
\ 'prompt': ['fg', 'Conditional'],
\ 'pointer': ['fg', 'Exception'],
\ 'marker': ['fg', 'Keyword'],
\ 'spinner': ['fg', 'Label'],
\ 'header': ['fg', 'Comment'] }
" [Buffers] Jump to the existing window if possible
let g:fzf_buffers_jump = 1
" [[B]Commits] Customize the options used by 'git log':
let g:fzf_commits_log_options = '--graph --color=always --format="%C(auto)%h%d %s %C(black)%C(bold)%cr"'
" Hide statusline of terminal buffer
autocmd! FileType fzf
autocmd FileType fzf set laststatus=0 noshowmode noruler
\| autocmd BufLeave <buffer> set laststatus=2 showmode ruler
" }}}
" ==========================================================================
" others FZF {{{
" ==========================================================================
" let $FZF_DEFAULT_COMMAND='ag --hidden --ignore .git -g "" --path-to-ignore ~/.vim/.ignore'
let $FZF_DEFAULT_OPTS='--height 20% --reverse --border --multi'
" <M-f> (Option-f)
nmap ƒ :Ag<Space>
" nmap <C-o> :Buffers<CR>
nmap <C-p> :Files<CR>
autocmd BufReadPost quickfix nnoremap <buffer> <CR> <CR>
" }}}
" ==========================================================================
" yen3 FZF {{{
" ==========================================================================
" key binding
autocmd VimEnter * command! Yen3Files
\ call fzf#vim#files(<q-args>, {'left': '50%', 'options': '--reverse --prompt=""'})
autocmd VimEnter * command! Yen3Ag
\ call fzf#vim#ag(<q-args>, {'left': '80%', 'options': '-e --reverse --prompt=""'})
autocmd VimEnter * command! Yen3AgCursorWord
\ call fzf#vim#ag(<q-args>, {'left': '80%', 'options': '-e --reverse --prompt="" -q '. shellescape(expand('<cword>'))})
noremap <silent><C-P> :Yen3Files<CR>
noremap <silent><leader>s :Yen3Ag<CR>
noremap <silent><leader>ss :Yen3AgCursorWord<CR>
noremap <silent><leader>b :Buffers<CR>
" }}}
" ==========================================================================
" deoplete {{{
" ==========================================================================
let g:deoplete#enable_at_startup = 1
" }}}
" ==========================================================================
" 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
" nnoremap <Leader>e :Errors<CR>
" nnoremap <Leader>ee :SyntasticToggleMode<CR>
"
" let g:syntastic_python_python_exec = 'python'
" let g:syntastic_python_checkers = ['python', 'flake8', 'pep8', 'pylint']
" }}}
" autocmd FileType vue syntax sync fromstart
" autocmd BufReadPre *.js let b:javascript_lib_use_vue = 1