-
Notifications
You must be signed in to change notification settings - Fork 0
/
_vimrc
448 lines (341 loc) · 13.3 KB
/
_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
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
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
" don't make Vi-compatible
set nocompatible
" display line number. (set nu)
set number
" Set tabstop to tell vim how many columns a tab counts for.
set tabstop=4
" Set softtabstop to control how many columns vim uses when you hit Tab in
" insert mode. If softtabstop is less than tabstop and expandtab is not set,
" vim will use a combination of tabs and spaces to make up the desired
" spacing. If softtabstop equals tabstop and expandtab is not set, vim will
" always use tabs. When expandtab is set, vim will always use the appropriate
" number of spaces.
set softtabstop=4
" When expandtab is set, hitting Tab in insert mode will produce
" the appropriate number of spaces.
set expandtab
" Set shiftwidth to control how many columns text is indented with the
" reindent operations (<< and >>) and automatic C-style indentation.
set shiftwidth=4
" when cursor stays at one of the [],(),{}, highlight the other.
set showmatch
" wrap the line when line is too long.
set wrap
" Show the line and column number of the cursor position.
set ruler
" highlight searching results.
set hlsearch
" By default, searching starts after you enter the string. With `incsearch`
" set, the Vim editor will start searching when you type the first character of the
" search string. As you type in more characters, the search is refined.
set incsearch
" This turns on C style indentation. Each new line will be automatically
" indented the correct amount according to the C indentation standard.
"set cindent
" Setup the colors for syntax highlighting. (syntax enable)
syntax on
" when on, enable file type detection.
" turn this off, required by vundle.
filetype off
"###############################################
" Vundle
"###############################################
" set the runtime path to include Vundle and initialize
set rtp+=%HOME%/.vim/bundle/Vundle.vim
call vundle#begin('$USERPROFILE/.vim/bundle/')
" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'
Plugin 'fatih/vim-go'
Plugin 'FuzzyFinder'
Plugin 'bufexplorer.zip'
Plugin 'scrooloose/nerdtree'
Plugin 'scrooloose/nerdcommenter'
Plugin 'Mark--Karkat'
Plugin 'nathanaelkane/vim-indent-guides'
Plugin 'tpope/vim-surround'
Plugin 'mileszs/ack.vim'
Plugin 'L9'
Plugin 'tpope/vim-repeat'
Plugin 'majutsushi/tagbar'
"Plugin 'Valloric/YouCompleteMe'
Plugin 'Lokaltog/vim-easymotion'
Plugin 'altercation/vim-colors-solarized'
Plugin 'tomasr/molokai'
Plugin 'bling/vim-airline'
Plugin 'vim-airline/vim-airline-themes'
" All of your Plugins must be added before the following line
call vundle#end() " required
"###################################################
" You can enable loading the indent file for specific file types.
"filetype indent on
" You can enable loading the plugin files for specific file types.
"filetype plugin on
filetype plugin indent on
" set number of colors.
" avoid terminal vim to display abnormal.
set t_Co=256
" set terminal vim colorscheme
set background=dark
colorscheme solarized
" By default, when pressing left/right cursor keys, Vim will not move to the
" previous/next line after reaching first/last character in the line. This can
" be quite annoying for new users. Fortunately this behaviour can be easily
" changed by putting this in your vimrc file:
set whichwrap+=<,>,h,l,b,s,[,]
" The *.ext~ file is a backup file, containing the file as it was before you
" edited it.
" To switch off automatic creation of backup files, use this:
set nobackup
" The *.ext.swp file is the swap file, which serves as a lock file and
" contains the undo/redo history as well as any other internal info Vim needs.
" In case of a crash you can re-open your file and Vim will restore its
" previous state from the swap file (which I find helpful, so I don't switch
" it off).
"set noswapfile
" By default, hitting backspace will only delete what has been inserted in the
" current insert mode and on the current line. This makes deleting in insert mode
" very difficult.
"
" indent allow backspacing over autoindent
" eol allow backspacing over line breaks (join lines)
" start allow backspacing over the start of insert; CTRL-W and CTRL-U
" stop once at the start of insert.
set backspace=indent,eol,start
" The 'fileformat' option is local to each buffer. It is set by Vim when a
" file is read, or can be specified in a command telling Vim how to read a
" file. In addition, the 'fileformat' option can be changed to specify the
" line endings that will be added to each line when the buffer is written to a
" file.
set ff=unix
" The 'fileformats' option is global and specifies which file formats will be
" tried when Vim reads a file (unless otherwise specified, Vim attempts to
" automatically detect which file format should be used to read a file). The
" first file format in 'fileformats' is also used as the default for a new
" buffer.
" comment to hide ^M symbol
"set ffs=unix
" The following command displays the fileformat option (abbreviated as ff) for
" the current buffer, and the fileformats global option (abbreviated as ffs)
" which determines how Vim reads and writes files
" :set ff? ffs?
" Sets the character encoding used inside Vim.
set enc=utf-8
" Sets the character encoding for the file of this buffer.
" When 'fileencoding' is different from 'encoding', conversion will be
" done when writing the file.
set fenc=utf-8
" This is a list of character encodings considered when starting to edit
" an existing file. When a file is read, Vim tries to use the first
" mentioned character encoding. If an error is detected, the next one
" in the list is tried. When an encoding is found that works,
" 'fileencoding' is set to it.
"
" Ucs-bom is "ucs with byte-order-mark"
" cp936 is GBK
set fencs=ucs-bom,utf-8,cp936
" Only effective when 'encoding' is "utf-8" or another Unicode encoding.
" Tells Vim what to do with characters with East Asian Width Class
" Ambiguous (such as Euro, Registered Sign, Copyright Sign, Greek
" letters, Cyrillic letters).
set ambiwidth=double
" display a highlight column
"set colorcolumn=80
" Press space to clear search highlighting and any message already displayed.
nnoremap <silent> <Space> :silent noh<Bar>echo<CR>
" Highlight the screen line of the cursor.
set cursorline
" Don't ring the bell (beep or screen flash) for error messages. This only
" makes a difference for error messages, the bell will be used always
" for a lot of errors without a message (e.g., hitting <Esc> in Normal
" mode).
set noerrorbells
" To make all yanking/deleting operations automatically copy to the system
" clipboard. (works in OSX, Windows)
set clipboard+=unnamed
" set mapleader key
let mapleader = ","
" copy to system clipboard.
map <leader>y "+y
" paste from system clipboard.
map <leader>p "+p
" %F: File path
" %y: Type of file
" %r: Readonly flag
" %m: Modified flag
" %{&ff}: File format
" %l: Line number
" %L: Number of lines in buffer
" %c: Column number
" %p: Percentage through file in lines as in |CTRL-G|
" %o: Byte number in file of byte under cursor
set statusline=[%F]%y%r%m[%{strlen(&fenc)?&fenc:'none'}][%{&ff}]%=[%l/%L,%c][%p%%][%o]
" Number of screen lines to use for the command-line.
set cmdheight=1
" The value of this option influences when the last window will have a
" status line:
" 0: never
" 1: only if there are at least two windows
" 2: always
set laststatus=2
" When 'confirm' is on, certain operations that would normally
" fail because of unsaved changes to a buffer, e.g. ":q" and ":e",
" instead raise a |dialog| asking if you wish to save the current
" file(s).
set confirm
" Remove trailing whitespace when writing a buffer, but not for diff (From Vigil)
function RemoveTrailingWhitespace()
if &ft != "diff"
let b:curcol = col(".")
let b:curline = line(".")
" Remove trailing whitespace
silent! %s/\s\+$//
" To change all the existing tab characters to match the current tab settings.
"silent! retab!
" Remove trailing ^M
" ^M is a visual representation of DOS/Windows line-ending character '\r'
" You can also use :%s/^M//g
" To get ^M, hold CTRL and press V then M
"silent! %s/$//g
call cursor(b:curline, b:curcol)
endif
endfunction
autocmd BufWritePre * call RemoveTrailingWhitespace()
function! VisualSelection(direction) range
let l:saved_reg = @"
execute "normal! vgvy"
let l:pattern = escape(@", '\/.*$^~[]')
let l:pattern = substitute(l:pattern, "\n$", "", "")
if a:direction == 'b'
execute "normal ?" . l:pattern . ""
"
elseif a:direction == 'f'
execute "normal /" . l:pattern . ""
"
elseif a:direction == 'gv'
execute "noautocmd vimgrep " . "/" . l:pattern . "/gj" . " **/*"
execute "cw"
endif
let @/ = l:pattern
let @" = l:saved_reg
endfunction
function! VisualSelection_ack(direction) range
let l:saved_reg = @"
execute "normal! vgvy"
let l:pattern = escape(@", '\"`$')
let l:pattern = substitute(l:pattern, "\n$", "", "")
if a:direction == 'ga' || a:direction == 'gv'
execute "Ack! " . "\"" . l:pattern . "\""
endif
let @/ = l:pattern
let @" = l:saved_reg
endfunction
" In visual mode when you press * or # to search for the current selection
vnoremap <silent> * :call VisualSelection('f')<CR>
vnoremap <silent> # :call VisualSelection('b')<CR>
" When you press gv you vimgrep after the selected text
vnoremap <silent> gv :call VisualSelection_ack('gv')<CR>
" Use Ack search
vnoremap <silent> ga :call VisualSelection_ack('ga')<CR>
" ###############################################
" Plugin config
" ###############################################
" BufExplorer
nnoremap <leader>be :BufExplorer<CR>
nnoremap <leader>bs :BufExplorerHorizontalSplit<CR>
nnoremap <leader>bv :BufExplorerVerticalSplit<CR>
" Mark
nnoremap <leader>c :MarkClear<CR>
" Nerdtre
nnoremap <leader>tr :NERDTree<CR>
" Indent Guides
let g:indent_guides_start_level = 2
let g:indent_guides_guide_size = 1
" Fuzzy Finder
nnoremap <leader>fa :FufCoverageFile<CR>
nnoremap <leader>fb :FufBuffer<CR>
nnoremap <leader>ff :FufFile<CR>
nnoremap <leader>fd :FufDir<CR>
nnoremap <leader>fl :FufLine<CR>
nnoremap <leader>ft :FufTag<CR>
" ctags setting
set tags=tags
map <F9> <Esc>:!ctags -R *<CR>
" ###############################################
" vim-go
" ###############################################
let g:go_highlight_functions = 1
let g:go_highlight_methods = 1
let g:go_highlight_structs = 1
let g:go_highlight_operators = 1
let g:go_highlight_build_constraints = 1
au FileType go nmap <leader>r <Plug>(go-run)
au FileType go nmap <leader>b <Plug>(go-build)
"au FileType go nmap <Leader>i <Plug>(go-install)
au FileType go nmap <leader>t <Plug>(go-test)
au FileType go nmap <leader>c <Plug>(go-coverage)
" vim-go default `gd`
au FileType go nmap <Leader>ds <Plug>(go-def-split)
au FileType go nmap <Leader>dv <Plug>(go-def-vertical)
au FileType go nmap <Leader>dt <Plug>(go-def-tab)
au FileType go nmap <Leader>gd <Plug>(go-doc)
au FileType go nmap <Leader>gv <Plug>(go-doc-vertical)
au FileType go nmap <Leader>gb <Plug>(go-doc-browser)
au FileType go nmap <Leader>s <Plug>(go-implements)
au FileType go nmap <Leader>i <Plug>(go-info)
au FileType go nmap <Leader>e <Plug>(go-rename)
" ###############################################
" Tagbar
nnoremap <leader>tt :TagbarToggle<CR>
" ###############################################
" EasyMotion
" ###############################################
let g:EasyMotion_do_mapping = 0 "Disable default mappings
let g:EasyMotion_smartcase = 1 "Turn on case insensitive feature
" Bi-directional find motion
" Need one more keystroke, but on average, it may be more comfortable.
nmap <Leader>s <Plug>(easymotion-s2)
" Replace build-in '/'
map / <Plug>(easymotion-sn)
" JK motions: Line motions
map <Leader>j <Plug>(easymotion-j)
map <Leader>k <Plug>(easymotion-k)
" ###############################################
" ###############################################
" YouCompleteMe
" ###############################################
let g:ycm_path_to_python_interpreter = '/usr/bin/python'
let g:ycm_global_ycm_extra_conf = '~/.vim/bundle/YouCompleteMe/.ycm_extra_conf.py'
let g:ycm_show_diagnostics_ui = 0
let g:ycm_key_invoke_completion = '<C-X>'
" ###############################################
" ###############################################
" ack.vim
" ###############################################
let g:ackprg = 'ag --vimgrep -Q'
let g:ackhighlight = 1
" ###############################################
" ###############################################
" vim-airline
" ###############################################
"let g:airline_powerline_fonts = 1
let g:airline_theme="solarized"
let g:airline#extensions#wordcount#enabled = 0
let g:airline#extensions#tagbar#enabled = 0
let g:airline#extensions#whitespace#enabled = 0
" consolas powerline font"
"set guifont=Consolas\ for\ Powerline\ FixedD:h10
"set guifont=Consolas_for_Powerline_FixedD:h10
"set guifont=Bitstream_Vera_Sans_Mono:h10:cANSI
set guifont=Monaco:h9:cANSI
"statusline symbols"
"let g:Powerline_symbols="fancy"
"let g:airline_symbols = {}
"let g:airline_left_sep = "\u2b80"
"let g:airline_left_alt_sep = "\u2b81"
"let g:airline_right_sep = "\u2b82"
"let g:airline_right_alt_sep = "\u2b83"
"let g:airline_symbols.branch = "\u2b60"
"let g:airline_symbols.readonly = "\u2b64"
"let g:airline_symbols.linenr = "\u2b61"
" ###############################################