-
Notifications
You must be signed in to change notification settings - Fork 4
/
vimrc
410 lines (350 loc) · 11.8 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
" Some settings are OS-dependent
let s:uname = system("echo -n \"$(uname)\"")
" ---------------------------- Basic Settings ------------------------------ {{{
syntax on
filetype plugin indent on
" Text-wrapping stuff. (Also check out my cursorcolumn setting in .gvimrc.)
set textwidth=80
let &wrapmargin= &textwidth
" Don't hard-wrap long lines as you're typing (annoying), but allow gq to work.
set formatoptions=croql
set hidden
set history=1000
set number
set hlsearch
set autoindent
set wildmenu
set wildmode=list:longest
set scrolloff=3 " This keeps three lines of context when scrolling.
set autoread " Reload changed files when focus returns.
au FocusGained * :checktime " Make autoread work with neovim/vimr
set expandtab
set smarttab
set ts=2
set sw=2
set sts=-1
set laststatus=2
set ignorecase
set smartcase
set undofile
set backspace=indent,eol,start
set incsearch
set nojoinspaces
set splitright
set nospell " turn this on as required
if exists("&ballooneval")
set noballooneval " annoying
endif
set noshowcmd
" Govim recommendations
set updatetime=500
set balloondelay=250
" When completing, don't automatically select the first choice, but instead just
" insert the longest common text.
set completeopt=menu,longest
" See stuff in .vim/after/plugins/endwise.vim for some more completion settings
" that necessarily must be loaded after endwise.
" (https://github.com/tpope/vim-endwise/pull/16)
" TODO: Get around this; it's better to have all configuration in this file or
" in plugins directly.
" Leaving foldmethod=syntax on all the time causes horrible slowdowns for some
" syntaxes in gvim.
set foldmethod=manual
set foldlevel=99
" TODO(caleb): Investigate and implement a workaround such as those listed here:
" http://vim.wikia.com/wiki/Keep_folds_closed_while_inserting_text
" Allow for modelines
set modeline
let mapleader = ","
" Bells == annoying
set vb
set t_vb=
" For some reason I accidentally hit this shortcut all the time, so disable it.
" I usually don't look at man pages from within vim anyway.
noremap K <Nop>
" Disable ctrl-a; I press this accidentally because of tmux all the time.
noremap <C-a> <Nop>
" Unify vim's default register and the system clipboard
set clipboard=unnamed
if s:uname == "Linux"
set clipboard=unnamedplus
endif
" Ensure the temp dirs exist
if !isdirectory($HOME . "/.vim/tmp")
call system("mkdir -p ~/.vim/tmp/swap")
call system("mkdir -p ~/.vim/tmp/undo")
endif
" Change where we store swap/undo files.
set dir=~/.vim/tmp/swap//
set undodir=~/.vim/tmp/undo/
" Don't save backup files. That's what git is for.
set nobackup
set nowritebackup
" Don't save other tabs in sessions (as I don't use tabs)
set sessionoptions-=tabpages
" Don't save help pages in sessions
set sessionoptions-=help
" Don't save hidden buffers -- only save the visible ones.
set sessionoptions-=buffers
" Viminfo saves/restores editing metadata in ~/.viminfo.
" '100 Save marks for the last 100 edited files
" f1 Store global marks
" <500 Save max of 500 lines of each register
" :100 Save 100 lines of command-line history
" /100 Save 100 searches
" h Disable hlsearch when starting
set viminfo='1000,f1,<500,:100,/100,h
" Make split divisions look nicer.
set fillchars+=vert:\
" }}}
" --------------------------- Colorscheme Settings ------------------------- {{{
set t_Co=256
colorscheme cespare
" Show extra whitespace
hi ExtraWhitespace guibg=#CCCCCC
hi ExtraWhitespace ctermbg=7
match ExtraWhitespace /\s\+$/
augroup highlight_whitespace
au!
au BufWinEnter * match ExtraWhitespace /\s\+$/
au InsertEnter * match ExtraWhitespace /\s\+\%#\@<!$/
au InsertLeave * match ExtraWhitespace /\s\+$/
au BufWinLeave * call clearmatches()
augroup END
" }}}
" ------------------------ Plugin-specific Settings ------------------------ {{{
" Gundo settings
let g:gundo_prefer_python3 = 1
nnoremap <leader>gu :GundoToggle<cr>
" fzf
nnoremap ; :Buffers<CR>
nnoremap <leader>d :Files<CR>
" rg (via ack.vim):
let g:ackprg = 'rg --vimgrep'
nnoremap <leader>a :Ack!
" Insertlessly settings
" I nmap space to :
let g:insertlessly_insert_spaces = 0
" I don't like deleting newlines when leaving insert mode (and I use
" DeleteTrailingWhitespace to do the whole file).
let g:insertlessly_cleanup_trailing_ws = 0
let g:insertlessly_cleanup_all_ws = 0
" easy-align settings
vnoremap <leader>a :EasyAlign<Enter>
" Airline
let g:airline_theme = 'minimalist'
let g:airline_section_z='%3p%% • %l/%L • %v'
let g:airline_section_error = ''
let g:airline_section_warning = ''
let g:airline#extensions#wordcount#enabled = 0
" }}}
" ---------------------- Custom Commands and Functions --------------------- {{{
" A function to delete all trailing whitespace from a file. (From
" http://vimcasts.org/episodes/tidying-whitespace/)
function! <SID>DeleteTrailingWhitespace()
" Preparation: save last search, and cursor position.
let _s=@/
let l = line(".")
let c = col(".")
" Do the business:
%s/\s\+$//e
" Clean up: restore previous search history, and cursor position
let @/=_s
call cursor(l, c)
endfunction
" Preview the current markdown file:
command! Markdownd !markdownd -w % >/dev/null &
" Toggle colorcolumn
function! ToggleColorColumn()
if &colorcolumn == 0
" Draw the color column wherever wrapmargin is set
let &colorcolumn = &wrapmargin
else
let &colorcolumn = 0
endif
endfunction
command! ToggleColorColumn call ToggleColorColumn()
" Toggle width between 80 and 110.
function! ToggleWidth()
if &textwidth == 80
set textwidth=110
else
set textwidth=80
endif
let &wrapmargin = &textwidth
if &colorcolumn > 0
let &colorcolumn = &wrapmargin
endif
endfunction
command! ToggleWidth call ToggleWidth()
" Show the current highlight group underneath the cursor:
function! SynStack()
if !exists("*synstack")
return
endif
echo map(synstack(line('.'), col('.')), 'synIDattr(v:val, "name")')
endfunc
" After running a command which alters the quickfix window, this function is
" useful for opening the window (if it's non-empty) and focus the first result.
function! FocusQuickfix()
cwindow
if len(getqflist()) > 0
cfirst
endif
endfunction
command! FocusQuickfix call FocusQuickfix()
" Fix the handy gx command by implementing it ourselves. (Seems to be utterly
" broken due to a netrw bug: https://github.com/vim/vim/issues/4738.)
function! OpenURL(url)
echo a:url
if a:url == ""
echo "No URL found"
else
" TODO: support non-Linux.
silent! exec "!(xdg-open ".shellescape(a:url, 1)." &) >/dev/null 2>&1"
redraw!
endif
endfunction
function! OpenURLUnderCursor()
" TODO: We want the url under the cursor, but that's not easy to do.
" For now, just find the first URL on the line. Few lines have multiple URLs.
" TODO: Improve regex.
let url = matchstr(getline("."), 'https\?:\/\/[^ <>"\\^`{|}]*[^ <>"\\^`{|}.):;]\+')
call OpenURL(url)
endfunction
nnoremap gx :call OpenURLUnderCursor()<CR>
function! OpenURLVisual()
let url = getline(".")[col("'<")-1:col("'>")-1]
call OpenURL(url)
endfunction
vnoremap gx :call OpenURLVisual()<CR>
" }}}
" ------------------------------- My Mappings ------------------------------ {{{
" Quickly un-highlight search terms
noremap <leader>nn :GOVIMClearReferencesHighlights<CR>:noh<CR>
" Quickly delete trailing whitespace (with cursor position restore)
nnoremap <leader>$ :call <SID>DeleteTrailingWhitespace()<cr>
" Make Y be like C and D (yank to end of line), a mapping so obvious it's
" recommended by :help Y.
nnoremap Y y$
" Shortcuts for creating splits
nnoremap <leader>h :split<cr>
nnoremap <leader>v :vsplit<cr>
" Make it easier to move around through blocks of text:
noremap <C-j> gj
noremap <C-k> gk
noremap <expr> <C-h> (&scroll-2).'k'
noremap <expr> <C-l> (&scroll+2).'j'
" Close a buffer without messing with the windows.
nnoremap <silent> <leader>q :bp\|bd #<CR>
" No colon in command mode to enter an ex command; just use space
nnoremap <Space> :
" Shortcuts for using the quickfix window (partly copied from unimpaired):
nnoremap ]q :cnext<cr>
nnoremap [q :cprevious<cr>
nnoremap [Q :cfirst<cr>
nnoremap ]Q :clast<cr>
nnoremap <leader>x :cclose<cr>
" Shortcuts for custom commands:
noremap <leader>m :Markdownd<cr><cr>
noremap <leader>l :ToggleColorColumn<cr>
noremap <leader>8 :ToggleWidth<cr>
" Git blame shortcut (fugitive)
noremap <leader>bl :Gblame<cr>
" Open GitHub page in browser (fugitive/rhubarb)
noremap <leader>bb :Gbrowse<cr>
" Quick fold toggling
noremap <leader>f za
" Get rid of Ex mode and map a useful command for reflowing text
nnoremap Q gqap
" Suggestions from Learn Vimscript the Hard Way
nnoremap <leader>ev :vsplit $MYVIMRC<cr>
nnoremap <leader>sv :source $MYVIMRC<cr>
" Go shortcuts
nnoremap <leader>gi : <C-u>call GOVIMHover()<CR>
nnoremap <leader>gh :GOVIMHighlightReferences<CR>
nnoremap <leader>gf :GOVIMReferences<CR>
nnoremap <leader>gr :GOVIMRename<CR>
nnoremap <leader>gd :GOVIMQuickfixDiagnostics<CR> :FocusQuickfix<CR>
" TODO:
" nnoremap <leader>gb <Plug>(go-build)
" nnoremap <leader>gt <Plug>(go-test)
" nnoremap <leader>gf <Plug>(go-test-func)
" nnoremap <leader>gc <Plug>(go-coverage-toggle)
" I usually want to evaluate the outermost s-expr in Clojure. This is often more
" handy than cpp (evaluate current expr).
nnoremap cpo :Eval<cr>
" Quickly 'go run' the current file. Good for little scratch programs.
nnoremap <leader>gg :!go run %<cr>
" }}}
" ------------------------- Language-specific Settings --------------------- {{{
" Ruby
let ruby_space_settings = 1
" Go (+govim)
" Docs here: https://godoc.org/github.com/myitcv/govim/cmd/govim/config
packadd govim
" Disable a bunch of spammy/disruptive/colorful stuff that's on by default in
" govim.
call govim#config#Set("QuickfixAutoDiagnostics", 0)
call govim#config#Set("QuickfixSigns", 0)
call govim#config#Set("HighlightDiagnostics", 0)
call govim#config#Set("HighlightReferences", 0)
" TODO:
" - Send the appropriate -local flag to gopls (https://github.com/golang/go/issues/32049)
" - Make govim use the gopls from my path (https://github.com/myitcv/govim/issues/440)
" - Add a shortcut for doing all of the following at once:
" * Run GOVIMQuickfixDiagnostics
" * If the quickfix window is populated, open it and jump to the first item
" * If the quickfix window is not populated, close it
" Once there is a command for running go test etc, add similar shortcuts for
" those as well.
augroup go
au!
au FileType go,asm,gomod setlocal noexpandtab
au FileType go,asm,gomod setlocal ts=8
au FileType go,asm,gomod setlocal sw=8
augroup END
let g:go_highlight_trailing_whitespace_error = 0
" Rust
let g:rustfmt_autosave = 1
" Markdown
augroup markdown
au!
au FileType markdown setlocal comments=b:*,b:-,b:+,n:>h
augroup END
" Vimscript
augroup filetype_vim
au!
au FileType vim setlocal foldmethod=marker
augroup END
" Git commit messages
augroup gitcommit
au!
au FileType gitcommit setlocal textwidth=72
augroup END
" Clojure
let g:clojure_align_multiline_strings = 0
let g:clojure_fuzzy_indent = 1
let g:clojure_fuzzy_indent_patterns = "with.*,def.*,let.*,send.*"
let g:clojure_fuzzy_indent_patterns .= ",GET,POST,PUT,PATCH,DELETE,context" " Compojure
let g:clojure_fuzzy_indent_patterns .= ",clone-for" " Enlive
let g:clojure_fuzzy_indent_patterns .= ",select,insert,update,delete,with.*" " Korma
let g:clojure_fuzzy_indent_patterns .= ",fact,facts" " Midje
let g:clojure_fuzzy_indent_patterns .= ",up,down" " Lobos
let g:clojure_fuzzy_indent_patterns .= ",entity" " Custom
let g:clojure_fuzzy_indent_patterns .= ",check" " Custom
" Nimrod
fun! JumpToDef()
if exists("*GotoDefinition_" . &filetype)
call GotoDefinition_{&filetype}()
else
exe "norm! \<C-]>"
endif
endf
nn <M-g> :call JumpToDef()<cr>
ino <M-g> <esc>:call JumpToDef()<cr>i
" JSON
" Override weird highlighting.
hi def link jsonKeyword String
" Turn off disruptive error highlighting.
let g:vim_json_warnings = 0