~charles/dotfiles

ref: 720ff3de4b21a81cc3727fa3f55f5fda43500684 dotfiles/overlay/.vimrc -rw-r--r-- 15.0 KiB
720ff3deCharles Daniels clarify comment in xsession 3 years ago
                                                                                
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
" Install plugins
call plug#begin('~/.local/share/nvim/plugged')

Plug 'scrooloose/nerdtree'
Plug 'gi1242/vim-tex-syntax'
Plug 'christoomey/vim-tmux-navigator'
Plug 'heavenshell/vim-pydocstring'
Plug 'PProvost/vim-ps1'
Plug 'majutsushi/tagbar'
Plug 'scrooloose/nerdcommenter'
Plug 'godlygeek/tabular'
Plug 'Rykka/riv.vim'
Plug 'sukima/xmledit'
Plug 'twmht/jcommenter.vim'
Plug 'csexton/trailertrash.vim'
Plug 'xolox/vim-misc'
Plug 'xolox/vim-easytags'
Plug 'ctrlpvim/ctrlp.vim'
Plug 'keith/investigate.vim'
Plug 'mzlogin/vim-markdown-toc'
Plug 'vim-scripts/DoxygenToolkit.vim'
Plug 'mtth/scratch.vim'
Plug 'ledger/vim-ledger'
Plug 'lazywei/vim-matlab'
Plug 'morhetz/gruvbox'
Plug 'nathanaelkane/vim-indent-guides'
Plug 'KSP-KOS/EditorTools', {'rtp': 'VIM/vim-kerboscript'}
Plug 'tpope/vim-fugitive'
Plug 'airblade/vim-gitgutter'
Plug 'jonsmithers/vim-html-template-literals'
Plug 'pangloss/vim-javascript'
Plug 'heavenshell/vim-jsdoc'

call plug#end()

""""""""10""""""""20"""""""" platform independent """"""""60""""""""70""""""""80

filetype plugin indent on      " guess indent based on file type
syntax on                      " enable syntax highlighting
set cursorline                 " highlight the active line
hi clear CursorLine
hi CursorLine gui=underline cterm=underline cterm=underline
set number                     " use line numbering
set laststatus=2               " always render the statusline
set ignorecase                 " use case insensitive searching by default
set smartcase                  " except for when capital letters are used
set nocompatible               " fix odd behavior on some older systems
set ruler                      " display column and line number in statusline
set backspace=indent,eol,start " fix dumbass default backspace behavior
set nowrap                     " disable line wrapping
set formatoptions+=cro         " enable content continuation on enter
set bg=dark                    " assume a dark background
colorscheme default            " explicitly use the default colorscheme
set shortmess+=I               " disable welcome message on blank file
set virtualedit=block          " allow visual block past EOL
set ttyfast

" enable a nice interactive menu for tab-completing buffers and such
set wildmenu
set wildmode=longest:full,full

let mapleader=","         " use , as the leader

" enable colorcolumns if available
if exists("+colorcolumn")
	set colorcolumn=80,160,240,320,400,480,660,740,820
	hi ColorColumn ctermbg=red guibg=red
endif

" enable relative line numbering if available
if exists("+relativenumber")
	set relativenumber " enable relative numbering too
endif

" enable mouse support if available
if has("mouse")
	set mouse=a
	if !has('nvim')
		" for tmux compatibility
		set ttymouse=xterm2
	endif
endif

" Yank to system clipboard with ,yc
noremap <Leader>yc "+yy

" ,fl to fill line with char under cursor
noremap <Leader>fl y1l$80p079ld$

" Visualize Makefiles
noremap <Leader>vm :!visualize-makefile %:p <CR> <CR>

" TODO: should do something like this (http://vim.wikia.com/wiki/Indent_text_object)
" to create a visual maping so that vic/vac selects the RGB or HEX color under
" the cursor.

" colortool binding
vnoremap <silent> <leader>vc :'<,'>:w !colortool -c "$(cat /dev/stdin)" -d <CR> <CR>

" render markdown
noremap <Leader>vr :!md2txt < % \| less <CR> <CR>

" manual code folding only by default, for performance
set foldmethod=manual

" automatically unfold on new files
autocmd BufWinEnter * silent! :%foldopen!

" set cursor color in gvim
autocmd BufEnter * silent! :hi Cursor guifg=#FF0000 

" bind C-n to :noh
noremap <C-n> :noh<CR>

" tab management
noremap <C-t> :tabnew<CR>

" st-style copy-paste in gvim
if has('gui_running')
	inoremap <C-S-v> <ESC>ma:read !cliptool get<CR>mb'add'bo
	nnoremap <C-S-v> ma:read !cliptool get<CR>mb'add'b
	" for whatever reason, c works but y does not
	vnoremap <silent> <C-S-c> c<C-r>=system('cliptool copy', @")<CR><ESC>u

endif

""""""""10""""""""20""""""""30""" key mapping ""50""""""""60""""""""70""""""""80

nnoremap <F1> <nop> " don't open help with F1


""""""""10""""""""20""""""""3 platform detection 0""""""""60""""""""70""""""""80

let g:uname = substitute(system("uname"), '\n\+$', '', '')

" platform will be POSIX, NT, or UNKNOWN
" variant refers to the flavor, such as POSIX/Linux, or POSIX/BSD

let g:platform = "UNKNOWN"
let g:variant = "UNKNOWN"

if (has("win32") || has("win64"))
	let g:platform = "NT"
	let g:variant = "NT"
endif

if g:uname =~ "FreeBSD"
	let g:platform = "POSIX"
	let g:variant = "BSD"
endif

if g:uname =~ "OpenBSD"
	let g:platform = "POSIX"
	let g:variant = "OpenBSD"
	let g:easytags_cmd = "ectags"

	" the way vim allocates memory is not very performant under
	" OpenBSD, reducing the amount of lines that will be
	" syntax highlighted at once helps somewhat
	let sh_minlines=100
	let sh_maxlines=600
	set synmaxcol=300
endif

if g:uname =~ "Linux"
	let g:platform = "POSIX"
	let g:platform = "LINUX"
endif

if g:uname =~ "MINGW"
	let g:platform = "POSIX"
	let g:variant = "MINGW"
endif

if g:uname =~ "Darwin"
	let g:platform = "POSIX"
	let g:variant = "MACOS"
endif

""""""""10""""""""20""""""""3 shell configuration """"""""60""""""""70""""""""80

set shell=/bin/sh

if g:platform == "NT"
	set shell=C:\Windows\system32\cmd.exe
endif

""""""""10""""""""20""""""""30" UTF-8 handling "50""""""""60""""""""70""""""""80

let g:multibytesupport = "NO"
if has("multi_byte") || has ("multi_byte_ime/dyn")
	let g:multibytesupport = "YES"
endif

" this is a shot in the dark, and may break on very old systems
if has('gui_running')
	let g:multibytesupport = "YES"
endif

if g:multibytesupport == "YES"
	" we can only enable utf-8 if we have multi byte support compiled in
	scriptencoding utf-8
	set encoding=utf-8
	set fileencoding=utf-8
	set fileencodings=ucs-bom,utf8,prc
	set langmenu=en_US.UTF-8
endif

""""""""10""""""""20""""""""30 GUI configuration 0""""""""60""""""""70""""""""80

if has('gui_running')
	" set the GUI font
	let g:normalGUIFont="Gohufont 10"
	let g:largeGUIFont="Monospace 14"
	set bg=dark
	colorscheme gruvbox
	let &guifont=g:normalGUIFont

	" make the GUI be not stupid
	set guioptions=Ace
else
	set t_Co=256 " force 256 color
	if has('nvim')
		set termguicolors  " less broken colors in 256 color terminals
	endif
	set bg=dark
	colorscheme gruvbox
	set lazyredraw
endif

""""""""10""""""""20""""""" listchars configuration """"""60""""""""70""""""""80

" show non-printing characters

set list
set listchars=
set listchars+=trail:¬
set listchars+=precedes:«
set listchars+=extends:»
set listchars+=tab:→⋅

""""""""10""""""""20""""""""30 presentation mode 0""""""""60""""""""70""""""""80

function EnterPresentationMode()
	if has('gui_running')
		let &guifont=g:largeGUIFont
	endif
	set nolist
	hi clear SpellBad
	hi clear SpellLocal
endfunction

function ExitPresentationMode()
	if has('gui_running')
		let &guifont=g:normalGUIFont
	endif
	set list
	highlight SpellBad cterm=underline gui=underline
	highlight SpellLocal cterm=underline gui=underline
	call ApplyWorkarounds()
endfunction

""""""""10""""""""20"""""""" indentation settings """"""""60""""""""70""""""""80

function TwoSpacesSoftTabs()
	set tabstop=2
	set shiftwidth=2
	set softtabstop=2
	set expandtab
endfunction

function EightSpacesHardTabs()
	set tabstop=8
	set shiftwidth=8
	set softtabstop=8
	set noexpandtab
endfunction

function FourSpacesSoftTabs()
	set tabstop=4
	set shiftwidth=4
	set softtabstop=4
	set expandtab
endfunction

function FourSpacesHardTabs()
	set tabstop=4
	set shiftwidth=4
	set softtabstop=4
	set noexpandtab
endfunction

" use "normal" tabs n spaces by default
call EightSpacesHardTabs()

""""""""10""""""""20""""""" filetype configuration """""""60""""""""70""""""""80

" forcibly use the c filetype for all header files
autocmd BufNewFile,BufRead *.h,*.c set filetype=c

" verilog-related
autocmd BufNewFile,BufRead *.v set filetype=verilog
autocmd BufNewFile,BufRead *.tv set filetype=text

" use tex filetype for *.tex
autocmd BufNewFile,BufRead *.tex,*.sty set filetype=tex

" Handle YAML files correctly
autocmd BufNewFile,BufRead *.yml,*.yaml,Sakefile set filetype=yaml

" fix broken behaviour for CHANGELOG files
autocmd BufEnter CHANGELOG setlocal filetype=text

" because net.cdaniels.toolchest uses .lib as an extension for shell
" libraries, we shall force them to be treated as .sh
autocmd BufEnter *.lib setlocal filetype=sh

" set up tab & space behaviour sensibly
autocmd FileType c call EightSpacesHardTabs()
autocmd FileType html call FourSpacesSoftTabs()
autocmd FileType java call FourSpacesSoftTabs()
autocmd FileType javascript call FourSpacesSoftTabs()
autocmd FileType json call FourSpacesSoftTabs()
autocmd FileType matlab call FourSpacesSoftTabs()
autocmd FileType perl call EightSpacesHardTabs()
autocmd FileType python call FourSpacesSoftTabs()
autocmd FileType rst call FourSpacesSoftTabs()
autocmd FileType sh call EightSpacesHardTabs()
autocmd FileType tex call EightSpacesHardTabs()
autocmd FileType verilog call EightSpacesHardTabs()
autocmd FileType yaml call TwoSpacesSoftTabs()
autocmd FileType toml call FourSpacesSoftTabs()
autocmd FileType xml call FourSpacesSoftTabs()

""""""""10""""""""20"""" text wrapping (gq) behaviour """"60""""""""70""""""""80

" configure indenting to work gqap correctly - not working quite right at the
" moment
set showbreak=\ \\_
if exists('+breakindent')  " breakindent was not merged until 2014
	set breakindent
else
	" a more primative and hacky solution - does not work as well as
	" breakindent
	set formatoptions=l
	set lbr
endif
set formatoptions+=q  " allow gqq to wrap comments

" disable hard wrapping
set wrap linebreak textwidth=0 wrapmargin=0

""""""""10""""""""20""""""""30" spell checking "50""""""""60""""""""70""""""""80

if has("spell")
	" enable spell checking
	set spell spelllang=en_us
	set complete+=kspell " allow words as completions
	" render misspelled words with underlines, rather than highlights
	highlight clear SpellBad
	highlight clear SpellCap
	highlight clear SpellRare
	highlight clear SpellLocal
	highlight SpellBad cterm=underline gui=underline
	highlight SpellLocal cterm=underline gui=underline
endif

""""""""10""""""""20""""""""30""" workarounds ""50""""""""60""""""""70""""""""80

function ApplyWorkarounds()

	" sometimes vim cannot write to /tmp in embedded configurations like
	" Windows's git bundled POSIX environment.
	if g:platform == "NT"
		let $TMPDIR = $HOME."\\tmp"
	endif

	" Windows terminal environments do not play nice with underlining, so
	" we want to disable that on Windows, but only if the GUI is not
	" running.
	if g:platform == "NT" && !has('gui_running')
		hi clear CursorLine
		" sadly, this also affects misspellings
		hi clear SpellBad
		hi clear SpellCap
		hi clear SpellRare
		hi clear SpellLocal
	endif

endfunction

call ApplyWorkarounds()

""""""""10""""""""20""""""" NERDTree configuration """""""60""""""""70""""""""80

" also map to C-Tab in GUI mode, since some platforms behave strangely with
" C-e
if has("gui_running")
	map <C-Tab> :NERDTreeToggle<Cr>
endif

" Open NERDTree in the directory of the current file¬
" (or /home if no file is open)
" From here: https://superuser.com/a/868124

nmap <silent> <C-e> :silent! call NERDTreeToggleInCurDir()<cr>
function! NERDTreeToggleInCurDir()
	" If NERDTree is open in the current buffer
	if (exists("t:NERDTreeBufName") && bufwinnr(t:NERDTreeBufName) != -1)
		exe ":NERDTreeClose"
	else
		exe ":NERDTreeFind"
		" refresh the view
		call g:NERDTree.ForCurrentTab().getRoot().refresh() |
		call g:NERDTree.ForCurrentTab().render() |
		wincmd w
	endif
endfunction


""""""""10""""""""20"""" vim-pydocstring configuration """60""""""""70""""""""80

" C-g should generate docs in supported languages
autocmd FileType python nmap <silent> <C-g> <Plug>(pydocstring)

"""" vim-jsdoc configuration """"""""""""""""""""""""""""""""""""""""""""""""""
autocmd FileType javascript nmap <silent> <C-g> :JsDoc<cr>

""""""""10""""""""20"""""""" tagbar configuration """"""""60""""""""70""""""""80

nmap <F8> :TagbarToggle<CR>  " map tagbar to F8
let g:tagbar_type_ps1 = {
			\ 'ctagstype' : 'powershell',
			\ 'kinds'     : [
			\ 'f:function',
			\ 'i:filter',
			\ 'a:alias'
			\ ]
			\ }

""""""""10""""""""20""""" NERDCommenter configuration """"60""""""""70""""""""80

let g:NERDSpaceDelims = 1  " spaces after comment char
let g:NERDDefaultAlign = 'left'  " align comments to left edge of file
let g:NERDCommentEmptyLines = 1  " allow empty lines to be commented

""""""""10""""""""20"""""""" riv.vim configuration """""""60""""""""70""""""""80

let g:riv_global_leader = "<C-U>"
let g:riv_fold_level = 1
let g:riv_fold_blank = 1
let g:riv_file_link_style = 2 " Sphinx cross reference syntax

let project1 = {
		\ 'Name': 'wiki',
		\ 'path': '~/src/git/wiki-next/source',
		\ 'scratch_path': 'Diary'}
let g:riv_projects = [project1]

" vimwiki-like bindings, for convenience
nmap <Leader>ww <C-U>ww zR
nmap <Leader>sc <C-U>sc zR

" build wiki using ,wb
nmap <Leader>wb :! ~/src/git/wiki-next/build_wiki.sh  <enter>

""""""""10""""""""20"""""" jcommenter configuration """"""60""""""""70""""""""80

autocmd FileType java nmap <silent> <C-g> :call JCommentWriter()<CR>
autocmd FileType java let b:jcommenter_class_author=system('git config user.name')
autocmd FileType java let b:jcommenter_file_author=system('git config user.email')

""""""""10""""""""20""""" TrailerTrash configuration """""60""""""""70""""""""80

" note that I just want :TrailerTrim, so I disable hilighting like so
autocmd BufEnter * TrailerHide
autocmd InsertLeave * TrailerHide
nnoremap <Leader>tt :TrailerTrim<CR>

""""""""10""""""""20""""""""3 ctrlP configuration """"""""60""""""""70""""""""80

" show dotfiles
let g:ctrlp_show_hidden = 1
let g:ctrlp_dotfiles = 1
let g:ctrlp_working_path_mode = 'a'
let g:ctrlp_switch_buffer = 0
let g:ctrlp_max_depth = 100
let g:ctrlp_max_files = 500000

""""""""10""""""""20"""" investigate.vim configuration """60""""""""70""""""""80

let g:investigate_use_dash=1  " use dash on OSX

""""""""10""""""""20"" vim-tmux-navigator configuration ""60""""""""70""""""""80

function MapTmuxNavigator ()
	noremap<silent> <C-h> :TmuxNavigateLeft<cr>
	noremap<silent> <C-j> :TmuxNavigateDown<cr>
	noremap<silent> <C-k> :TmuxNavigateUp<cr>
	noremap<silent> <C-l> :TmuxNavigateRight<cr>
endfunction

" other plugins insist on overriding vim-tmux-navigator's bindings
autocmd BufEnter,BufWritePost * call MapTmuxNavigator()

call MapTmuxNavigator()

""""""""10""""""""20""" vim-markdown-toc configuration """60""""""""70""""""""80
" auto update TOC on save
let g:vmt_auto_update_on_save = 1

""""""""10""""""""20""""""""30" DoxygenToolkit "50""""""""60""""""""70""""""""80

autocmd FileType c nmap <silent> <C-g> :Dox <CR>

""""""""10""""""""20""""""""30" indentGuide    "50""""""""60""""""""70""""""""80

if has('gui_running')
	let g:indent_guides_enable_on_vim_startup = 1
endif

"" fugative.vim """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set statusline=%<%f\ %h%m%r%=%-14.(%l,%c%V%)\ %{FugitiveStatusline()}\ %P

"" vim-html-temlate-literals """"""""""""""""""""""""""""""""""""""""""""""""""

let g:html_indent_style1 = "inc"

"" easytags """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

let g:easytags_async = 1