-
Notifications
You must be signed in to change notification settings - Fork 0
/
vimrc.symlink
502 lines (393 loc) Β· 13.4 KB
/
vimrc.symlink
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
" vim: fdm=marker foldlevel=0
scriptencoding utf-8
" {{{ Plugins
let g:plugins_file_path = '~/.vim/plugins.vim'
if filereadable(expand(g:plugins_file_path))
exe ':source ' . g:plugins_file_path
endif
filetype plugin indent on
" }}}
" {{{ Basics
set nobackup
set nowritebackup
set noswapfile
set directory=~/.vim-tmp,~/.tmp,/var/tmp,/tmp
if exists('+undofile')
set undofile
set undodir=~/.vim-tmp,~/.tmp,~/tmp,/var/tmp,/tmp
endif
set history=10000
set undolevels=1000
set mouse=nvi " enable mouse
set cursorline " highlight current line
set hidden " allow buffers in background
set number " line numbers
set listchars=tab:»·,trail:· " invisible chars
set list " show tabs and trailing whitespace
" set wildmode=longest:list,full " tab completion
set laststatus=2 " always show status bar
set wildignorecase " ignore case when completing filenames in command mode
set ignorecase smartcase " search is case insensitive unless when upper case
set gdefault " global search by default; /g for first-per-row only.
set autoindent " indent to current depth on new lines
set expandtab " spaces for tabs
set tabstop=2
set shiftwidth=2
set softtabstop=2
set foldlevel=999 " folds come expanded
set autoread " update files when coming back
set exrc " auto load local .vimrc files
set secure " β¦ but lets keep it secure
" brew install ripgrep
if executable('rg')
set grepprg=rg\ --vimgrep
endif
if exists('+termguicolors')
" let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum"
" let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"
set termguicolors
endif
if has('nvim')
" :s command real-time preview
set inccommand=nosplit
end
" }}}
" {{{ Mappings
let g:mapleader="\<Space>"
" jumping
nnoremap <leader><leader> <c-^>
" so fast save save save
nmap <leader>j :w<cr>
" / to search, <c-/> to clear search
" term:
noremap <c-_> :set hlsearch!<cr>
" gui:
noremap <c-/> :set hlsearch!<cr>
" old leader is the new project wide search
nnoremap \ :Ack<SPACE>
" qq to record, Q to replay
nmap Q @q
vmap Q :normal Q<cr>
" %% expands to dir of current file in cmd mode
cmap %% <C-R>=expand('%:h').'/'<cr>
" edit file in the same directory as the current file
nmap <leader>e :edit %%
" visual moving
noremap k gk
noremap j gj
noremap gk k
noremap gj j
" Easy split navigation
nnoremap <C-h> <C-w>h
nnoremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
nnoremap <C-l> <C-w>l
nnoremap <Left> <C-w>h
nnoremap <Down> <C-w>j
nnoremap <Up> <C-w>k
nnoremap <Right> <C-w>l
" tabs
nnoremap ]w :tabn<cr>
nnoremap [w :tabp<cr>
" Y behaves like other capital letters
nnoremap Y y$
" always jump to mark column (and not just line)
noremap ' `
" Indenting visual selection keeps selection
vnoremap < <gv
vnoremap > >gv
" Open pwd in Finder.app
nnoremap <leader>O :call system('open .')<cr>
" Just, you know, close the bottom window
nnoremap <silent> <c-w>z :wincmd z<bar>cclose<bar>lclose<cr>
" c-c doesn't trigger InsertLeave by default so we map it to regular esc
xnoremap <c-c> <esc>
inoremap <c-c> <esc>
" Shortcuts to configs
nmap <leader>vv :e ~/.vimrc<cr>
nmap <leader>vp :e <c-r>=g:plugins_file_path<cr><cr>
" set <cr> to reload browsers
" for the scripts, see https://github.com/mikker/dotfiles/tree/master/bin
noremap <leader>mc :Rerun call system('reload-chrome')<cr>
noremap <leader>ms :Rerun call system('reload-safari')<cr>
noremap <leader>mr :Rerun call system('reload-firefox-dev')<cr>
" wait what time is it?
iab <expr> ddate strftime("%Y-%m-%d")
iab <expr> ttime strftime("%H:%M")
" stupid hands
cnoreabbrev E e
cnoreabbrev G Git
cnoreabbrev Qa qa
if has('nvim')
" <esc> goes to normal mode in term buffers
tnoremap <esc> <c-\><c-n>
end
" }}}
" {{{ Functions and commands
" Open current file in Marked.app
command! Marked call system('open -a Marked\ 2 "'.expand('%').'"')
" Quicker filetype setting:
" :F html
command! -nargs=1 F set filetype=<args>
" find and delete all trailing whitespace
fun! <SID>StripTrailingWhitespaces()
let l:l = line('.')
let l:c = col('.')
%s/\s\+$//e
call cursor(l:l, l:c)
endfun
noremap <leader>S :call <SID>StripTrailingWhitespaces()<cr>
" TT runs a terminal command in a new tab before the current one
" :TT [terminal command]
fun! s:runTermInTab(args)
if tabpagenr() > 1
else
execute '-tabnew|term ' . expand(a:args)
keepalt file TT
normal i
endif
endfun
command! -nargs=* -complete=file TT call s:runTermInTab(<q-args>)
" }}}
" {{{ Autocommands
augroup vimrcEx
autocmd!
" Auto-open quickfix window after grep cmds
autocmd QuickFixCmdPost *grep* cwindow
" magic markers: enable using `H/S/J/C to jump back to
" last HTML, stylesheet, JS or app code buffer
au BufLeave *.{erb,html,haml,slim,eex} exe "normal! mH"
au BufLeave *.{css,scss} exe "normal! mS"
au BufLeave *.{js,jsx,ts,tsx} exe "normal! mJ"
au BufLeave *.{rb,ex,exs} exe "normal! mC"
au BufLeave *.yml exe "normal! mY"
" Resize windows when the terminal window size changes (from http:https://vimrcfu.com/snippet/186)
autocmd VimResized * wincmd =
" Don't auto insert a comment when using O/o for a newline
autocmd VimEnter,BufRead,FileType * set formatoptions-=o
" Automatically reload vimrc when it's saved
" autocmd BufWritePost {.,}vimrc so ~/.vimrc"
" Automatically reload files when changed
autocmd FocusGained, BufEnter * :checktime
autocmd FocusGained,BufEnter,CursorHold,CursorHoldI *
\ if mode() == 'n' && getcmdwintype() == '' | checktime | endif
augroup END
if has('nvim')
" Close finished term buffers with <cr> in nvim
augroup nvimrcEx
autocmd!
au TermOpen * nmap <buffer> <cr> :bd!<cr>
augroup END
end
" }}}
" Plugin config and maps {{{
" FZF
noremap <leader>f :Files<cr>
nnoremap <silent> <Leader>b :Buffers<cr>
" nnoremap <leader>f :Clap files<cr>
" nnoremap <silent> <Leader>b :Clap buffers<cr>
" nnoremap <silent> <Leader>T :Clap tags<cr>
xmap <cr> :EasyAlign<cr>
let g:lightline = {
\ 'colorscheme': 'pencil',
\ 'separator': { 'left': '', 'right': '' },
\ 'subseparator': { 'left': '', 'right': '' },
\ 'active': {
\ 'left': [
\ ['mode', 'paste'],
\ ['readonly', 'filename', 'fugitive']
\ ],
\ 'right': [['filetype'], []]
\ },
\ 'component_function': {
\ 'filename': 'LightLineFilename',
\ 'fugitive': 'fugitive#head'
\ }
\}
function! LightLineModified()
if &filetype ==# 'help'
return ''
elseif &modified
return '[+]'
else
return ''
endif
endfunction
function! LightLineFilename()
return ('' !=# expand('%f') ? expand('%f') : '[No Name]') .
\ ('' !=# LightLineModified() ? LightLineModified() : '')
endfunction
let g:vimwiki_ext2syntax = {}
let g:vimwiki_list = [{'path': '~/Documents/Wiki/', 'syntax': 'markdown', 'ext': '.md'}]
com! -bang Wiki call fzf#vim#files('~/Documents/Wiki/', fzf#vim#with_preview(), <bang>0)
nnoremap <leader>W :Wiki<cr>
" Use :TT for vim-test
fun! TTStrategy(cmd)
execute 'TT ' . a:cmd
endfun
let g:test#custom_strategies = { "tt": function('TTStrategy') }
if has('nvim')
let test#strategy = "tt"
else
let test#strategy = "basic"
endif
let test#strategy = "vtr"
nmap <silent> <leader>tt :TestNearest<CR>
nmap <silent> <leader>tT :TestFile<CR>
nmap <silent> <leader>ta :TestSuite<CR>
nmap <silent> <leader>tl :TestLast<CR>
nmap <silent> <leader>tg :TestVisit<CR>
" https://github.com/mikker/vim-rerunner
let g:rerunner_focus = 'TestLast'
map <leader>md :Rerun TestLast<cr>
let g:colorizer_nomap = 1
augroup pencil
autocmd!
autocmd FileType markdown,mkd,text call pencil#init()
augroup END
let g:pencil#wrapModeDefault = 'soft'
let g:pencil#conceallevel = 0
let g:pencil#concealcursor = 'c'
map <leader>G :Goyo<cr>
call togglebg#map("<f5>")
" " }}}
set background=dark
colo paramount
" GUI {{{
" when in VimR.app
if has("gui_vimr")
" act as in a term
nmap <c-z> :term<cr>
set background=light
cd ~/Documents/Wiki
let g:goyo_height = '100%'
autocmd VimEnter * if argc() == 0 | execute 'VimwikiIndex' | execute 'Goyo' | endif
endif
" " }}}
inoremap <c-_> <c-x><c-l>
let g:VtrOrientation = 'h'
let g:VtrPercentage = 40
let g:VtrClearBeforeSend = 0
map <leader>ro :VtrOpenRunner<cr>
map <leader>rk :VtrKillRunner<cr>
iabbrev donatoin donation
set tags^=./.git/tags
let g:vrc_curl_opts = {
\ '--silent': ''
\ }
nnoremap <leader>F :Prettier<cr>
" if has('nvim') && !has("gui_vimr")
" luafile ~/.vim/lsp.lua
" autocmd BufEnter * lua require'completion'.on_attach()
" endif
" Auto-darkmode
let output = system("is-this-dark-mode")
if v:shell_error == 0
set background=dark
else
set background=light
endif
command! -nargs=0 Rubyfmt %!rubyfmt %
let g:coc_global_extensions = ['coc-tsserver', 'coc-css', 'coc-tailwindcss', 'coc-html']
" ---- COC
" Having longer updatetime (default is 4000 ms = 4 s) leads to noticeable
" delays and poor user experience.
set updatetime=300
" Don't pass messages to |ins-completion-menu|.
set shortmess+=c
" " Make <CR> auto-select the first completion item and notify coc.nvim to
" " format on enter, <cr> could be remapped by other vim plugin
" inoremap <silent><expr> <cr> pumvisible() ? coc#_select_confirm()
" \: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"
" Use `[g` and `]g` to navigate diagnostics
" Use `:CocDiagnostics` to get all diagnostics of current buffer in location list.
nmap <silent> [g <Plug>(coc-diagnostic-prev)
nmap <silent> ]g <Plug>(coc-diagnostic-next)
" GoTo code navigation.
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)
" Use K to show documentation in preview window.
nnoremap <silent> K :call <SID>show_documentation()<CR>
function! s:show_documentation()
if (index(['vim','help'], &filetype) >= 0)
execute 'h '.expand('<cword>')
elseif (coc#rpc#ready())
call CocActionAsync('doHover')
else
execute '!' . &keywordprg . " " . expand('<cword>')
endif
endfunction
" Highlight the symbol and its references when holding the cursor.
autocmd CursorHold * silent call CocActionAsync('highlight')
" Symbol renaming.
nmap <leader>rn <Plug>(coc-rename)
" Formatting selected code.
" xmap <leader>f <Plug>(coc-format-selected)
" nmap <leader>f <Plug>(coc-format-selected)
augroup mygroup
autocmd!
" Setup formatexpr specified filetype(s).
autocmd FileType typescript,json setl formatexpr=CocAction('formatSelected')
" Update signature help on jump placeholder.
autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp')
augroup end
" Applying codeAction to the selected region.
" Example: `<leader>aap` for current paragraph
xmap <leader>a <Plug>(coc-codeaction-selected)
nmap <leader>a <Plug>(coc-codeaction-selected)
" Remap keys for applying codeAction to the current buffer.
nmap <leader>ac <Plug>(coc-codeaction)
" Apply AutoFix to problem on the current line.
nmap <leader>qf <Plug>(coc-fix-current)
" Map function and class text objects
" NOTE: Requires 'textDocument.documentSymbol' support from the language server.
xmap if <Plug>(coc-funcobj-i)
omap if <Plug>(coc-funcobj-i)
xmap af <Plug>(coc-funcobj-a)
omap af <Plug>(coc-funcobj-a)
xmap ic <Plug>(coc-classobj-i)
omap ic <Plug>(coc-classobj-i)
xmap ac <Plug>(coc-classobj-a)
omap ac <Plug>(coc-classobj-a)
" Remap <C-f> and <C-b> for scroll float windows/popups.
if has('nvim-0.4.0') || has('patch-8.2.0750')
nnoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-f>"
nnoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? coc#float#scroll(0) : "\<C-b>"
inoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(1)\<cr>" : "\<Right>"
inoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(0)\<cr>" : "\<Left>"
vnoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-f>"
vnoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? coc#float#scroll(0) : "\<C-b>"
endif
" Use CTRL-S for selections ranges.
" Requires 'textDocument/selectionRange' support of language server.
nmap <silent> <C-s> <Plug>(coc-range-select)
xmap <silent> <C-s> <Plug>(coc-range-select)
" Add `:Format` command to format current buffer.
command! -nargs=0 Format :call CocAction('format')
" Add `:Fold` command to fold current buffer.
command! -nargs=? Fold :call CocAction('fold', <f-args>)
" Add `:OR` command for organize imports of the current buffer.
command! -nargs=0 OR :call CocAction('runCommand', 'editor.action.organizeImport')
" Add (Neo)Vim's native statusline support.
" NOTE: Please see `:h coc-status` for integrations with external plugins that
" provide custom statusline: lightline.vim, vim-airline.
set statusline^=%{coc#status()}%{get(b:,'coc_current_function','')}
" Mappings for CoCList
" Show all diagnostics.
nnoremap <silent><nowait> <space>a :<C-u>CocList diagnostics<cr>
" Manage extensions.
" nnoremap <silent><nowait> <space>e :<C-u>CocList extensions<cr>
" Show commands.
nnoremap <silent><nowait> <space>c :<C-u>CocList commands<cr>
" Find symbol of current document.
nnoremap <silent><nowait> <space>o :<C-u>CocList outline<cr>
" Search workspace symbols.
nnoremap <silent><nowait> <space>s :<C-u>CocList -I symbols<cr>
" Do default action for next item.
" nnoremap <silent><nowait> <space>j :<C-u>CocNext<CR>
" Do default action for previous item.
" nnoremap <silent><nowait> <space>k :<C-u>CocPrev<CR>
" Resume latest coc list.
nnoremap <silent><nowait> <space>p :<C-u>CocListResume<CR>