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
|
if !has('gui_running')
set t_Co=256
endif
set nocompatible
filetype off
""""""""""""
" VUNDLE "
""""""""""""
execute 'set rtp+=' . split(&rtp, ',')[0] . '/bundle/Vundle.vim'
call vundle#begin()
Plugin 'gmarik/Vundle.vim'
"FILETYPES
Plugin 'kchmck/vim-coffee-script'
Plugin 'rhysd/vim-crystal'
Plugin 'elixir-lang/vim-elixir'
Plugin 'plasticboy/vim-markdown'
Plugin 'shmibs/mips.vim'
Plugin 'zah/nim.vim'
Plugin 'wlangstroth/vim-racket'
Plugin 'rust-lang/rust.vim'
Plugin 'cakebaker/scss-syntax.vim'
Plugin 'cespare/vim-toml'
Plugin 'ziglang/zig.vim'
"FUNCTIONALITY
Plugin 'junegunn/vim-easy-align'
Plugin 'xolox/vim-misc'
Plugin 'shmibs/vim-easytags'
Plugin 'tommcdo/vim-exchange'
Plugin 'lilydjwg/fcitx.vim'
Plugin 'airblade/vim-gitgutter'
Plugin 'junegunn/goyo.vim'
Plugin 'sjl/gundo.vim'
Plugin 'itchyny/lightline.vim'
Plugin 'tomtom/tcomment_vim'
Plugin 'SirVer/ultisnips'
Plugin 'honza/vim-snippets'
call vundle#end()
"""""""""""""""""""""
" PLUGIN SETTINGS "
"""""""""""""""""""""
"Start interactive EasyAlign in visual mode (e.g. vip<Enter>)
vmap <Enter> <Plug>(EasyAlign)
"Start interactive EasyAlign for a motion/text object (e.g. gaip)
nmap ga <Plug>(EasyAlign)
"timeout on keycodes to prevent fcitx-switcher from lagging
set ttimeoutlen=100
"toggle gundo pane
nnoremap <Leader>u :GundoToggle<CR>
"snippet bindings
let g:UltiSnipsExpandTrigger="<tab>"
let g:UltiSnipsJumpForwardTrigger="<c-m>"
let g:UltiSnipsJumpBackwardTrigger="<c-,>"
"lightline colours. modded from 16color
function! s:Lightline_palette_init()
let l:black = [ '#000000', 0 ]
let l:lblack = [ '#808080', 8 ]
let l:red = [ '#800000', 1 ]
let l:lred = [ '#ff0000', 9 ]
"let l:green = [ '#008000', 2 ]
"let l:lgreen = [ '#00ff00', 10 ]
let l:yellow = [ '#808000', 3 ]
"let l:lyellow = [ '#ffff00', 11 ]
let l:blue = [ '#000080', 4 ]
"let l:lblue = [ '#0000ff', 12 ]
let l:magenta = [ '#800080', 5 ]
"let l:lmagenta = [ '#ff00ff', 13 ]
"let l:cyan = [ '#008080', 6 ]
"let l:lcyan = [ '#00ffff', 14 ]
let l:white = [ '#c0c0c0', 7 ]
let l:lwhite = [ '#ff00ff', 15 ]
let l:p = {'normal': {}, 'inactive': {}, 'insert': {}, 'replace': {}, 'visual': {}, 'tabline': {}}
let l:p.normal.left = [ [ l:lwhite, l:blue ], [ l:lwhite, l:lblack ] ]
let l:p.normal.right = [ [ l:black, l:white ], [ l:lwhite, l:lblack ] ]
let l:p.inactive.right = [ [ l:lblack, l:black ], [ l:lblack, l:black ] ]
let l:p.inactive.left = [ [ l:lblack, l:black ], [ l:lblack, l:black ] ]
let l:p.insert.left = [ [ l:lwhite, l:magenta ], [ l:lwhite, l:lblack ] ]
let l:p.replace.left = [ [ l:lwhite, l:lred ], [ l:lwhite, l:lblack ] ]
let l:p.visual.left = [ [ l:white, l:red ], [ l:lwhite, l:lblack ] ]
let l:p.normal.middle = [ [ l:white, l:black ] ]
let l:p.inactive.middle = [ [ l:white, l:black ] ]
let l:p.tabline.left = [ [ l:white, l:black ] ]
let l:p.tabline.tabsel = [ [ l:white, l:black ] ]
let l:p.tabline.middle = [ [ l:black, l:white ] ]
let l:p.tabline.right = copy(l:p.normal.right)
let l:p.normal.error = [ [ l:white, l:red ] ]
let l:p.normal.warning = [ [ l:white, l:yellow ] ]
let g:lightline#colorscheme#shmibs#palette = lightline#colorscheme#flatten(l:p)
let g:lightline = {
\ 'active': {
\ 'right': [ [ 'lineinfo' ],
\ [ 'percent' ],
\ [ 'filetype' ] ]
\ }, 'colorscheme': 'shmibs' }
endfunction
call s:Lightline_palette_init()
"async easytags
let g:easytags_async = 1
let g:easytags_always_enabled = 1
"opam stuff
if executable("opam")
let s:opam_share_dir = system("opam config var share")
let s:opam_share_dir = substitute(s:opam_share_dir, '[\r\n]*$', '', '')
let s:opam_configuration = {}
function! OpamConfOcpIndent()
execute "set rtp^=" . s:opam_share_dir . "/ocp-indent/vim"
endfunction
let s:opam_configuration['ocp-indent'] = function('OpamConfOcpIndent')
function! OpamConfOcpIndex()
execute "set rtp+=" . s:opam_share_dir . "/ocp-index/vim"
endfunction
let s:opam_configuration['ocp-index'] = function('OpamConfOcpIndex')
function! OpamConfMerlin()
let l:dir = s:opam_share_dir . "/merlin/vim"
execute "set rtp+=" . l:dir
endfunction
let s:opam_configuration['merlin'] = function('OpamConfMerlin')
let s:opam_packages = ["ocp-indent", "ocp-index", "merlin"]
let s:opam_check_cmdline = ["opam list --installed --short --safe --color=never"] + s:opam_packages
let s:opam_available_tools = split(system(join(s:opam_check_cmdline)))
for tool in s:opam_packages
" Respect package order (merlin should be after ocp-index)
if count(s:opam_available_tools, tool) > 0
call s:opam_configuration[tool]()
endif
endfor
endif
""""""""""""""""""""""
" GENERAL SETTINGS "
""""""""""""""""""""""
syntax on
filetype plugin indent on
set autoindent
"top-level folds only
set foldnestmax=1
colorscheme shmibs
"close modeline security hole
set nomodeline
set modelines=0
"revert annoying neovim cursor
set guicursor=i-ci-ve-r-cr-o-n-v-c-sm:block-blinkon200
"enable status-line
set laststatus=2
"hide mode in cmd
set noshowmode
"allow edited background buffers
set hidden
set title
"spelling
set spelllang=en_gb
"visual marker for overflowing the 80th column
highlight Overwide ctermbg=8
call matchadd('Overwide', '\%81v', 100)
"highlight space before tab
highlight SpaceBeforeTab ctermbg=red
call matchadd('SpaceBeforeTab', '\ \t')
"get rid of that annoying yellow explosion everywhere
"that neovim sets as default
set nohlsearch
set encoding=utf-8
set fileencoding=utf-8
"""""""""""""
" ALIASES "
"""""""""""""
"i keep accidentally typing these over and over
command W w
command Wq wq
command WQ wq
command Q q
command E e
""""""""""""""
" MAPPINGS "
""""""""""""""
"insert lines below
nnoremap <silent>= :set paste<CR>m`O<Esc>``:set nopaste<CR>
"folds!
nnoremap fo zO
nnoremap fc zC
nnoremap fm zM
nnoremap fr zR
"buffer-handling
nnoremap <C-j> :bn<CR>
nnoremap <C-k> :bp<CR>
nnoremap <C-g> :buffers<CR>:b<Space>
"copy words from above and below the cursor
inoremap <expr> <C-y> pumvisible() ? "\<C-y>" : matchstr(getline(line('.')-1), '\%' . virtcol('.') . 'v\%(\k\+\\|.\)')
inoremap <expr> <C-e> pumvisible() ? "\<C-e>" : matchstr(getline(line('.')+1), '\%' . virtcol('.') . 'v\%(\k\+\\|.\)')
"use the X clipboard for things when running in a virtual terminal, because yes
if &term != "linux" && has('clipboard')
nnoremap <expr> y (v:register ==# '"' ? '"+' : '') . 'y'
nnoremap <expr> Y (v:register ==# '"' ? '"+' : '') . 'Y'
xnoremap <expr> y (v:register ==# '"' ? '"+' : '') . 'y'
xnoremap <expr> Y (v:register ==# '"' ? '"+' : '') . 'Y'
nnoremap <expr> d (v:register ==# '"' ? '"+' : '') . 'd'
nnoremap <expr> D (v:register ==# '"' ? '"+' : '') . 'D'
xnoremap <expr> d (v:register ==# '"' ? '"+' : '') . 'd'
xnoremap <expr> D (v:register ==# '"' ? '"+' : '') . 'D'
nnoremap <expr> p (v:register ==# '"' ? '"+' : '') . 'p'
nnoremap <expr> P (v:register ==# '"' ? '"+' : '') . 'P'
xnoremap <expr> p (v:register ==# '"' ? '"+' : '') . 'p'
xnoremap <expr> P (v:register ==# '"' ? '"+' : '') . 'P'
end
"""""""""""""""""""""""
" FILETYPE SETTINGS "
"""""""""""""""""""""""
"annoying syntax-related values that need to be set before files are
"opened
let g:c_no_comment_fold = 1
let g:c_no_if0_fold = 1
let g:sh_fold_enabled = 1
if has("autocmd")
"set various filetype-specific settings.
augroup filetypesettings
au FileType asm call Settings_asm()
au FileType bash call Settings_shell()
au FileType c call Settings_c()
au FileType coffee call Settings_coffee()
au FileType conf call Settings_conf()
au FileType cpp call Settings_c()
au FileType crystal call Settings_crystal()
au FileType cs call Settings_c()
au FileType css call Settings_css()
au FileType d call Settings_c()
au FileType elixir call Settings_elixir()
au FileType javascript call Settings_c()
au FileType tex call Settings_tex()
au FileType haskell call Settings_haskell()
au FileType html call Settings_html()
au FileType xhtml call Settings_html()
au FileType ia64 call Settings_ia64()
au FileType make call Settings_script()
au FileType mail call Settings_mail()
au FileType markdown call Settings_markdown()
au FileType matlab call Settings_matlab()
au FileType mips call Settings_mips()
au FileType mkd call Settings_text()
au FileType nim call Settings_nim()
au FileType ocaml call Settings_ocaml()
au FileType perl call Settings_perl()
au FileType php call Settings_html()
au FileType python call Settings_script()
au FileType ruby call Settings_elixir ()
au FileType rust call Settings_rust()
au FileType scss call Settings_css()
au FileType sh call Settings_script()
au FileType text call Settings_text()
au FileType vim call Settings_vim()
au FileType yaml call Settings_script2()
au FileType zig call Settings_c()
au FileType zsh call Settings_shell()
au FileType z80 call Settings_z80()
augroup END
"do other stuff
augroup filetypemisc
au FileType * call Settings_skel_read()
augroup END
endif "autocmd
"command for reading filetype skeletons
function! Settings_skel_read()
"is the buffer not empty?
if line('$') != 1 || col('$') != 1
return 1
end
"is there no template?
if filereadable(split(&rtp, ',')[0] . "/skel/" . &ft) == 0
return 1
end
execute 'silent! r ' . split(&rtp, ',')[0] . "/skel/" . &ft
"read the date into %DATE%
execute '%s/%DATE%/' . system("date '+%a, %B %d, %Y'|tr -d '\n'") . '/ge'
"move cursor to %START%
execute "silent! normal! ggJ/%START%\<CR>:s/%START%//\<CR>"
endfunction
"a 'writing mode' for prose-y formats
function! Settings_sub_wmodetoggle()
if &fo =~ 'a'
setlocal formatoptions-=a
Goyo!
echo 'wmode off'
else
setlocal formatoptions+=a
Goyo
echo 'wmode on'
end
endfunction
function! Settings_asm()
"settings
setlocal foldmethod=syntax
"mappings
nnoremap <buffer> -- A<Tab>;<Space>
nnoremap <buffer> -_ O;<Space>
endfunction
function! Settings_c()
"settings
setlocal foldmethod=syntax
setlocal shiftwidth=4
setlocal tabstop=4
setlocal softtabstop=4
"mappings
"note: these mappings are in weird reverse order to avoid opening folds
nnoremap <buffer> -- O<Space>*/<Esc>hhi/*<Space>
inoremap <buffer> {<CR> }<Esc>i{<CR><Esc>O
endfunction
function! Settings_coffee()
call Settings_script2()
setlocal foldmethod=syntax
nnoremap <buffer> -_ O###<CR><C-u>###<Esc>O<C-u>
endfunction
function! Settings_conf()
call Settings_script()
setlocal expandtab
endfunction
function! Settings_crystal()
call Settings_script2()
setlocal expandtab
endfunction
function! Settings_css()
call Settings_c()
"settings
setlocal shiftwidth=2
setlocal tabstop=2
setlocal softtabstop=2
"mappings
endfunction
function! Settings_elixir()
call Settings_script2()
inoremap <buffer> do<CR> end<Esc>hhido<CR><Esc>O
endfunction
function! Settings_ia64()
"settings
setlocal foldmethod=syntax
"mappings
nnoremap <buffer> -- A<Space>*/<Esc>hhi<Tab>/*<Space>
nnoremap <buffer> -_ O<Space>*/<Esc>hhi/*<Space>
endfunction
function! Settings_haskell()
"settings
setlocal shiftwidth=4
setlocal tabstop=4
setlocal softtabstop=4
setlocal expandtab
"mappings
nnoremap <buffer> -- O--<Space>
endfunction
function! Settings_html()
"settings
setlocal foldmethod=syntax
setlocal shiftwidth=4
setlocal tabstop=4
setlocal softtabstop=4
"mappings
nnoremap <buffer> -- O<Space>--><Esc>3hi<!--<Space>
endfunction
function! Settings_markdown()
"settings
setlocal shiftwidth=4
setlocal tabstop=4
setlocal softtabstop=4
setlocal nojoinspaces
setlocal spell
"mappings
nnoremap <buffer> -- O<Space>--><Esc>3hi<!--<Space>
nnoremap <buffer> <Leader>w :call Settings_sub_wmodetoggle()<CR>
endfunction
function! Settings_mail()
"settings
setlocal spell
"mappings
nnoremap <buffer> <Leader>w :call Settings_sub_wmodetoggle()<CR>
endfunction
function! Settings_matlab()
"settings
setlocal shiftwidth=4
setlocal tabstop=4
setlocal softtabstop=4
"mappings
nnoremap <buffer> -- O%<Space>
endfunction
function! Settings_mips()
"settings
setlocal shiftwidth=6
setlocal tabstop=6
setlocal softtabstop=6
"mappings
nnoremap <buffer> -- A<Tab>#<Space>
nnoremap <buffer> -_ O#<Space>
endfunction
function! Settings_nim()
call Settings_script()
nnoremap <buffer> -- O<Space>]#<Esc>hhi#[<Space>
endfunction
function! Settings_ocaml()
"settings
setlocal shiftwidth=2
setlocal tabstop=2
setlocal softtabstop=2
"mappings
nnoremap <buffer> -- O<Space>*)<Esc>hhi(**<Space>
nnoremap <buffer> -_ A<Space>*)<Esc>hhi(*<Space>
endfunction
function! Settings_script()
"settings
setlocal shiftwidth=4
setlocal tabstop=4
setlocal softtabstop=4
"mappings
nnoremap <buffer> -- O#<Space>
endfunction
function! Settings_script2()
"settings
setlocal shiftwidth=2
setlocal tabstop=2
setlocal softtabstop=2
"mappings
nnoremap <buffer> -- O#<Space>
endfunction
function! Settings_perl()
call Settings_script()
inoremap <buffer> {<CR> }<Esc>i{<CR><Esc>O
endfunction
function! Settings_rust()
call Settings_c()
nnoremap <buffer> -_ O///<Space>
endfunction
function! Settings_shell()
call Settings_script()
inoremap <buffer> {<CR> }<Esc>i{<CR><Esc>O
endfunction
function! Settings_tex()
"settings
setlocal noautoindent
setlocal nocindent
setlocal nosmartindent
setlocal nojoinspaces
setlocal shiftwidth=4
setlocal tabstop=4
setlocal softtabstop=4
setlocal spell
"mappings
nnoremap <buffer> -- O%<Space>
nnoremap <buffer> <Leader>c :!latex -output-format=pdf "%"<CR><CR>
nnoremap <buffer> <Leader>C :!latex -output-format=pdf "%"<CR>
nnoremap <buffer> <Leader>x :!xelatex "%"<CR><CR>
nnoremap <buffer> <Leader>X :!xelatex "%"<CR>
nnoremap <buffer> <Leader>w :call Settings_sub_wmodetoggle()<CR>
endfunction
function! Settings_text()
"settings
setlocal noautoindent
setlocal nocindent
setlocal nosmartindent
setlocal nojoinspaces
setlocal shiftwidth=4
setlocal tabstop=4
setlocal softtabstop=4
setlocal spell
"mappings
nnoremap <buffer> <Leader>w :call Settings_sub_wmodetoggle()<CR>
endfunction
function! Settings_vim()
"settings
setlocal shiftwidth=4
setlocal tabstop=4
setlocal softtabstop=4
"mappings
nnoremap <buffer> -- O"
endfunction
function! Settings_z80()
"settings
setlocal shiftwidth=6
setlocal tabstop=6
setlocal softtabstop=6
"mappings
nnoremap <buffer> -- A<Tab>;<Space>
nnoremap <buffer> -_ O;<Space>
endfunction
|