~charles/dotfiles

dotfiles/overlay.lite/.vimrc -rw-r--r-- 9.2 KiB
171c95a2Charles Daniels ztag: include tags in output 8 days 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
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=light                   " assume a light 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

" https://github.com/joshukraine/dotfiles/blob/master/vim-performance.md
set re=1

" set vim backup directories
set directory=$HOME/.vimbak//
set backupdir=$HOME/.vimbak//
set undodir=$HOME/.vimbak//

" 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$

" 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
	set bg=light
	let &guifont=g:normalGUIFont

	" make the GUI be not stupid
	" +k https://stackoverflow.com/a/47212810
	set guioptions=Acek
else
	set t_Co=256 " force 256 color
	if has('nvim')
		set termguicolors  " less broken colors in 256 color terminals
	endif
	set bg=light
	set lazyredraw
endif

""""""""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

autocmd BufNewFile,BufRead *.pmd, set filetype=markdown

" 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 go 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 tcl 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()