-
Notifications
You must be signed in to change notification settings - Fork 0
/
.vimrc
612 lines (519 loc) · 15.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
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
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
" ==============================================
" cmr vimrc
" ==============================================
set nocompatible " iMproved
filetype off " required
filetype plugin indent on
"setlocal spell spelllang=en_us
set nofoldenable " disable folding
" ----------------------------------
" Extremely Important Fix
" ----------------------------------
" Turn off Esc+O key sequences (eliminates one-second delay when pressing O):
" https://superuser.com/questions/161178/why-does-vim-delay-for-a-second-whenever-i-use-the-o-command-open-a-new-line#161216
" if this is re-enabled i may stab someone.
set noesckeys
set ttimeoutlen=5
" now you have to do this a second time
" (after the above lines)
set nocompatible
" ------------------------
" Lazy stuffs
" -----------------------
" https://spf13.com/post/perfect-vimrc-vim-config-file/
"
" make ; work like : to save us from Shift
" nnoremap --> extra n means normal mode only,
" nore means no recursive
nnoremap ; :
"
"""" Remove trailing whitespaces and \^M chars
"""autocmd FileType c,cpp,java,php,js,python,twig,xml,yml autocmd
"""BufWritePre <buffer> :call
"""setline(1,map(getline(1,"$"),'substitute(v:val,"\\\\s\\\\+$","","")'))
" -----------------------------------
" TwiddleCase function
" -----------------------------------
" TwiddleCase cycles a visual selection through
" lower case/UPPER CASE/Capital Case
"
" Originallly mapped to ~
" Switched to Control+P
" b/c it was not doing anything useful
function! TwiddleCase(str)
if a:str ==# toupper(a:str)
let result = tolower(a:str)
elseif a:str ==# tolower(a:str)
let result = substitute(a:str,'\(\<\w\+\>\)', '\u\1', 'g')
else
let result = toupper(a:str)
endif
return result
endfunction
"" Map twiddle to ~
"vnoremap ~ y:call setreg('', TwiddleCase(@"), getregtype(''))<CR>gv""Pgv
" Map twiddle to C-p
" (You have to have a visual selection first!!!)
" (This is complete black magic, no idea where this comes from)
vnoremap <C-p> y:call setreg('', TwiddleCase(@"), getregtype(''))<CR>gv""Pgv
" ----------------------------------------
" insert new line without leaving normal mode
" by literally typing ,o or ,O
" (this still sucks.)
" https://vi.stackexchange.com/a/3877
" ----------------------------------------
nnoremap <Leader>o o<Esc>
nnoremap <Leader>O O<Esc>
" ------------------------
" Vim Annoyances
" -----------------------
" http://blog.sanctum.geek.nz/vim-annoyances/
" don't break words with wrap on
set linebreak
" don't make these keys do annoying things
nnoremap <F1> <nop>
nnoremap J mzJ`z
nnoremap n nzz
nnoremap } }zz
nnoremap <F1> <nop>
nnoremap Q <nop>
nnoremap K <nop>
" use j and k to move among display lines, not just file lines
noremap j gj
noremap k gk
" if compiled with autocmd, jump to last cursor position
if has("autocmd")
" 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).
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal g`\"" |
\ endif
endif " has("autocmd")
" allow visual mode to go to blank space at end of lines
set virtualedit=block
" put horz./vert. splits in the right place
set splitbelow
set splitright
" ------------------------
" For Sanity
" -----------------------
" this turns on syntax highlighting
syntax on
set synmaxcol=200 " don't syntax highlight past this many chars
set ic
" this highlights search items
set hls
" this highlights search items as they are typed
set incsearch
hi IncSearch cterm=none ctermfg=blue ctermbg=green
" make searches case-insensitive, unless they contain upper-case letters:
set ignorecase
set smartcase
" toggle search highlighting:
" space after search turns off highlights and clears messages
:nnoremap <silent> <Space> :nohlsearch<Bar>:echo<CR>
" turn off splash message
set shortmess+=I
" allow backspacing after first insert spot
set backspace=indent,eol,start
" murder that cursed blinking cursor
let &guicursor = &guicursor . ",a:blinkon0"
" --------------------------
" Pathogen
" --------------------------
"
" to install vim pathogen plugin:
" mkdir -p ~/.vim/autoload ~/.vim/bundle && \
" curl -LSso ~/.vim/autoload/pathogen.vim https://tpo.pe/pathogen.vim
"
" now you need to "infect" yourself
" (questionable word choices...)
execute pathogen#infect()
" --------------------------
" Go settings
" --------------------------
"
" https://github.com/paulswanson/congo/blob/master/congo.sh
"
filetype indent plugin on
"set number
"set mouse=a
"
" to install vim-go plugin:
" git clone https://github.com/fatih/vim-go.git ~/.vim/bundle/vim-go
"
let g:go_highlight_functions = 1
let g:go_highlight_methods = 1
let g:go_highlight_structs = 1
let g:go_fmt_command = "goimports"
" ------------------------
" Filetype Settings
" -----------------------
" python
" ------------------------
" don't move comment hashtag to the first column.
" smartindent is unnecessary for python anyway.
" http://stackoverflow.com/questions/2063175/vim-insert-mode-comments-go-to-start-of-line
au! FileType python setl textwidth=0 nosmartindent
" golang
" see https://github.com/paulswanson/congo/blob/master/congo.sh
" ------------------------
au BufRead,BufNewFile *.go set textwidth=0 noexpandtab
" Makefiles
" ------------------------
au BufRead,BufNewFile Makefile*,*.make,*.mk set textwidth=0 noexpandtab
" C++
" ------------------------
au BufRead,BufNewFile *.cpp,*.cxx,*.cc,*.c,*.h,*.hpp,*.hxx,*.hh set textwidth=0 tabstop=4 shiftwidth=4 softtabstop=4 nowrap
" shell scripts
" ------------------------
au BufRead,BufNewFile *.sh set textwidth=0 noexpandtab
" Snakemake files: Snakefile, .rule, .snake, .settings, .smk
" ------------------------
au BufNewFile,BufRead set syntax=snakemake
au BufNewFile,BufRead Snakefile*,*.rule,*.snake,*.smk set syntax=snakemake
" Yaml
" ------------------------
autocmd FileType yaml setlocal ts=2 sts=2 sw=2 expandtab
" don't autoindent yaml files
filetype plugin indent on
au filetype yaml call DisableIndentY()
function! DisableIndentY()
set autoindent&
set cindent&
set smartindent&
set indentexpr&
endfunction
" Javascript
" -------------------------
au BufRead,BufNewFile *.js,*.javascript set textwidth=0 tabstop=2 shiftwidth=2 softtabstop=2 nowrap
" ------------------------
" Lines & Tabs
" ------------------------
" line numbering - make it more readable
set ruler
" eliminate line wrapping
set nowrap
" tabs are 4 spaces: the *correct* way
set tabstop=4 shiftwidth=4 expandtab
set nosmartindent " die die die
" set the text width at
" 80 or 88, whatever
set textwidth=115
" IMPORTANT -
" above directive will auto-wrap
" your text as you type it, and may
" end up driving you mad.
" Set textwidth to 0 or a different number for known (code) filetypes.
" > Bugbear's documentation explains 88 vs 80:
" > "it's like highway speed limits, we won't bother
" > you if you overdo it by a few km/h".
"
" Turn character 80/88 red
" (for visibility conforming to
" coding standards)
" https://stackoverflow.com/questions/23246962/vim-highlight-a-single-character-at-column-80#23247938
hi Bang ctermfg=red guifg=red
"match Bang /\%>87v.*\%<89v/
match Bang /\%>79v.*\%<81v/
" ---------------------------
" Spelling
" --------------------------
" correct my common typos without me even noticing them:
abbreviate teh the
abbreviate hte the
abbreviate reccommend recommend
abbreviate reccomend recommend
abbreviate recomend recommend
abbreviate slef self
abbreviate paramters parameters
abbreviate exmaple example
abbreviate improt import
abbreviate impot import
abbreviate imrpot import
abbreviate surpress suppress
abbreviate supress suppress
" ------------------------
" Tab Wild Mode
" -----------------------
" from http://dotfiles.org/~brendano/.vimrc:
" :e <tab> brings up longest; <tab> again shows list
set wildmode=longest,list
if exists('+autochdir')
" so :e is relative to current file
set autochdir
endif
" Running command :CD will change to current file's directory
com! CD cd %:p:h
" ------------------------
" Fat Fingers
" -----------------------
" allow quit via double keypress
map XX :q!<CR>
map QQ :wq<CR>
map WQ :wq<CR>
map WW :w<CR>
" for fat fingers
" http://blog.sanctum.geek.nz/vim-command-typos/
if has("user_commands")
command! -bang -nargs=? -complete=file E e<bang> <args>
command! -bang -nargs=? -complete=file W w<bang> <args>
command! -bang -nargs=? -complete=file Wq wq<bang> <args>
command! -bang -nargs=? -complete=file WQ wq<bang> <args>
command! -bang Wa wa<bang>
command! -bang WA wa<bang>
command! -bang Q q<bang>
command! -bang QA qa<bang>
command! -bang Qa qa<bang>
endif
" ------------------------
" Markdown
" -----------------------
" don't autoindent markdown files
filetype plugin indent on
au filetype mkd call DisableIndent()
function! DisableIndent()
set autoindent&
set cindent&
set smartindent&
set indentexpr&
endfunction
" fix latex highlighting in markdown
function! MathAndLiquid()
"" Define certain regions
" Block math. Look for "$$[anything]$$"
syn region math start=/\$\$/ end=/\$\$/
" inline math. Look for "$[not $][anything]$"
syn match math_block '\$[^$].\{-}\$'
" Fenced code blocks, used in GitHub Flavored Markdown (GFM)
syn region highlight_block start='```' end='```'
"" Actually highlight those regions.
hi link math Statement
hi link math_block Function
hi link highlight_block Function
endfunction
" Call everytime we open a Markdown file
autocmd BufRead,BufNewFile,BufEnter *.md,*.markdown call MathAndLiquid()
" ------------------------
" Reddit
" -----------------------
"
" Persistent Undo
if has("persistent_undo")
set undodir=~/.vim/undodir
set undofile
endif
" ------------------------
" Github Maximum Awesome
" -----------------------
"
" By default, <Leader> is \
" but that's hard to reach,
" and no one uses , anyway
let mapleader = ','
" now shortcuts are as easy as
" ,A ,B ,C
" Shift+Tab should de-indent
" Control + D is de-indent
inoremap <S-Tab> <C-d>
set autoindent
set backspace=2 " Fix broken backspace in some setups
set clipboard=unnamed " yank and paste with the system clipboard
set encoding=utf-8
set ruler " show where you are
set showcmd
set smartcase " case-sensitive search if any caps
set wildignore=log/**,node_modules/**,target/**,tmp/**,*.pyc
noremap <C-h> <C-w>h
noremap <C-j> <C-w>j
noremap <C-k> <C-w>k
noremap <C-l> <C-w>l
" in case you forgot to sudo
cnoremap w!! %!sudo tee > /dev/null %
" automatically rebalance windows on vim resize
autocmd VimResized * :wincmd =
" Fix Cursor in TMUX
if exists('$TMUX')
let &t_SI = "\<Esc>Ptmux;\<Esc>\<Esc>]50;CursorShape=1\x7\<Esc>\\"
let &t_EI = "\<Esc>Ptmux;\<Esc>\<Esc>]50;CursorShape=0\x7\<Esc>\\"
else
let &t_SI = "\<Esc>]50;CursorShape=1\x7"
let &t_EI = "\<Esc>]50;CursorShape=0\x7"
endif
" Don't copy the contents of an overwritten selection.
vnoremap p "_dP
" ====================
" modified mathias
" ====================
" " (woah.)
" Enhance command-line completion
set wildmenu
" Allow backspace in insert mode
set backspace=indent,eol,start
" Optimize for fast terminal connections
set ttyfast
""""""""""""""""""""""""
"" EVIL
"set binary
""""""""""""""""""""""""
" Don’t add empty newlines at the end of files
set noeol
" Set swap file dir
set directory=~/.vim/swap
if exists("&undodir")
set undodir=~/.vim/undo
endif
" Don’t create backups when editing files in certain directories
set backupskip=/tmp/*,/private/tmp/*
" Respect modeline in files
set modeline
set modelines=4
" Enable per-directory .vimrc files and disable unsafe commands in them
"""set exrc
"""set secure
" Enable line numbers
set number
"""""""""""""" Enable syntax highlighting
"""""""""""""syntax on
" Highlight current line
set cursorline
" Highlight searches
set hlsearch
" Ignore case of searches
set ignorecase
" Highlight dynamically as pattern is typed
set incsearch
" Always show status line
set laststatus=2
" Enable mouse in all modes
set mouse=a
" Disable error bells
set noerrorbells
" Don’t reset cursor to start of line when moving around.
set nostartofline
" Show the cursor position
set ruler
" Don’t show the intro message when starting Vim
set shortmess+=atI
" Show the current mode
set showmode
" Show the filename in the window titlebar
set title
" Show the (partial) command as it’s being typed
set showcmd
" Use relative line numbers
""" if exists("&relativenumber")
""" set relativenumber
""" au BufReadPost * set relativenumber
""" endif
" Start scrolling N lines before the horizontal window border
set scrolloff=5
" Automatic commands
if has("autocmd")
" Enable file type detection
filetype on
" Treat .json files as .js
autocmd BufNewFile,BufRead *.json setfiletype json syntax=javascript
" Treat .md files as Markdown
autocmd BufNewFile,BufRead *.md setlocal filetype=markdown
endif
" Mark special characters
"set listchars=nbsp:☠,tab:▸␣
"set listchars=tab:▸␣
"set list
" ---------------------------
" <leader> is set to , above
" and gives us a whole namespace
" of shortcuts to work with.
"
" Can map things to:
" - custom functions
" - system comands
" Show leader in bottom right
set showcmd
" Strip whitespace - trailing whitespace - with (,ss)
function! StripWhitespace()
let save_cursor = getpos(".")
let old_query = getreg('/')
:%s/\s\+$//e
call setpos('.', save_cursor)
call setreg('/', old_query)
endfunction
noremap <Leader>ss :call StripWhitespace()<cr>
" Strip annoying windows newline characters ^M
function! StripWinLineBreaks()
let save_cursor = getpos(".")
let old_query = getreg('/')
:%s///g
call setpos('.', save_cursor)
call setreg('/', old_query)
endfunction
noremap <Leader>sn :call StripWinLineBreaks()<cr>
" Save a file as root (,W)
noremap <Leader>W :w !sudo tee % > /dev/null<cr>
" ----------------------------
" colorrrzzzzz
" ----------------------------
""" set background=dark
"""
""" set t_Co=256
"""
""" function! BgToggle()
""" if &background == "light"
""" execute ":set background=dark"
""" else
""" execute ":set background=light"
""" endif
""" endfunction
""" nnoremap <F5> :call BgToggle()<cr>
" more color schemes:
"colorscheme blue
"colorscheme darkblue
"colorscheme default
"colorscheme delek
"colorscheme desert " <-- old standby
"colorscheme elflord
"colorscheme evening
"colorscheme industry
"colorscheme koehler
"colorscheme macvim
"colorscheme morning
"colorscheme murphy
"colorscheme pablo
"colorscheme peachpuff " <-- not bad
"colorscheme ron
"colorscheme shine
"colorscheme slate
"colorscheme solarized
"colorscheme torte
"colorscheme zellner
" ------------------------
" Move Faster
" ------------------------
" (these MUST go at the end)
"
" default shift + j (combines lines)
" moves to shift + L
nnoremap <S-L> :join<CR>
" shift + j and shift + k
" move up and down n lines
map <S-j> 7j
map <S-k> 7k
" Bubble text up/down
" Single line:
nmap <C-k> ddkP
nmap <C-j> ddp
" Multiple lines:
vmap <C-k> xkP`[V`]
vmap <C-j> xp`[V`]
" -----------------------------
" Jedi Autocomplete Plugin
" -----------------------------
"let g:jedi#auto_initialization = 0
"" -----------------------
"" Black shortcut
"" -----------------------
"noremap <Leader>bb :Black<cr>