-
Notifications
You must be signed in to change notification settings - Fork 0
/
vimrc
506 lines (426 loc) · 15.6 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
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
" John Kerl's vimrc, 2003-2013 and onward ...
" See vim online help for more information.
source $HOME/.vimrc-site
behave xterm
"set compatible
set nobackup
set nohlsearch
set noincsearch
set noshowmode
"set notagrelative
set tagrelative
set cpoptions=aABcdeFs
set exrc
set modeline
set modelines=5
set tw=100
set encoding=utf-8
"set encoding=latin1
set autoindent
set nocindent " Nice feature; doesn't match my preferences.
"I'll break lines when I want them broken:
set formatoptions=ql " This one is needed for vim without filename
" ?!?! >:[
" :autocmd FileType * set formatoptions=ql
" ?!?! >:[
" map \0 :se formatoptions=ql<C-m>
" ?!?! >:[
" http://stackoverflow.com/questions/6076592/vim-set-formatoptions-being-lost
autocmd BufNewFile,BufRead * setlocal formatoptions=ql
autocmd BufEnter reg_test/run :syntax sync fromstart
set vb t_vb= "Turn the beeping off
set noignorecase
set nonovice
set nowrapscan
" Flag trailing whitespace in red.
let c_space_errors=1
let ruby_space_errors=1
let java_space_errors=1
let groovy_space_errors=1
let scala_space_errors=1
set background=dark
"set background=light
"map ,z :set background=light<C-m>
set tagstack
set tags=./tags,../tags,../../tags,../../../tags,../../../../tags,../../../../../tags
" Include '-' (ASCII 45) and ':' (ASCII 58) as part of word for tag searches; '_'=95
"set iskeyword=@,45,48-57,58,95,192-255,#
" Enable language-specific syntax highlighting.
syntax on
"au BufNewFile,BufRead *.g,*.groovy set filetype=groovy
" ----------------------------------------------------------------
" Trying this 2008-02-12 ...
" Once I start vim and type 'set comments', it does *not* have this
" value, if the mode (C, .vimrc, etc.) has been detected. If I type vim with
" no arguments, this comments=... does apply. However, autoindent with gqip
" now breaks; //'s flow into the paragraph. :(
" set comments=f:-
"map \f :set comments=f:-<C-m>
" ================================================================
" Keymaps
"Leader for two-key sequences
map , \
map \, :tnext<C-m>
" 2010-08-08
"map # :w<C-m>:e#
map \x l
"""""map \w :w<C-m>:!latex %<C-m>
map \e :set hlsearch<CR>
map \E :set nohlsearch<CR>
map \i :set ic<C-m>
map \I :set noic<C-m>
map \a :set ai<C-m>
map \A :set noai<C-m>
map \t :set paste<C-m>
map \T :set nopaste<C-m>
map \D :set ft=diff<C-m>
map \n :se nu<C-m>
map \N :se nonu<C-m>
map \l :se list<C-m>
map \L :se nolist<C-m>
" This highlight git merge lines
map \m :se hlsearch<C-m>/^[<=\|>][<=\|>][<=\|>][<=\|>][<=\|>][<=\|>][<=\|>] <C-m>
map <C-h> :.!bash<CR>j
map \h !}echorun<CR>}}
"map \h yyp:.!sh<CR>
"map \H yyp!}head -n 1 \| sh<CR>k
"map \b i\begin{eqnarray*}<C-m><TAB>&=& \\<C-m><C-d>\end{eqnarray*}<C-m><ESC>
map <C-q> I* <ESC>j
map \b :.!ind -1b<C-m>j
map \B :.!uind -1b<C-m>
map e <C-e>
map ; :
"map v ~
" Show current line number:
map - :.=<C-m>
" Show last line number:
map _ :$=<C-m>
" Insert a space & keep the cursor position still:
map <C-k> i <ESC>
" Put current line at middle of screen
map <SPACE> zz
" ----------------------------------------------------------------
" https://vi.stackexchange.com/questions/15505/highlight-whole-todo-comment-line
syntax match myTodo /\v.<(TODO|FIXME|XXX|xxx).*/hs=s+1 containedin=.*Comment
highlight link myTodo Todo
highlight Search ctermbg=LightGrey
highlight Todo ctermbg=DarkGrey
syntax match myImportant1 /^ *! .*/
highlight link myImportant1 ErrorMsg
syntax match myImportant2 /^ *\~ .*/
highlight link myImportant2 SpellBad
syntax match myImportant3 /^ *w .*/
highlight link myImportant3 Visual
"syn list Todo
"syn list myTodo
au BufNewFile,BufRead * syntax match myTodo /\v.<(TODO|FIXME|XXX|xxx).*/hs=s+1 containedin=.*Comment
au BufNewFile,BufRead * syntax match myImportant1 /^ *! .*/
au BufNewFile,BufRead * syntax match myImportant2 /^ *\~ .*/
au BufNewFile,BufRead * syntax match myImportant3 /^ *w .*/
" ----------------------------------------------------------------
" Tabs/whitespaces, and indent/unindent keymaps
"set noexpandtab
set expandtab
" TWO:
map <C-a> I <ESC>
map <C-S-A> I <ESC>j
map <C-u> 0xx
map <C-S-U> 0xxj
set ts=2
" THREE:
"map <C-a> I <ESC>
"map <C-S-A> I <ESC>j
"map <C-u> 0xxx
"map <C-S-U> 0xxxj
"set ts=3
" FOUR:
"#map <C-a> I <ESC>
"#map <C-S-A> I <ESC>j
"map <C-u> 0xxxx
"map <C-S-U> 0xxxxj
"set ts=4
" TAB:
"""""map <C-a> I<TAB><ESC>
"""""map <C-S-A> I<TAB><ESC>j
"""""map <C-u> 0x
"""""map <C-S-U> 0xj
"set ts=8
map \2 :se ts=2<C-m>
map \3 :se ts=3<C-m>
map \4 :se ts=4<C-m>
map \8 :se ts=8<C-m>
"map \0 :se ts=80<C-m>
map \0 :set colorcolumn=120<CR>
map \o :set colorcolumn=88<CR>
map \c :set colorcolumn=80<C-m>
map \O :set colorcolumn=0<CR>
map \C :set colorcolumn=<C-m>
" ----------------------------------------------------------------
"au BufNewFile,BufRead *.java map <C-a> I <ESC>
"au BufNewFile,BufRead *.java map <C-S-A> I <ESC>j
"au BufNewFile,BufRead *.java map <C-u> 0xxxx
"au BufNewFile,BufRead *.java map <C-S-U> 0xxxxj
"au BufNewFile,BufRead *.g map <C-a> I <ESC>
"au BufNewFile,BufRead *.g map <C-S-A> I <ESC>j
"au BufNewFile,BufRead *.g map <C-u> 0xxxx
"au BufNewFile,BufRead *.g map <C-S-U> 0xxxxj
"au BufNewFile,BufRead *.groovy map <C-a> I <ESC>
"au BufNewFile,BufRead *.groovy map <C-S-A> I <ESC>j
"au BufNewFile,BufRead *.groovy map <C-u> 0xxxx
"au BufNewFile,BufRead *.groovy map <C-S-U> 0xxxxj
au BufNewFile,BufRead Makefile* set ts=8
au BufNewFile,BufRead Makefile* set noexpandtab
au BufNewFile,BufRead Makefile* map <C-a> I<TAB><ESC>
au BufNewFile,BufRead Makefile* map <C-S-A> I<TAB><ESC>j
au BufNewFile,BufRead Makefile* map <C-u> 0x
au BufNewFile,BufRead Makefile* map <C-S-U> 0xj
au BufNewFile,BufRead Makevars* set ts=8
au BufNewFile,BufRead Makevars* set noexpandtab
au BufNewFile,BufRead Makevars* map <C-a> I<TAB><ESC>
au BufNewFile,BufRead Makevars* map <C-S-A> I<TAB><ESC>j
au BufNewFile,BufRead Makevars* map <C-u> 0x
au BufNewFile,BufRead Makevars* map <C-S-U> 0xj
au BufNewFile,BufRead configure.ac set ts=8
au BufNewFile,BufRead configure.ac set noexpandtab
au BufNewFile,BufRead configure.ac map <C-a> I<TAB><ESC>
au BufNewFile,BufRead configure.ac map <C-S-A> I<TAB><ESC>j
au BufNewFile,BufRead configure.ac map <C-u> 0x
au BufNewFile,BufRead configure.ac map <C-S-U> 0xj
"au BufNewFile,BufRead *.[ch] set ts=4
"au BufNewFile,BufRead *.[ch] set noexpandtab
"au BufNewFile,BufRead *.[ch] map <C-a> I<TAB><ESC>
"au BufNewFile,BufRead *.[ch] map <C-S-A> I<TAB><ESC>j
"au BufNewFile,BufRead *.[ch] map <C-u> 0x
"au BufNewFile,BufRead *.[ch] map <C-S-U> 0xj
au BufNewFile,BufRead *.[ch] set ts=2
au BufNewFile,BufRead *.[ch] set expandtab
au BufNewFile,BufRead *.[ch] map <C-a> I <ESC>
au BufNewFile,BufRead *.[ch] map <C-S-A> I <ESC>j
au BufNewFile,BufRead *.[ch] map <C-u> 0xx
au BufNewFile,BufRead *.[ch] map <C-S-U> 0xxj
au BufNewFile,BufRead *.cc set ts=2
au BufNewFile,BufRead *.cc set expandtab
au BufNewFile,BufRead *.cc map <C-a> I <ESC>
au BufNewFile,BufRead *.cc map <C-S-A> I <ESC>j
au BufNewFile,BufRead *.cc map <C-u> 0xx
au BufNewFile,BufRead *.cc map <C-S-U> 0xxj
au BufNewFile,BufRead *.cpp set ts=2
au BufNewFile,BufRead *.cpp set expandtab
au BufNewFile,BufRead *.cpp map <C-a> I <ESC>
au BufNewFile,BufRead *.cpp map <C-S-A> I <ESC>j
au BufNewFile,BufRead *.cpp map <C-u> 0xx
au BufNewFile,BufRead *.cpp map <C-S-U> 0xxj
au BufNewFile,BufRead CMakeLists.txt set ts=2
au BufNewFile,BufRead CMakeLists.txt set expandtab
au BufNewFile,BufRead CMakeLists.txt map <C-a> I <ESC>j
au BufNewFile,BufRead CMakeLists.txt map <C-u> 0xx
au BufNewFile,BufRead CMakeLists.txt map <C-S-U> 0xxj
au BufNewFile,BufRead *.[ly] set ts=4
au BufNewFile,BufRead *.[ly] set noexpandtab
au BufNewFile,BufRead *.[ly] map <C-a> I<TAB><ESC>
au BufNewFile,BufRead *.[ly] map <C-S-A> I<TAB><ESC>j
au BufNewFile,BufRead *.[ly] map <C-u> 0x
au BufNewFile,BufRead *.[ly] map <C-S-U> 0xj
au BufNewFile,BufRead *.[d] set ts=4
au BufNewFile,BufRead *.[d] set noexpandtab
au BufNewFile,BufRead *.[d] map <C-a> I<TAB><ESC>
au BufNewFile,BufRead *.[d] map <C-S-A> I<TAB><ESC>j
au BufNewFile,BufRead *.[d] map <C-u> 0x
au BufNewFile,BufRead *.[d] map <C-S-U> 0xj
au BufNewFile,BufRead *.go set ts=4
au BufNewFile,BufRead *.go set noexpandtab
au BufNewFile,BufRead *.go map <C-a> I<TAB><ESC>
au BufNewFile,BufRead *.go map <C-S-A> I<TAB><ESC>j
au BufNewFile,BufRead *.go map <C-u> 0x
au BufNewFile,BufRead *.go map <C-S-U> 0xj
"au BufNewFile,BufRead *.py set ts=4
"au BufNewFile,BufRead *.py set noexpandtab
"au BufNewFile,BufRead *.py map <C-a> I<TAB><ESC>
"au BufNewFile,BufRead *.py map <C-S-A> I<TAB><ESC>j
"au BufNewFile,BufRead *.py map <C-u> 0x
"au BufNewFile,BufRead *.py map <C-S-U> 0xj
"au BufNewFile,BufRead py* set ts=4
"au BufNewFile,BufRead py* set noexpandtab
"au BufNewFile,BufRead py* map <C-a> I<TAB><ESC>
"au BufNewFile,BufRead py* map <C-S-A> I<TAB><ESC>j
"au BufNewFile,BufRead py* map <C-u> 0x
"au BufNewFile,BufRead py* map <C-S-U> 0xj
"au BufNewFile,BufRead pgr set ts=4
"au BufNewFile,BufRead pgr set noexpandtab
"au BufNewFile,BufRead pgr map <C-a> I<TAB><ESC>
"au BufNewFile,BufRead pgr map <C-S-A> I<TAB><ESC>j
"au BufNewFile,BufRead pgr map <C-u> 0x
"au BufNewFile,BufRead pgr map <C-S-U> 0xj
au BufNewFile,BufRead *.py set ts=4
au BufNewFile,BufRead *.py set expandtab
au BufNewFile,BufRead *.py map <C-a> I <ESC>
au BufNewFile,BufRead *.py map <C-S-A> I <ESC>j
au BufNewFile,BufRead *.py map <C-u> 0xxxx
au BufNewFile,BufRead *.py map <C-S-U> 0xxxxj
au BufNewFile,BufRead py* set ts=4
au BufNewFile,BufRead py* set expandtab
au BufNewFile,BufRead py* map <C-a> I <ESC>
au BufNewFile,BufRead py* map <C-S-A> I <ESC>j
au BufNewFile,BufRead py* map <C-u> 0xxxx
au BufNewFile,BufRead py* map <C-S-U> 0xxxxj
au BufNewFile,BufRead pgr set ts=4
au BufNewFile,BufRead pgr set expandtab
au BufNewFile,BufRead pgr map <C-a> I <ESC>
au BufNewFile,BufRead pgr map <C-S-A> I <ESC>j
au BufNewFile,BufRead pgr map <C-u> 0xxxx
au BufNewFile,BufRead pgr map <C-S-U> 0xxxxj
:autocmd FileType python set ts=4
:autocmd FileType python set expandtab
:autocmd FileType python map <C-a> I <ESC>
:autocmd FileType python map <C-S-A> I <ESC>j
:autocmd FileType python map <C-u> 0xxxx
:autocmd FileType python map <C-S-U> 0xxxxj
au BufNewFile,BufRead *.[rR] set ts=2
au BufNewFile,BufRead *.[rR] set expandtab
au BufNewFile,BufRead *.[rR] map <C-a> I <ESC>
au BufNewFile,BufRead *.[rR] map <C-S-A> I <ESC>j
au BufNewFile,BufRead *.[rR] map <C-u> 0xx
au BufNewFile,BufRead *.[rR] map <C-S-U> 0xxj
au BufNewFile,BufRead *.md set ts=2
au BufNewFile,BufRead *.md set expandtab
au BufNewFile,BufRead *.md map <C-a> I <ESC>
au BufNewFile,BufRead *.md map <C-S-A> I <ESC>j
au BufNewFile,BufRead *.md map <C-u> 0xx
au BufNewFile,BufRead *.md map <C-S-U> 0xxj
function Yestabs()
set ts=4
set noexpandtab
map <C-a> I<TAB><ESC>
map <C-S-A> I<TAB><ESC>j
map <C-u> 0x
map <C-S-U> 0xj
endfunction
function Notabs()
set ts=4
set expandtab
map <C-a> I <ESC>
map <C-S-A> I <ESC>j
map <C-u> 0xxxx
map <C-S-U> 0xxxxj
endfunction
map ,Z :call Yestabs()<CR>
map ,z :call Notabs()<CR>
" ----------------------------------------------------------------
"map <C-r> :rewind
" Next file
map <C-n> :n<C-m>
" Reflow the current paragraph
map <C-p> gqip}}{j
" Reflow the current line and the one below. Nice with auto-repeat.
map <C-x> gqj
" Replace current character with space and move right. Nice with auto-repeat.
map <C-d> r l
" Move to next file, with save.
map <C-o> :w<C-m>:n<C-m>
" Shell uncomment with autorepeat
map <C-S-o> 0xj
" ================================================================
" Language-specific separators. Uppercase is equal signs; lowercase is dashes.
" ,S and ,s for shell:
" # ================================================================
" # ----------------------------------------------------------------
"
" ,P and ,p for C++-style comments:
" // ================================================================
" // ----------------------------------------------------------------
"
" ,J and ,j for just the separator:
" ================================================================
" ----------------------------------------------------------------
"
" etc.
" /* comment */
"map \c O/* <ESC>64A-<ESC>A*/<ESC>
"map \C O/* <ESC>64A=<ESC>A*/<ESC>
" (* comment *)
"map \c 0i(*<ESC>A*)<ESC>
"map \m O(* <ESC>64A-<ESC>A*)<ESC>
"map \M O(* <ESC>64A=<ESC>A*)<ESC>
" // comment
map \p O// <ESC>64A-<ESC>
map \P O// <ESC>64A=<ESC>
" - - - instead of -----
map \q O// <ESC>32A -<ESC>
map \Q O// <ESC>32A =<ESC>
map \= O// <ESC>32A -<ESC>
" # comment
map \s O# <ESC>64A-<ESC>
map \S O# <ESC>64A=<ESC>
" % comment
" map \t O%% <ESC>64A-<ESC>
" map \T O%% <ESC>64A=<ESC>
" Just the line, no comment character
map \j O<ESC>64A-<ESC>
map \J O<ESC>64A=<ESC>
" Centered stars:
" * * *
map \r O* * *<ESC>32I <ESC>
" HTML monospace smiley:
map \v :se ft=java<C-m>
" fleurons:
"map \f O𐡷𐡷 ❦ 𐡸 𐫱 𐡷 ❦ 𐡸 𐫱 𐡷 ❦ 𐡸 𐫱 𐡷 ❦ 𐡸 𐫱 𐡷 ❦ 𐡸 𐫱 𐡷 ❦ 𐡸 𐫱 𐡷 ❦ 𐡸 𐫱 𐡷 ❦ 𐡸𐡸<ESC>
" Set mark, format, return to mark. Without the mark, the cursor would be at
" the top of the file after the %!...
map \G mz:%!gofmt<CR>'z
map \g mz:%!clang-format<CR>'z
map \f :w<CR>!make format<CR>
"au BufNewFile,BufRead *.go set filetype=go
map \y :.!xget<CR>
map \t :w<C-m>:!clear;go run %<C-m>
"---------------------------------------------------------------
" 2011-04-22
"
" Results of attempts to get bash (not sh but bash) syntax
" highlighting for files not ending in .bash and not having
" a #!/bin/bash line.
"
" 1. set modeline; set modelines=5. Use a per-file modeline.
" * On the modeline in the file, put vim: set filetype=bash. Does nothing
" good.
" * On the modeline in the file, put vim: set filetype=sh. Gets sh syntax
" but flags bashisms as if they were invalid.
" * On the modeline in the file, put vim: call SetFileTypeSH("bash").
" 'Error detected while processing modelines: Unknown option: call'
" Although once I'm in the file and type :call SetFileTypeSH("bash"), it
" does what I want.
"
" 2. Use entries like the following here in my ~/.vimrc:
" * au BufNewFile,BufRead baz set filetype=bash.
" Same results as with modeline.
" * au BufNewFile,BufRead baz set filetype=sh
" Same results as with modeline.
" * au BufNewFile,BufRead baz call SetFileTypeSH("bash")
" 'set verbose=9' and/or 'au baz BufRead' shows it being there.
" Likewise 'au ... echo "WTF"' results in WTF being echoed.
" Also if once in the file I type "do baz BufRead", I get what I want.
" Maybe the function *is* being called but then clobbered? set verbose=9
" isn't showing it ...
"
" 3. Put a shebang line even in files that don't need them (e.g. my
" ~/.aliases file) just to make vim use bash syntax.
"
" Solution: For Vim 7.2 patchlevel 330, anyhow, filetype.vim has the following:
"
" " Generic configuration file (check this last, it's just guessing!)
" au BufNewFile,BufRead,StdinReadPost *
" \ if !did_filetype() && expand("<amatch>") !~ g:ft_ignore_pat
" \ && (getline(1) =~ '^#' || getline(2) =~ '^#' || getline(3) =~ '^#'
" \ || getline(4) =~ '^#' || getline(5) =~ '^#') |
" \ setf conf |
" \ endif
"
" It sets filetype to conf. So SetFileTypeSH *is* getting called, and then
" this stanza *afterward* sets filetype back to conf. This is annoying.
" Now, I can replace filetype.vim at runtime. But the following is easier:
"
" a. Here in .vimrc, add an autocommand to call SetFileTypeSH("bash").
" b. *AND*, in my modeline, for each target file:
" # vim: set filetype.sh
"augroup my_bash_init_files
" au BufNewFile,BufRead .aliases,.colorrc,.vars,.vars-personal,.vars-site :call SetFileTypeSH("bash")
"augroup END