-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvimrc
397 lines (311 loc) · 9.62 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
" Specify a directory for plugins (for Neovim: ~/.local/share/nvim/plugged)
call plug#begin('~/.vim/plugged')
" Make sure you use single quotes
" Shorthand notation; fetches https://github.com/junegunn/vim-easy-align
Plug 'junegunn/vim-easy-align'
" Any valid git URL is allowed
Plug 'https://github.com/junegunn/vim-github-dashboard.git'
" Multiple Plug commands can be written in a single line using | separators
Plug 'SirVer/ultisnips' | Plug 'honza/vim-snippets'
" On-demand loading
Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }
Plug 'tpope/vim-fireplace', { 'for': 'clojure' }
" Using a non-master branch
Plug 'rdnetto/YCM-Generator', { 'branch': 'stable' }
" Using a tagged release; wildcard allowed (requires git 1.9.2 or above)
Plug 'fatih/vim-go', { 'tag': '*' }
" Plugin outside ~/.vim/plugged with post-update hook
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
" Unmanaged plugin (manually installed and updated)
Plug '~/my-prototype-plugin'
"***********************
"* Plugins added by me *
"***********************
" A code-completion engine for Vim
Plug 'Valloric/YouCompleteMe'
" c++ code navigation
Plug 'lyuts/vim-rtags'
" Comment funtions
Plug 'scrooloose/nerdcommenter'
" Vim motion on speed
Plug 'haya14busa/is.vim'
" Vim airline
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
" A vim plugin to display the indention levels with thin vertical lines
Plug 'Yggdroot/indentLine'
" Visually select regions
Plug 'terryma/vim-expand-region'
" Showing git status flags
Plug 'Xuyuanp/nerdtree-git-plugin'
" C family highlighting
Plug 'octol/vim-cpp-enhanced-highlight'
" Color scheme
Plug 'chriskempson/vim-tomorrow-theme'
" gocode
Plug 'nsf/gocode', { 'rtp': 'vim', 'do': '~/.vim/plugged/gocode/vim/symlink.sh' }
" Asynchronous build and test dispatcher
Plug 'tpope/vim-dispatch'
" fzf
Plug 'junegunn/fzf.vim'
Plug 'tweekmonster/fzf-filemru'
" Switch between header and source files
Plug 'derekwyatt/vim-fswitch'
" Initialize plugin system
call plug#end()
" Let vimrc change work immediately
autocmd BufWritePost $MYVIMRC source $MYVIMRC
""""""""""""""""""""""""
" Environment settings "
""""""""""""""""""""""""
" Set leader key to space
let mapleader = " "
" File type detection
filetype on
" Load plugins based on file type
filetype plugin on
" Not compatible with VI
set nocompatible
" Set session options
set sessionoptions="blank,buffers,globals,localoptions,tabpages,sesdir,folds,help,options,resize,winops,winsize"
" Keep undo history
set undodir=~/.undo_history
set undofile
""""""""""""""
" Visibility "
""""""""""""""
" Display line number
set number
noremap <F5> :set invnumber<CR>
" Display line number, the colume number, the virtual column number and the
" relative position of the cursor in the file
set ruler
" Highlighting cursor
set cursorline
" Search highlight
set hlsearch
" Switch off scroll bar
set guioptions-=l
set guioptions-=L
set guioptions-=r
set guioptions-=R
" Open a vertical split on the right side
set splitright
set encoding=utf-8
" Set font
set guifont=Consolas
" Syntax highlighting
syntax enable
syntax on
" Set color scheme
colorscheme Tomorrow-Night-Eighties
if has('gui_running')
set background=light
else
set background=dark
endif
""""""""""""""
" Formatting "
""""""""""""""
" Smart indent for different file type
filetype plugin indent on
" To insert space characters whenever the tab key is pressed
set expandtab
" Normal tab for makefile
autocmd FileType make set noexpandtab
" Number of space characters inserted when the tab key is pressed
set tabstop=4
" Number of space characters inserted for indentation
set shiftwidth=4
" Jump cursor to the matching paren
set showmatch
"""""""""""
" Edition "
"""""""""""
" Show search results in realtime
set incsearch
" Ingore search case sensitive
set ignorecase
" Set vim command autocomplete
set wildmenu
" Copy to system clipboard
if !exists("g:os")
let g:os = substitute(system('uname'), '\n', '', '')
endif
if g:os == "Linux"
set clipboard=unnamedplus
else
set clipboard=unnamed
endif
" Enable backspace
set backspace=indent,eol,start
" Automatically jump to end of text pasted
vnoremap <silent> y y`]
vnoremap <silent> p p`]
nnoremap <silent> p p`]
map <C-a> GVgg
" unindent
nnoremap <S-Tab> <<
inoremap <S-Tab> <C-d>
vnoremap <S-Tab> <<
" Shortcut for terminal-normal mode to avoid mistakenly press <Cmd-w> to close
" the terminal
" https://vimhelp.org/terminal.txt.html
tnoremap <C-n> <C-W>N
""""""""""""""
" Navigation "
""""""""""""""
" Enable mouse for window and inline navigation
set mouse=a
" Line navigation. Macbook's keyboard shortcuts fn+<Arrow> are not easy to
" press
noremap <C-Up> <PageUp>
noremap <C-Down> <PageDown>
noremap <C-Left> <Home>
noremap <C-Right> <End>
inoremap <C-Up> <PageUp>
inoremap <C-Down> <PageDown>
inoremap <C-Left> <Home>
inoremap <C-Right> <End>
" Shortcuts for split and vsplit windows to avoid to mistakenly press <Cmd-w> to close the terminal
nnoremap <C-d> <C-w>v
nnoremap <C-x> <C-w>s
" Open termdebug windows vertifcally
"let g:termdebug_wide = 0
" Go back
nnoremap <S-F2> <C-o>
" Move to the next occurrence
map <F3> n
map <S-F3> N
" GDB
nnoremap <Leader>b :Break<CR>
" Highligh all occurrence
nnoremap <Leader>f *
"""""""""""""""""""
" Plugin settings "
"""""""""""""""""""
" fzf.vim plugin settings
" This is the default extra key bindings
let g:fzf_action = {
\ 'ctrl-x': 'split',
\ 'ctrl-d': 'vsplit' }
" Default fzf layout
" - down / up / left / right
let g:fzf_layout = { 'down': '~40%' }
" Customize fzf colors to match your color scheme
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'] }
" Enable per-command history.
" CTRL-N and CTRL-P will be automatically bound to next-history and
" previous-history instead of down and up. If you don't like the change,
" explicitly bind the keys to down and up in your $FZF_DEFAULT_OPTS.
let g:fzf_history_dir = '~/.local/share/fzf-history'
nnoremap <silent> <Leader>p :FilesMru --tiebreak=end<CR>
nnoremap <silent> <Leader>F :Rg <C-R><C-W><CR>
" Nerdtree plugin settings
nnoremap <silent> <Leader>n :NERDTreeToggle<CR>
let NERDTreeWinPos = "right"
let NERDTreeWinSize = 32
let NERDTreeShowHidden = 1
let NERDTreeAutoDeleteBuffer = 1
let NERDTreeMinimalUT = 1
let g:NERDTreeIndicatorMapCustom = {
\ "Modified" : "✹",
\ "Staged" : "✚",
\ "Untracked" : "✭",
\ "Renamed" : "➜",
\ "Unmerged" : "═",
\ "Deleted" : "✖",
\ "Dirty" : "✗",
\ "Clean" : "✔︎",
\ "Unknown" : "?"
\ }
" indentLine plugin settings
let g:indentLine_char = '¦'
" Youcompleteme plugin settings
let g:ycm_global_ycm_extra_conf = '~/.vim/.ycm_extra_conf.py'
let g:ycm_confirm_extra_conf = 0
let g:ycm_error_symbol = '>>'
let g:ycm_warning_symbol = '>*'
let g:ycm_enable_diagnostic_signs = 0
let g:ycm_enable_diagnostic_highlighting = 0
" vim-rtags plugin settings
nmap <F2> <Leader>rj
" Nerdcommenter plugin settings
let g:NERDSpaceDelims = 1
let g:NERDCompactSexyComs = 1
let g:NERDDefaultAlign = 'left'
let g:NERDAltDelims_java = 1
let g:NERDCustomDelimiters = { 'c': { 'left': '/**','right': '*/' } }
let g:NERDCommentEmptyLines = 1
let g:NERDTrimTrailingWhitespace = 1
let g:NERDCreateDefaultMappings = 0
map <Leader>/ <Plug>NERDCommenterToggle('n', 'Toggle')<CR>
" vim-cpp-enhanced-highlight plugin settings
let g:cpp_class_scope_highlight = 1
let g:cpp_member_variable_highlight = 1
let g:cpp_class_decl_highlight = 1
let g:cpp_experimental_template_highlight = 1
" vim-fswitch plugin settings
nnoremap <silent> <F4> :FSHere<CR>
" Vim-airline plugin settings
let g:airline_theme='powerlineish'
let g:airline_left_sep=''
let g:airline_right_sep=''
let g:airline_section_z=''
" Vim-expand-region
vmap v <Plug>(expand_region_expand)
vmap V <Plug>(expand_region_shrink)
" Prevent replacing paste buffer on paste (place this to end of vimrc)
" vp doesn't replace paste buffer
function! RestoreRegister()
let @" = s:restore_reg
return ''
endfunction
function! s:Repl()
let s:restore_reg = @"
return "p@=RestoreRegister()\<cr>"
endfunction
vmap <silent> <expr> p <sid>Repl()
" Vim-go plugin settings
map <C-n> :cnext<CR>
map <C-m> :cprevious<CR>
nnoremap <leader>a :cclose<CR>
autocmd FileType go nmap <leader>r <Plug>(go-run)
autocmd FileType go nmap <leader>t <Plug>(go-test)
function! s:build_go_files()
let l:file = expand('%')
if l:file =~# '^\f\+_test\.go$'
call go#test#Test(0, 1)
elseif l:file =~# '^\f\+\.go$'
call go#cmd#Build(0)
endif
endfunction
autocmd FileType go nmap <leader>b :<C-u>call <SID>build_go_files()<CR>
autocmd FileType go nmap <leader>c <Plug>(go-coverage-toggle)
let g:go_fmt_command = "goimports"
let g:go_highlight_types = 1
let g:go_higjlight_fields = 1
let g:go_higjlight_functions = 1
let g:go_higjlight_methods = 1
let g:go_highlight_operators = 1
let g:go_highlight_extra_types = 1
let g:go_highlight_build_constraints = 1
autocmd Filetype go command! -bang A call go#alternate#Switch(<bang>0, 'edit')
autocmd Filetype go command! -bang AV call go#alternate#Switch(<bang>0, 'vsplit')
autocmd Filetype go command! -bang AS call go#alternate#Switch(<bang>0, 'split')
autocmd Filetype go command! -bang AT call go#alternate#Switch(<bang>0, 'tabe')
let g:go_def_mode = 'godef'
let g:go_decls_includes = "func,type"