-
Notifications
You must be signed in to change notification settings - Fork 1
/
vimrc
432 lines (355 loc) Β· 13.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
let g:slime_no_mappings = 1 " needs to be before it loads.. hm
filetype plugin indent on " important options
syntax on " turn on syntax highlighting
let lightscheme = 'komau'
let darkscheme = 'apprentice'
execute 'colorscheme ' . darkscheme
let g:copilot_enabled = 1
let mapleader = "\<Space>"
inoremap <C-\> <Plug>(copilot-suggest)
set autoindent " dont need smartindent. syntax files do that
set encoding=utf-8 " encoding
set hidden " allow hidden buffers
set iskeyword+=-
set laststatus=2 " always show status bar
set linebreak " breaks on space + :set breakat?
set modelines=1 " security
set noequalalways " don't equalize window sizes when splitting
set ruler " show file stats
set signcolumn=number
set t_vb= " dont beep
set termguicolors
set visualbell " dont blink
set mouse=a " enable mouse
" TODO don't offer to open certain files/directories
set wildignore+=*.bmp,*.gif,*.ico,*.jpg,*.png,*.ico
set wildignore+=*.pdf,*.psd,*.com,*.tdy,*.dll,*.exe
set wildignore+=*.o,*.obj,*.so,*.a,*.lib;
set wildignore+=bower_components/*,*/.vim/junk/*
set wildignore+=**/node_modules/**
inoremap <C-l> Ξ»
" use existing tab if possible when loading a file from quickfix
set switchbuf+=usetab
nnoremap <Leader>ch <Cmd>Chistory<Cr>
" whitespace
set nowrap
set textwidth=0
set formatoptions=tcqrn1
set shiftwidth=2
set softtabstop=2
set expandtab
set noshiftround
" ui
set lazyredraw " make things like macros run faster
set wildmenu
set wildmode=list:full
set shortmess+=WI
" cursor motion
set scrolloff=1
set backspace=indent,eol,start
set matchpairs+=<:> " use % to jump between pairs
set whichwrap+=<,>,h,l,[,] " wrap cursor on more shit
" folds
set foldmethod=indent
set foldnestmax=10
set foldlevelstart=10
" last line
set showmode
set showcmd
" searching
set hlsearch
set incsearch
set ignorecase
set smartcase
set showmatch
" formatting
set nojoinspaces
nnoremap <space>q gggqG
" visualize tabs and newlines
set listchars=tab:βΈ\ ,eol:Β¬
let &showbreak = 'β³ '
" set guitablabel=%f
set guitablabel=%t
" undo/backup shit
set backupdir=~/.vim/junk/backup// " double slash means files are stored with
set directory=~/.vim/junk/swp// " full path, to eliminate clobbering
set undodir=~/.vim/junk/undo//
set viewdir=~/.vim/junk/view//
set undofile
set undolevels=1000
set undoreload=10000
set backupcopy=yes
" change cursor from block to i-beam in insert mode
" https://vim.fandom.com/wiki/Change_cursor_shape_in_different_modes
" may need but idk: autocmd VimEnter * silent !echo -ne "\e[1 q"
let &t_SI = "\e[5 q"
let &t_EI = "\e[1 q"
" window management
set splitright
nmap <c-n> :SC<cr>
nmap <c-c> :q<cr>
" maximize
nnoremap <C-w>\ <C-w>\|<C-w>_
" mode exit
imap jj <esc>
" kill highlight
map <space>l :let @/=''<cr>
nnoremap gf gF
nnoremap gF gf
" kill whitespace
nnoremap <silent> <space>W :%s/\s\+$//<cr>:let @/=''<cr>
" vimrc
nnoremap <silent> <space>ev :edit ~/.vim/vimrc<cr>
nnoremap <silent> <space>es :edit ~/.vim/after/plugin/settings.vim<cr>
nnoremap <silent> <space>rv :source ~/.vim/vimrc<cr>
nnoremap <silent> <space>er :edit ~/lisp/notes/learnxiny.rkt<cr>
nnoremap <silent> <space>eg :edit ~/.vim/tools/gpt/<cr>
nnoremap <silent> <space>el :edit ~/brain/journals/<cr>
nnoremap <silent> <space>eu :edit ~/txt/unicode.txt<cr>
nnoremap <silent> <space>ei :edit ~/.config/i3/config<cr>
nnoremap <silent> <space>eb :edit ~/.bashrc<cr>
nnoremap <silent> <space>ex :edit ~/.Xdefaults<cr>
nnoremap <silent> <space>ed :edit ~/projects/xom.world/txt/shmup.crawlrc<cr>
nnoremap <silent> <space>et :edit ~/.tmux.conf<cr>
nnoremap <silent> <space>ef :edit ~/.mozilla/firefox/jtm/chrome/userChrome.css<cr>
nnoremap <silent> <space>ec :edit ~/.vim/coc-settings.json<cr>
nnoremap <silent> <space>ea :edit ~/.config/alacritty/alacritty.toml<cr>
" alt-tab between two buffers
nnoremap <space><space> :b#<cr>
" better window changing
map <C-h> <C-w>h
map <C-j> <C-w>j
map <C-k> <C-w>k
map <C-l> <C-w>l
" make Y like C/D
nnoremap Y y$
" toggles, also :help *unimpaired-toggling*
" https://github.com/tpope/vim-unimpaired/blob/master/doc/unimpaired.txt#L77-L95
nnoremap <silent><expr>yot printf(":set bg=%s \| colo %s\r", &bg ==# 'dark' ? 'light' : 'dark', &bg ==# 'dark' ? lightscheme : darkscheme)
nnoremap <silent>yog :GitGutterToggle<cr>
nnoremap <silent>yoS :SCREAM<CR>
nnoremap <silent>yoW :WHISPER<CR>
nnoremap <silent>yoz :syntax sync fromstart<CR>
nnoremap yoo :ToggleChad<CR>
nmap ,q <Plug>(qf_qf_switch)
nmap ,Q <Plug>(qf_qf_toggle_stay)
" just do it
inoremap <C-x> β
nnoremap <leader>j :% !jq .<CR>
nnoremap j gj
nnoremap k gk
" easier change and replace word
nnoremap c* *Ncgn
nnoremap c# #NcgN
nnoremap cg* g*Ncgn
nnoremap cg# g#NcgN
" change to file dir, repo dir, or Z result
nnoremap <silent> ,cd :lcd %:p:h<cr>
nnoremap <silent> ,cr :lcd <c-r>=FugitiveWorkTree()<cr><cr>
nnoremap ,z :Z<space>
nnoremap ,e :silent Zedit<space>
" auto expansion
inoremap (<cr> (<cr>)<esc>O
inoremap `<cr> `<cr>`<esc>O
inoremap {<cr> {<cr>}<esc>O
inoremap {; {<cr>};<esc>O
" inoremap {, {<cr>},<esc>O
inoremap [<cr> [<cr>]<esc>O
inoremap [; [<cr>];<esc>O
" inoremap [, [<cr>],<esc>O
" keep cursor put
nnoremap * *``
nnoremap # #``
nnoremap g* g*``
nnoremap g# g#``
" quicker buffer
nnoremap gb :ls<cr>:buffer<space>
nnoremap gB :ls<cr>:sbuffer<space>
" find mappings
nnoremap ,f :find *
nnoremap ,s :sfind *
nnoremap ,v :vert sfind *
nnoremap ,F :find ./**/*
nnoremap ,S :sfind ./**/*
nnoremap ,V :vert sfind ./**/*
nnoremap ,t :tabfind *
nnoremap ,T :tabfind ./**/*
nnoremap <silent> ,cl :CocCommand document.toggleCodeLens<CR>
nnoremap <silent> ,cp :silent! let g:copilot_enabled = !get(g:, 'copilot_enabled', v:false) \| let b:copilot_enabled = g:copilot_enabled \| echo "Copilot " . (g:copilot_enabled ? "enabled" : "disabled")<CR>
" augroup CopilotSync
" autocmd!
" autocmd BufEnter * if !exists('b:copilot_enabled') | let b:copilot_enabled = get(g:, 'copilot_enabled', 0) | endif
" augroup END
" let me save with sudo when needed
cmap w!! %!sudo tee > /dev/null %
" yank and delete to system clipboard
vnoremap <space>y "+y
vnoremap <space>d "+d
" it's a mood thing
command! BufOnly silent! execute "%bd|e#|bd#"
nnoremap <space>o :only<cr>
nnoremap <space>O :BufOnly<cr>
" tab nav
nnoremap <space>tn :tabnew<cr>:tabmove 0<cr>
nnoremap <space>tN :tabnew<cr>
nnoremap <space>tc :tabclose<cr>
nnoremap <space>to :tabonly<cr>
for i in range(1, 9)
execute 'nnoremap <Space>'.i.' '.i.'gt'
execute 'nnoremap <Space>tm'.i.' :tabmove '.(i-1).'<CR>'
endfor
" easy align
vmap <enter> <plug>(EasyAlign)
" xmap ga <plug>(EasyAlign)
" nmap ga <plug>(EasyAlign)
" GoTo code navigation.
nmap <silent><space>m :CocList --height=10 diagnostics<cr>
nmap <silent><space>M :CocDiagnostics 10<cr>
nmap <silent> gd <Plug>(coc-definition)
nmap <silent> gy <Plug>(coc-type-definition)
nmap <silent> gi <Plug>(coc-implementation)
nmap <silent> gr <Plug>(coc-references)
" inoremap <silent><expr> <tab> coc#refresh()
" fugitive/rhubarb/gv
nmap <space>gb :Git blame<cr>
nmap <space>gs :Git<cr>
nmap <space>ge :Gedit<cr>
nmap <space>gc :Gcommit -v<cr>
nmap <space>gn :Gcommit -v --no-verify<cr>
nmap <space>gm :Gcommit -v --amend<cr>
nmap <space>gp :Gpush<cr>
nmap <space>gl :BCommits<cr>
nmap <space>gL :GcLog<cr>
nmap <space>gd :Gdiffsplit<cr>
nmap <space>gw :Gwrite<cr>
nmap <silent> [g <Plug>(coc-diagnostic-prev)
nmap <silent> ]g <Plug>(coc-diagnostic-next)
" gutter
nmap [c <plug>(GitGutterPrevHunk)
nmap ]c <plug>(GitGutterNextHunk)
nmap <space>hs <Plug>(GitGutterStageHunk)
nmap <space>hu <Plug>(GitGutterUndoHunk)
nmap <space>hv <Plug>(GitGutterPreviewHunk)
set statusline=%3l " show the line number
set statusline+=, " and a comma
set statusline+=%v " show the virtual column number
set statusline+=\ " and two spaces
set statusline+=( " and a (
set statusline+=%{strlen(@\")} " byte count in register
set statusline+=)\ " and a )
set statusline+=%{printf('x%X',char2nr(getline('.')[getpos('.')[2]-1]))}
set statusline+=\ " and two spaces
set statusline+=%Y " show the filetype
set statusline+=\ " and two spaces
set statusline+=%{ObsessionStatus('πΎ\ ','')}
" set statusline+=%{get(b:,'copilot_enabled',0)?'π\':'π'}
set statusline+=\ " and two spaces
set statusline+=%{g:coc_enabled?'π':'π΄'}
set statusline+=\ " and two spaces
set statusline+=%= " move to the right side
set statusline+=%<%F " (truncated) full path to the file we are editing
set statusline+=%m " [+] if the file is modified but not saved
set statusline+=%r " show [RO] if a file is read-only
command! -range GOpen execute 'silent ! git browse ' . expand('%') . ' ' . <line1> . ' ' . <line2> | checktime | redraw!
" Show words and codes as colors, coc.nvim does this in some filetypes
command! CT silent! execute "ColorToggle"
" show the groupings under cursor
command! SS echo map(synstack(line('.'), col('.')), 'synIDattr(v:val, "name")')
" Tig current file
command! Tig execute "Start tig " . expand('%:p')
" scratch buffer
command! SC vnew | setlocal nobuflisted buftype=nofile nospell filetype=markdown bufhidden=wipe noswapfile
command! JS vsplit ~/tmp/tmp.js | setlocal nobuflisted nospell filetype=javascript bufhidden=wipe noswapfile
command! Workspaced let g:copilot_workspace_folders = FugitiveWorkTree()
augroup Convenience
" get completions from current syntax file
autocmd BufEnter * exec('setlocal complete+=k$VIMRUNTIME/syntax/'.&ft.'.vim')
" let ignorelist =['vim', 'help', 'perl', 'sh', 'racket']
" autocmd Filetype * if (index(ignorelist, &ft) == -1)
" \ | let &l:keywordprg=fnamemodify($MYVIMRC, ":h") . "/tools/search.sh " . &l:filetype | endif
" jump to last cursor position
autocmd BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal! g'\"" | endif
" https://vi.stackexchange.com/a/69/287
" prevents unmodified buffer + crash = bullshit swap file
autocmd CursorHold,BufWritePost,BufReadPost,BufLeave *
\ if isdirectory(expand("<amatch>:h")) | let &swapfile = &modified | endif
augroup END
augroup CursorLine
autocmd!
autocmd VimEnter,WinEnter,BufWinEnter * setlocal cursorline
autocmd WinLeave * setlocal nocursorline
augroup END
function! WrapWithAsciiWalls(style) range
let l:start = a:firstline
let l:end = a:lastline
if a:firstline == 0 && a:lastline == 0
let l:start = line('.')
let l:end = l:start
endif
let l:lines = getline(l:start, l:end)
" Determine the wrapping characters based on the style parameter.
let l:wrap_chars = get({
\ 'H': ['ββββ ', ' ββββ'],
\ 'H2': ['βββ ', ' βββ'],
\ 'H3': ['ββ ', ' ββ'],
\ 'H4': ['β ', ' β'],
\ }, a:style, v:null)
if l:wrap_chars is v:null
throw "Invalid style: ".a:style
endif
" Apply wrapping characters to each line.
let l:wrapped_lines = map(l:lines, '"'.l:wrap_chars[0].'" . v:val . "'.l:wrap_chars[1].'"')
call setline(l:start, l:wrapped_lines)
endfunction
command! -range H <line1>,<line2>call WrapWithAsciiWalls('H')
command! -range H1 <line1>,<line2>call WrapWithAsciiWalls('H1')
command! -range H2 <line1>,<line2>call WrapWithAsciiWalls('H2')
command! -range H3 <line1>,<line2>call WrapWithAsciiWalls('H3')
command! -range H4 <line1>,<line2>call WrapWithAsciiWalls('H4')
" nnoremap <silent> <S-Right> :vertical resize +5<CR>
" nnoremap <silent> <S-Left> :vertical resize -5<CR>
" nnoremap <silent> <S-Up> :resize +5<CR>
" nnoremap <silent> <S-Down> :resize -5<CR>
" colors
hi SpellBad term=reverse ctermbg=226 ctermfg=0
highlight SEND_HELP ctermbg=131 ctermfg=white
highlight SEND_WARNING ctermbg=129 ctermfg=white
highlight CLEAN ctermbg=white ctermfg=black
highlight PASS ctermbg=131 ctermfg=65
highlight GENERIC cterm=reverse gui=reverse
highlight ColorColumn ctermbg=238
highlight YELLOW ctermbg=black ctermfg=yellow
highlight GREEN ctermbg=black ctermfg=green
highlight RED ctermbg=black ctermfg=red
augroup SpecialHighlights
autocmd!
autocmd WinEnter,BufEnter *
\ call clearmatches()
\| call matchadd('ColorColumn', '\s\+$', 100)
\| call matchadd('SEND_HELP', '\<HACK\>')
\| call matchadd('SEND_HELP', '\<ERROR\>')
\| call matchadd('SEND_HELP', '\<CLOSED\>')
\| call matchadd('SEND_HELP', '\<BLOCKED\>')
\| call matchadd('SEND_HELP', '\<REMOVED\>')
\| call matchadd('SEND_HELP', '\<BREAKING CHANGE\>')
\| call matchadd('SEND_HELP', '\<ALERT\>', 101)
\| call matchadd('GENERIC', '^\<EMILY\>', 101)
\| call matchadd('GENERIC', '^\<KRISTIAN\>', 101)
\| call matchadd('GENERIC', '\<FIXED\>')
\| call matchadd('GENERIC', '\<TODO\>')
\| call matchadd('GENERIC', '\<NOTE\>')
\| call matchadd('YELLOW', '^\<ASK\>')
\| call matchadd('YELLOW', '#\d\+')
\| call matchadd('SEND_WARNING', '\*priority\*')
\| call matchadd('SEND_WARNING', '\*deprioritize\*')
\| call matchadd('RED', '^\zs>')
\| call matchadd('YELLOW', '^\zs<')
\| call matchadd('GREEN', '^\zs!')
\| call matchadd('YELLOW', '\/\/\s\+@.*')
\| call matchadd('YELLOW', '\d\{4}-\d\{2}-\d\{2}T\d\{2}:\d\{2}:\d\{2}-\d\{4}')
\| call matchadd('GENERIC', '\<NOTES\>')
\| call matchadd('GENERIC', '\<EXCEPTION\>')
\| call matchadd('CLEAN', '\<CLEANME\>')
augroup END
packadd! matchit