-
Notifications
You must be signed in to change notification settings - Fork 2
/
.vimrc
400 lines (351 loc) · 10.4 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
" --- Start of modules ---
call plug#begin('~/.vim/plugged')
Plug 'HerringtonDarkholme/yats.vim'
Plug 'Lokaltog/vim-easymotion'
Plug 'cespare/vim-toml'
Plug 'chrisbra/unicode.vim'
Plug 'danro/rename.vim'
Plug 'gerw/vim-HiLinkTrace'
Plug 'gutenye/json5.vim'
Plug 'hynek/vim-python-pep8-indent'
Plug 'inkarkat/vim-ReplaceWithRegister'
Plug 'kalekundert/vim-nestedtext'
Plug 'konfekt/FastFold'
Plug 'kongo2002/fsharp-vim'
Plug 'ledger/vim-ledger'
Plug 'marklodato/vim-gfm-syntax'
Plug 'mbbill/undotree'
Plug 'mhinz/vim-signify'
Plug 'nathangrigg/vim-beancount'
Plug 'niklasl/vim-rdf'
Plug 'ojroques/vim-oscyank'
Plug 'othree/html5.vim'
Plug 'pangloss/vim-javascript'
Plug 'rhysd/conflict-marker.vim'
Plug 'thinca/vim-visualstar'
Plug 'tpope/vim-abolish'
Plug 'tpope/vim-commentary'
Plug 'tpope/vim-fugitive'
Plug 'tpope/vim-git'
Plug 'tpope/vim-markdown'
Plug 'tpope/vim-repeat'
Plug 'tpope/vim-rsi'
Plug 'tpope/vim-surround'
Plug 'tsandall/vim-rego'
Plug 'vim-jp/cpp-vim'
Plug 'vim-scripts/VisIncr'
Plug 'vim-scripts/a.vim'
Plug 'vim-scripts/svg.vim'
if !filereadable(expand('~/.at_google'))
Plug 'google/vim-codefmt'
Plug 'google/vim-glaive'
Plug 'google/vim-maktaba'
endif
call plug#end()
if !filereadable(expand('~/.at_google'))
call glaive#Install()
endif
" --- End of modules ---
" General options
set nocompatible
set autoindent
set autoread
set backspace=indent,eol,start
set colorcolumn=+1
set display+=lastline
set expandtab
set formatoptions=tcqj
set guioptions-=L
set guioptions-=T
set guioptions-=m
set guioptions-=r
set history=5000
set hlsearch
set ignorecase
set incsearch
set laststatus=2
set noautowrite
set noequalalways
set nofoldenable
set nojoinspaces
set nrformats-=octal
set ruler
set scrolloff=1
set shiftwidth=2
set showcmd
set sidescrolloff=5
set smartcase
set softtabstop=2
set spell
set spellcapcheck= " disable checking of capitalization after periods
set splitright
set suffixes+=.pdf,.ps,.lo,.la
set suffixes-=.h
set tags+=~/.tags
set ttimeout
set ttimeoutlen=50 " timeout (in ms) for ESC-based keys
if !has('nvim')
set undodir=~/.vim/undo
endif
set undofile
set viminfo='100,/100,:100,@10,h,s10
set wildmenu
set winaltkeys=no
set textwidth=80
set cinoptions+=g0(0t0p0
syntax on
" Increase sync backwards search for files that often mess up.
autocmd Syntax markdown syntax sync fromstart
if has('autocmd')
filetype plugin indent on
endif
" Allow color schemes to do bright colors without forcing bold.
if &t_Co == 8 && $TERM !~# '^linux'
set t_Co=16
endif
" Conditional options
if has("mouse")
set mouse=a
set mousemodel=popup
endif
if v:version >= 700
set spelllang=en_us
endif
" Plugins
runtime ftplugin/man.vim
runtime macros/matchit.vim
" Restore cursor position when opening a file, except for git commit messages.
function! ResCur()
if line("'\"") <= line("$") && &filetype != "gitcommit"
normal! g`"
return 1
endif
endfunction
augroup resCur
autocmd!
autocmd BufWinEnter * call ResCur()
augroup END
" Fix encoding issues.
if &encoding ==# 'latin1' && has('gui_running')
set encoding=utf-8
endif
" Show marker for tabs, and highlight spaces before tabs and at EOL
set list
set listchars=tab:»\ ,nbsp:␣
hi default link WhiteSpaceError Error
match WhiteSpaceError /\(\s\+\%#\@!$\)\|\( \+\ze\t\)/
if !has('gui_running') && &term =~ '^\%(screen\|tmux\)'
" Better mouse support, see :help 'ttymouse'
set ttymouse=sgr
" Enable true colors, see :help xterm-true-color
let &termguicolors = v:true
let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum"
let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"
" Enable bracketed paste mode, see :help xterm-bracketed-paste
let &t_BE = "\<Esc>[?2004h"
let &t_BD = "\<Esc>[?2004l"
let &t_PS = "\<Esc>[200~"
let &t_PE = "\<Esc>[201~"
" Enable focus event tracking, see :help xterm-focus-event
let &t_fe = "\<Esc>[?1004h"
let &t_fd = "\<Esc>[?1004l"
if exists("&<FocusGained>")
execute "set <FocusGained>=\<Esc>[I"
execute "set <FocusLost>=\<Esc>[O"
endif
endif
colorscheme darkblue
" Increase default gui size to include the gutter and have more lines.
if has("gui_running")
set columns=82
set lines=50
endif
" Use <C-L> to clear the highlighting of :set hlsearch.
if maparg('<C-L>', 'n') ==# ''
nnoremap <silent> <C-L> :nohlsearch<CR><C-L>
endif
" Change default behavior of some keys
noremap <Leader>q Q
noremap <Leader>Q gQ
noremap gQ gq
noremap Q gq
noremap Y y$
" Remove annoying keys
map! <C-?> <BS>
nnoremap <F1> <nop>
inoremap <F1> <nop>
vnoremap K k
nnoremap K k
vnoremap <Leader>K K
nnoremap <Leader>K K
vnoremap J j
vnoremap <Leader>J J
" Digraphs
digraph vv 10003 " CHECK MARK (✓)
digraph VV 10004 " HEAVY CHECK MARK (✔)
digraph vV 9989 " WHITE HEAVY CHECK MARK (✅)
digraph xx 10007 " BALLOT X (✗)
digraph XX 10008 " HEAVY BALLOT X (✘)
digraph xX 10060 " CROSS MARK (❌)
digraph up 128077 " THUMBS UP (👍)
digraph dn 128078 " THUMBS UP (👎)
" Some useful mappings
map <Leader>m :make<cr>
cnoremap <A-p> <Up>
cnoremap <A-n> <Down>
" Emacs bindings
inoremap <C-a> <Home>
cnoremap <C-a> <Home>
inoremap <C-e> <End>
cnoremap <C-e> <End>
inoremap <A-w> <C-o>w
inoremap <A-W> <C-o>W
inoremap <A-b> <C-o>b
inoremap <A-B> <C-o>B
inoremap <A-BS> x<C-o>dB<C-o>x
" Vi command-mode bindings for insert mode
inoremap <C-t> <C-o>t
inoremap <C-f> <C-o>t
inoremap <A-t> <C-o>t
inoremap <C-t> <C-o>t
" Map \vs to split vertically and scrollbind.
" Source: http://vim.wikia.com/wiki/View_text_file_in_two_columns
noremap <silent> <Leader>vs :<C-u>let @z=&so<CR>:set so=0 noscb<CR>:bo
\ vs<CR>Ljzt:setl scb<CR><C-w>p:setl scb<CR>:let &so=@z<CR>
" Map \s<motion> to :sort that area, and \ss to :sort in the paragraph.
function! SortMap(type) range
'[,']sort
endfunction
nnoremap <Leader>s :set opfunc=SortMap<CR>g@
nmap <Leader>ss <Leader>sip
vnoremap <Leader>s :sort<CR>
" Create the window that I like
let g:big_window_signify=1
function! BigWindow()
top vsplit
set lines=86
if g:big_window_signify
set columns=165
SignifyEnable
else
set columns=161
endif
execute "normal \<C-w>="
endfunction
command! BigWindow call BigWindow()
" Syntax file options
let c_gnu=1
" Useful functions
function! ReverseLineOrder() range
let lnum = a:firstline
for line in reverse(getline(a:firstline, a:lastline))
call setline(lnum, line)
let lnum = lnum+1
endfor
endfunction
command! -range=% -bar ReverseLineOrder <line1>,<line2>call ReverseLineOrder()
" a.vim
let g:alternateNoDefaultAlternate = 1
let g:alternateRelativeFiles = 1
" ReplaceWithRegister
nmap grr grl
" visincr.vim
vmap <C-a> :I<CR>
vmap <C-x> :I -1<CR>
" unicode.vim
nnoremap ga :UnicodeName<CR>
" html.vim
let g:html_indent_script1 = "inc"
let g:html_indent_style1 = "inc"
" vim-markdown
let g:markdown_fenced_languages = [ 'bash', 'build=bzl', "c++=cpp", 'cpp', 'dot', 'html', 'javascript', 'json', 'jsonc=json5', 'json5', 'proto', 'python', 'sh', 'shell=bash', 'sql' ]
let g:gfm_syntax_highlight_issue_number = 0
" vim-visualstar
" Do not map S-LeftMouse, which affects highlighting in visual mode.
let g:visualstar_no_default_key_mappings = 1
silent! xmap <unique> * <Plug>(visualstar-*)
silent! xmap <unique> <kMultiply> <Plug>(visualstar-*)
silent! xmap <unique> # <Plug>(visualstar-#)
silent! xmap <unique> g* <Plug>(visualstar-g*)
silent! xmap <unique> g<kMultiply> <Plug>(visualstar-g*)
silent! xmap <unique> g# <Plug>(visualstar-g#)
" conflict-marker.vim
"let g:conflict_marker_highlight_group = ''
let g:conflict_marker_begin = '^<<<<<<< .*$'
let g:conflict_marker_common_ancestors = '^||||||| .*$'
let g:conflict_marker_end = '^>>>>>>> .*$'
hi link ConflictMarkerOurs DiffAdd
hi link ConflictMarkerCommonAncestorsHunk DiffDelete
hi link ConflictMarkerTheirs DiffChange
" signify.vim
hi SignifyLineAdd guibg=#002040
hi SignifyLineChange guibg=#101040
hi SignifyLineDelete guibg=#100040
hi link SignifyLineChangeDelete SignifyLineChange
hi link SignifyLineDeleteFirstLine SignifyLineDelete
hi SignifySignAdd guifg=#009900 guibg=#000030 ctermfg=2 ctermbg=234
hi SignifySignChange guifg=#bbbb00 guibg=#000030 ctermfg=3 ctermbg=234
hi SignifySignDelete guifg=#ff2222 guibg=#000030 ctermfg=1 ctermbg=234
function! SignifyGitDiffBase(diffbase)
let g:signify_vcs_cmds['git'] = 'git diff --no-color --no-ext-diff -U0 ' .
\ a:diffbase . ' -- %f'
if exists(':SignifyRefresh')
execute 'SignifyRefresh'
endif
endfunction
if !exists('g:signify_vcs_cmds')
let g:signify_vcs_cmds = {}
endif
let g:signify_vcs_list = ['git']
let g:signify_sign_change = '~'
let g:signify_sign_changedelete = '~_'
let g:signify_sign_show_count = 0
nnoremap <Leader>gg :SignifyToggle<CR>
nnoremap <Leader>gl :SignifyToggleHighlight<CR>
nnoremap <Leader>gr :SignifyRefresh<CR>
nnoremap <Leader>gh :call SignifyGitDiffBase('HEAD')<CR>
nnoremap <Leader>gu :call SignifyGitDiffBase('@{upstream}')<CR>
nnoremap <Leader>gi :call SignifyGitDiffBase('')<CR>
" Allow % (matchit.vim) to work with merge conflict markers.
" This is simplified from rhysd/conflict_marker.vim.
" Unfortunately, due to b:match_skip, this will fail if the conflict marker is
" inside a multi-line string or comment.
function! s:add_conflict_markers_to_match_words()
let l:conflict_words = '^<<<<<<<.*:^\%(|||||||\|=======\).*:^>>>>>>>.*'
if exists('b:match_words')
let b:match_words = b:match_words . ',' . l:conflict_words
" c.vim stupidly sets match_words to contain 'matchpairs', which doesn't
" work properly and causes our pattern to break for some unknown reason.
" matchit.vim already honors 'matchpairs', so we should strip it off.
if b:match_words[:strlen(&matchpairs)] == &matchpairs . ','
let b:match_words = b:match_words[strlen(&matchpairs)+1:]
endif
else
let b:match_words = l:conflict_words
endif
endfunction
augroup ConflictMarkers
autocmd!
autocmd BufReadPost * call s:add_conflict_markers_to_match_words()
augroup END
" Allow % to work with <>'s in C++.
autocmd FileType cpp set matchpairs+=<:>
" Do not wrap fstab files.
autocmd FileType fstab setlocal textwidth=0
" EasyMotion:
map gs <Plug>(easymotion-s2)
let g:EasyMotion_smartcase = 1
" vim-codefmt:
nnoremap <Leader>f :set opfunc=codefmt#FormatMap<CR>g@
nnoremap <Leader>ff :FormatLines<CR>
nnoremap <Leader>fb :FormatCode<CR>
vnoremap <Leader>f :FormatLines<CR>
" CTRL-Y = yank to clipboard
vmap <C-y> <Plug>OSCYankVisual
nmap <C-y> <Plug>OSCYankOperator
nmap <C-y><C-y> <C-y>_
nmap <C-y>y <C-y>_
" Put anything that shouldn't be sync'd to GitHub in the following file.
if filereadable($HOME.'/.vim/rc-private.vim')
source ~/.vim/rc-private.vim
endif