-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdot_vimrc
457 lines (373 loc) · 15.7 KB
/
dot_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
448
449
450
451
452
453
454
455
456
457
let data_dir = has('nvim') ? stdpath('data') . '/site' : '~/.vim'
if empty(glob(data_dir . '/autoload/plug.vim'))
silent execute '!curl -fLo '.data_dir.'/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim'
if has('autocmd')
autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif
endif
if has('autocmd')
" Run PlugInstall if there are missing plugins
autocmd VimEnter * if len(filter(values(g:plugs), '!isdirectory(v:val.dir)'))
\| PlugInstall --sync | source $MYVIMRC
\| endif
endif
function! BuildYCM(info)
" info is a dictionary with 3 fields
" - name: name of the plugin
" - status: 'installed', 'updated', or 'unchanged'
" - force: set on PlugInstall! or PlugUpdate!
if a:info.status == 'installed' || a:info.force
!./install.py --java-completer
endif
endfunction
" Updating a plugin
" * Run :PlugUpdate
" * Press D in the window or run :PlugDiff to view differences
" Removing a plugin
" * Delete or comment out Plug commands for the plugins you want to remove.
" * Save and reload vimrc (:source ~/.vimrc) or restart Vim
" * Run :PlugClean. It will detect and remove undeclared plugins.
" Plugins will be downloaded under the specified directory.
call plug#begin(has('nvim') ? stdpath('data') . '/plugged' : '~/.vim/plugged')
Plug 'tpope/vim-sensible'
Plug 'tpope/vim-unimpaired'
Plug 'tpope/vim-surround'
Plug 'tpope/vim-commentary'
Plug 'tpope/vim-fugitive'
Plug 'tpope/vim-repeat'
Plug 'tpope/vim-git'
Plug 'tpope/vim-eunuch'
Plug 'preservim/nerdtree'
Plug 'dense-analysis/ale'
Plug 'michaeljsmith/vim-indent-object'
Plug 'terryma/vim-expand-region'
" Create helptags for vim-plug itself
Plug 'junegunn/vim-plug'
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim'
Plug 'junegunn/vim-peekaboo'
Plug 'machakann/vim-highlightedyank'
Plug 'justinmk/vim-sneak'
Plug 'unblevable/quick-scope'
Plug 'tommcdo/vim-exchange'
Plug 'vim-scripts/argtextobj.vim'
Plug 'vim-scripts/spec.vim'
Plug 'vim-scripts/ShowTrailingWhitespace'
Plug 'vim-scripts/DeleteTrailingWhitespace'
Plug 'vim-scripts/ReplaceWithRegister'
Plug 'vim-scripts/restore_view.vim'
Plug 'fioncat/vim-yaml-folds'
Plug 'altercation/vim-colors-solarized'
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
Plug 'majutsushi/tagbar'
" tmux syntax highlighting
Plug 'zaiste/tmux.vim'
Plug 'christoomey/vim-tmux-navigator'
Plug 'milkypostman/vim-togglelist'
" actually used with rg
Plug 'mileszs/ack.vim'
Plug 'ycm-core/YouCompleteMe', { 'do': function('BuildYCM') }
call plug#end()
function! PlugLoaded(name)
return (
\ has_key(g:plugs, a:name) &&
\ isdirectory(g:plugs[a:name].dir) &&
\ stridx(&rtp, g:plugs[a:name].dir) >= 0)
endfunction
" When started as "evim", evim.vim will already have done these settings.
if v:progname =~? "evim"
finish
endif
call extend(v:colornames, {
\ 'sol_yellow': '#b58900',
\ 'sol_orange': '#cb4b16',
\ 'sol_red': '#dc322f',
\ 'sol_magenta': '#d33682',
\ 'sol_violet': '#6c71c4',
\ 'sol_blue': '#268bd2',
\ 'sol_cyan': '#2aa198',
\ 'sol_green': '#859900',
\ 'sol_base03': '#002b36',
\ 'sol_base02': '#073642',
\ 'sol_base01': '#586e75',
\ 'sol_base00': '#657b83',
\ 'sol_base0': '#839496',
\ 'sol_base1': '#93a1a1',
\ 'sol_base2': '#eee8d5',
\ 'sol_base3': '#fdf6e3',
\}, 'keep')
" Use Vim settings, rather then Vi settings (much better!).
" This must be first, because it changes other options as a side effect.
set nocompatible
if !PlugLoaded('tpope/vim-sensible')
set autoindent
set backspace=indent,eol,start "backspace over everything in insert mode
set incsearch " do incremental searching
set wildmenu
set laststatus=2
set ruler " show the cursor position all the time
set history=1000 " keep 1000 lines of command line history
runtime! macros/matchit.vim
endif
set t_Co=256
set encoding=utf-8
" Provide a nice status line (if not using vim-airline)
set statusline=
set statusline+=%-3.3n\ " buffer number
set statusline+=%f\ " filename
set statusline+=%m%r%w " status flags
set statusline+=\[%{strlen(&ft)?&ft:'none'}] " file type
set statusline+=%= " right align remainder
set statusline+=0x%-8B " character value
set statusline+=%-14(%lL,%cC%V%) " line, column, virtual-column
set statusline+=%<%p%% " file position
set backup " keep a backup file
if has('gui_running')
set background=light
else
set background=dark
endif
set modeline "Respect others modelines
set hidden "Allow changing buffers without saving
set linebreak "Break lines on whitespace only
set softtabstop=4
set tabstop=4
set shiftwidth=4
set expandtab
set backupdir=~/.vim/backup/ "Set a standard backup directory
set viminfo='20,\"50 " .viminfo file with no more than 50 lines
set showcmd " display incomplete commands
set hlsearch " highlight search results
set showmatch " match parentheses
set ignorecase
set smartcase " ignore case in search strings unless the string has a capital letter
set printoptions=paper:letter "Print in letter size
set spellfile=~/.vim/vimspell.add
set spelllang=en_us
set tags^=./.git/tags;
set wildmode=longest,full "complete the longest string and then each match
set undodir=~/.vim/undo
set undofile
set undolevels=400
set undoreload=400
" restore_view.vim (:mkview under the covers) will remember cursor position,
" code folds, backslash to forward slash conversion, and end-of-line format.
" The 'slash' and 'unix' options are primarily beneficial for Windows
" interoperability.
set viewoptions=cursor,folds,slash,unix
" In many terminal emulators the mouse works just fine, thus enable it. (This
" breaks middle click pasting unless you hold the shift key in insert mode,
" so we'll just use the mouse in normal, visual, and command-line mode.)
if has('mouse')
set mouse=nvc
endif
syntax enable
" Use ripgrep for searching
let g:ackprg = 'rg --vimgrep --smart-case'
" Auto close the Quickfix list after pressing '<enter>' on a list item
let g:ack_autoclose = 1
" Any empty search will search for the work the cursor is on
let g:ack_use_cword_for_empty_search = 1
" Highlight searched term
let g:ackhighlight = 1
" Extend the global default (NOTE: Remove comments in dictionary before sourcing)
" "\/\\n\\n\<CR>": 1, " Motions are supported as well. Here's a search motion that finds a blank line
" 'a]' :1, " Support nesting of 'around' brackets
" 'ab' :1, " Support nesting of 'around' parentheses
" 'aB' :1, " Support nesting of 'around' braces
" 'ii' :0, " 'inside indent'. Available through michaeljsmith/vim-indent-object
" 'ai' :0, " 'around indent'. Available through michaeljsmith/vim-indent-object
call expand_region#custom_text_objects({
\ "\/\\n\\n\<CR>": 1,
\ 'a]' :1,
\ 'ab' :1,
\ 'aB' :1,
\ 'ii' :1,
\ 'ai' :1,
\ })
let g:airline_solarized_bg='dark'
let g:airline#extensions#tabline#enabled = 1
let g:airline#extensions#tabline#formatter = 'unique_tail_improved'
let g:airline#extensions#tabline#show_buffers = 0
let g:airline#extensions#tabline#tab_min_count = 2
let g:airline_section_y = 'BN: %{bufnr("%")}'
let g:airline_powerline_fonts = 1
let g:airline#extensions#ale#enabled = 1
if !exists('g:airline_symbols')
let g:airline_symbols = {}
endif
" Default is \ue0a3 which is in a private use area and not available in my
" typeface. Use Black-Letter C instead
let g:airline_symbols.colnr = "\u212D"
" Set TagBar to sort by order in file instead of by name
let g:tagbar_sort = 0
let g:tagbar_autofocus = 1
let g:ycm_autoclose_preview_window_after_completion = 1
let g:ycm_collect_identifiers_from_tags_files = 1
let g:ycm_filetype_blacklist = { 'mail': 1 }
let g:ycm_auto_hover=''
let g:ale_echo_msg_error_str = 'E'
let g:ale_echo_msg_warning_str = 'W'
let g:ale_echo_msg_format = '[%severity%] %s [%linter%]'
" Don't use multiline dictionary format
let g:ale_fixers = {}
let g:ale_fixers['*'] = ['remove_trailing_lines', 'trim_whitespace']
let g:ale_fixers.python = ['black']
let g:ale_python_flake8_options = "--ignore='E501,E121,E122,E123,E124,E125,E126,E127,E128'"
let g:ale_gitcommit_gitlint_options = '--ignore body-is-missing'
let g:NERDTreeChDirMode = 2
" See https://github.com/junegunn/vim-plug/issues/75
let g:plug_timeout = 300
let g:peekaboo_delay = 750
" The default action is to abort the write
let g:DeleteTrailingWhitespace_Action = 'ask'
" But I do still want trailing space highlighted even if I say don't delete it
let g:DeleteTrailingWhitespace_ChoiceAffectsHighlighting = 0
" Trigger a highlight in the appropriate direction only when pressing these keys:
let g:qs_highlight_on_keys = ['f', 'F', 't', 'T']
" Disable quickscope in non-editing buffer types. See :help buftype
let g:qs_buftype_blacklist = ['terminal', 'nofile', 'quickfix', 'prompt', 'popup']
" If another buffer tries to replace NERDTree, put it in the other window, and bring back NERDTree.
autocmd BufEnter * if bufname('#') =~ 'NERD_tree_\d\+' && bufname('%') !~ 'NERD_tree_\d\+' && winnr('$') > 1 |
\ let buf=bufnr() | buffer# | execute "normal! \<C-W>w" | execute 'buffer'.buf | endif
" Exit Vim if NERDTree is the only window remaining in the only tab.
autocmd BufEnter * if tabpagenr('$') == 1 && winnr('$') == 1 && exists('b:NERDTree') && b:NERDTree.isTabTree() | quit | endif
let g:tmux_navigator_no_mappings = 1
" Disable tmux navigator when zooming the Vim pane. Default behavior is to
" unzoom if an attempt is made to navigate past the 'edge'. Alternate
" behavior is controlled by let g:tmux_navigator_preserve_zoom = 1 which keeps
" tmux zoomed when moving from Vim to another pane
let g:tmux_navigator_disable_when_zoomed = 1
" Mappings
nnoremap <silent> <C-w>h :TmuxNavigateLeft<cr>
nnoremap <silent> <C-w>j :TmuxNavigateDown<cr>
nnoremap <silent> <C-w>k :TmuxNavigateUp<cr>
nnoremap <silent> <C-w>l :TmuxNavigateRight<cr>
nnoremap <silent> <C-w>\ :TmuxNavigatePrevious<cr>
nmap <script> <silent> <leader>ll :call ToggleLocationList()<CR>
nmap <script> <silent> <leader>ql :call ToggleQuickfixList()<CR>
" Don't jump to first match
cnoreabbrev Ack Ack!
map <F2> :NERDTreeToggle<CR> :wincmd p<CR>
map <F3> :NERDTreeFocus<CR>
map <F8> :TagbarToggle<CR>
map <F12> <Plug>(ale_fix)
" You can use any sort of range with DeleteTrailingWhitespace.
" E.g. :2,10DeleteTrailingWhitespace would delete only the whitespace on line 2 to 10
" The <C-U> in the mapping tells vim that after the : is entered the CTRL-U
" combination should be used to clear the command line, eliminating any
" automatically inserted range
nnoremap <Leader>d$ :<C-u>%DeleteTrailingWhitespace<CR>
vnoremap <Leader>d$ :DeleteTrailingWhitespace<CR>
" Pull up the current file in NERDTree then refocus on the current file pane
map <leader>cf :NERDTreeFind<CR> :wincmd p<CR>
" Maps <leader>/ so we're ready to type the search keyword
nnoremap <Leader>/ :Rg!<Space>
nmap <leader>qs <plug>(QuickScopeToggle)
xmap <leader>qs <plug>(QuickScopeToggle)
" FZF.vim bindings
noremap <leader>b :Buffers<CR>
noremap <leader>m :Marks<CR>
noremap <leader>f :Files<CR>
noremap <leader>gf :GFiles<CR>
noremap <leader>gs :GFiles?<CR>
noremap <leader>hs :History/<CR>
noremap <leader>hc :History:<CR>
noremap <leader>rg :Rg<CR>
" Don't use Ex mode, use Q for formatting
map Q gq
" As suggested by the vim docs themselves. Make Y not just a copy of yy.
" See https://vi.stackexchange.com/questions/6061/ for a discussion of the
" historical reasons behind the redundancy.
map Y y$
" Swap definitions for :tag and :tjump. :tag just goes to the first match,
" while :tjump goes to the first match unless there are multiple matches in
" which case it shows a select list.
nnoremap <C-]> g<C-]>
vnoremap <C-]> g<C-]>
nnoremap g<C-]> <C-]>
vnoremap g<C-]> <C-]>
" Since vim doesn't have +xterm_clipboard (but gvim does)
vnoremap <silent><Leader>y :w !xsel -b<CR><CR>
" Opposite of 'J': split a line. (By default 'K' runs man on the word under
" the cursor.)
nnoremap K i<CR><Esc>
" Change working directory to directory of current file
if !exists(":CDC")
command CDC cd %:p:h
endif
if &term =~ '^screen'
" tmux will send xterm-style keys when its xterm-keys option is on
execute "set <xUp>=\e[1;*A"
execute "set <xDown>=\e[1;*B"
execute "set <xRight>=\e[1;*C"
execute "set <xLeft>=\e[1;*D"
endif
" Only do this part when compiled with support for autocommands.
if has("autocmd")
" Enable file type detection.
" Use the default filetype settings, so that mail gets 'tw' set to 72,
" 'cindent' is on in C files, etc.
" Also load indent files, to automatically do language-dependent indenting.
filetype plugin indent on
augroup qs_colors
autocmd!
" See vim-colors-solarized/colors/solarized.vim for how the Solarized
" color scheme reassigns the standard terminal color names to the
" Solarized color space.
"
" By default, QuickScopePrimary is linked to the Function token type and
" QuickScopeSecondary to the Define token type. Both of these token types
" are in heavy use however, so I am going to customize to Solarized's
" yellow and violet colors which are uncommonly used in my highlighting.
autocmd ColorScheme * highlight QuickScopePrimary guifg=sol_yellow guibg=sol_base2 gui=underline guisp=sol_yellow
\ ctermfg=DarkYellow cterm=underline
autocmd ColorScheme * highlight QuickScopeSecondary guifg=sol_violet guibg=sol_base2 gui=underline guisp=sol_violet
\ ctermfg=Magenta cterm=underline
augroup END
" Put these in an autocmd group, so that we can delete them easily.
augroup vimrcEx
" Clear vimrcEx group in case we are sourced twice
autocmd!
autocmd FileType mail,python,ruby,markdown,md,gitcommit setlocal spell
" Don't expand tabs for makefiles
autocmd FileType make setlocal noexpandtab
" Turn off balloons in ruby. See http://stackoverflow.com/a/1111363
if has("gui_running")
autocmd FileType ruby,eruby setlocal noballooneval
endif
" Indent two spaces for these types
autocmd FileType ruby,eruby,yaml,html,less,vim,xml,ant,scss setlocal ai sw=2 sts=2 et
" Something about RVM and rubycomplete together results in error
" messages printed to the console about gems missing native extensions
autocmd FileType ruby setlocal omnifunc=syntaxcomplete#Complete
" Turn off the visual bell in both gui and terminal mode
autocmd VimEnter * set vb t_vb=
" For all text files wrap at 80 characters and show right margin
autocmd FileType text,markdown setlocal textwidth=80 colorcolumn=80
" When editing a file, always jump to the last known cursor position.
" Don't do it when the position is invalid or when inside an event handler
" (happens when dropping a file on gvim) or when in a git commit message
" since those are transient.
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") && &filetype != "gitcommit" |
\ exe "normal g`\"" |
\ endif
augroup END
endif
" Convenient command to see the difference between the current buffer and the
" file it was loaded from, thus the changes you made.
" Only define it when not defined already.
if !exists(":DiffOrig")
command DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis
\ | wincmd p | diffthis
endif
" The colorscheme needs to be set after QuickScope color customizations
colorscheme solarized
" vim-colors-solarized sets it (`:verbose highlight SpellBad`) as
" SpellBad xxx term=undercurl cterm=undercurl gui=undercurl guisp=Red
" Unfortunately, xfce4-terminal doesn't support undercurl so we customize
highlight SpellBad term=underline cterm=underline ctermul=red gui=undercurl guisp=red
" highlight end of line whitespace
highlight ShowTrailingWhiteSpace ctermbg=red guibg=red