-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.vimrc-2022
520 lines (377 loc) · 11.7 KB
/
.vimrc-2022
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
" VARIABLES
" =========
" Plugins variables
" -----------------
let g:netrw_banner = 0
let g:netrw_liststyle = 0
" vim-markdown
let g:vim_markdown_folding_disabled = 1
let g:vim_markdown_frontmatter = 1
let g:vim_markdown_auto_insert_bullets = 0
" vim-javascript
let g:javascript_plugin_jsdoc=1
" editorconfig-vim
let g:EditorConfig_exclude_patterns = ['fugitive://.*']
" ack.vim
let g:ackhighlight = 1
" fzf
let g:fzf_layout = { 'window': { 'width': 0.9, 'height': 0.9 } }
" Customize fzf colors to match your color scheme
" - fzf#wrap translates this to a set of `--color` options
let g:fzf_colors =
\ { 'fg': ['fg', 'Normal'],
\ 'bg': ['bg', 'Normal'],
\ 'hl': ['fg', 'Comment'],
\ 'fg+': ['fg', 'CursorLine', 'CursorColumn', 'Normal'],
\ 'bg+': ['bg', 'CursorLine', 'CursorColumn'],
\ 'hl+': ['fg', 'Statement'],
\ 'info': ['fg', 'PreProc'],
\ 'border': ['fg', 'Number'],
\ 'prompt': ['fg', 'Conditional'],
\ 'pointer': ['fg', 'Exception'],
\ 'marker': ['fg', 'Keyword'],
\ 'spinner': ['fg', 'Label'],
\ 'header': ['fg', 'Comment'] }
" CoC
let g:coc_global_extensions = [
\ 'coc-snippets',
\ 'coc-tsserver',
\ 'coc-eslint',
\ 'coc-html',
\ 'coc-css',
\ 'coc-json',
\ 'coc-prettier',
\ ]
" Syntastic
let g:syntastic_sass_checkers=["sasslint"]
let g:syntastic_scss_checkers=["sasslint"]
" Add below variable in a local .vimrc
" let g:sass_lint_config = '/path/to/.sass-lint.yml'
" markdown-preview
let g:mkdp_auto_start = 0
let g:mkdp_auto_close = 1
let g:mkdp_browser = 'Firefox Developer Edition'
" emmet-vim
let g:user_emmet_leader_key='<C-E>'
let g:user_emmet_install_global = 0
" vimwiki
let g:vimwiki_list = [{'path': '~/notebook/notes',
\ 'syntax': 'markdown', 'ext': '.md', 'links_space_char': '-'}]
let g:vimwiki_global_ext = 0
" PLUGINS
" =======
" Plugin manager => https://github.com/junegunn/vim-plug
call plug#begin('~/.vim/plugged')
" Text objects
" ------------
Plug 'kana/vim-textobj-user'
Plug 'kana/vim-textobj-entire'
Plug 'kana/vim-textobj-line'
Plug 'michaeljsmith/vim-indent-object'
Plug 'whatyouhide/vim-textobj-xmlattr'
Plug 'jceb/vim-textobj-uri'
Plug 'wellle/targets.vim'
" Language support/syntax highlighting
" ------------------------------------
Plug 'pangloss/vim-javascript', { 'for': ['js', 'jsx'] }
Plug 'mustache/vim-mustache-handlebars', { 'for': ['mustache', 'hbs'] }
Plug 'plasticboy/vim-markdown', { 'for': ['md', 'markdown'] }
Plug 'neoclide/coc.nvim', {'branch': 'release'}
Plug 'mattn/emmet-vim'
Plug 'udalov/kotlin-vim'
Plug 'jparise/vim-graphql'
" Syntax checkers/linters
" -----------------------
Plug 'editorconfig/editorconfig-vim'
Plug 'scrooloose/syntastic'
Plug 'gcorne/vim-sass-lint'
" Buffer management
" -----------------
Plug 'arithran/vim-delete-hidden-buffers'
Plug 'tpope/vim-eunuch'
" UI/UX Extensions
" ----------------
Plug '~/.fzf' " Should have been installed with git seperately in home folder.
Plug 'junegunn/fzf.vim'
Plug 'airblade/vim-gitgutter'
Plug 'tpope/vim-fugitive'
Plug 'tpope/vim-rhubarb'
Plug 'mileszs/ack.vim'
Plug 'iamcco/markdown-preview.nvim', { 'do': 'cd app & npm install' }
Plug 'mzlogin/vim-markdown-toc'
Plug 'romainl/vim-cool'
" Extensions
" ----------
Plug 'vim-scripts/matchit.zip'
Plug 'tpope/vim-surround'
Plug 'tpope/vim-unimpaired'
Plug 'tpope/vim-commentary'
Plug 'tpope/vim-repeat'
Plug 'vim-scripts/ReplaceWithRegister'
Plug 'junegunn/vim-easy-align'
" Applications
" ------------
Plug 'vimwiki/vimwiki'
call plug#end()
" FUNCTIONS
" =========
function MyVimEnter()
if argc() == 1 && argv(0) == '.'
execute "Files"
endif
return
endfunction
" netrw functions
" -------------
function NetrwMappings()
nnoremap <buffer> <C-h> :wincmd h<cr>
nnoremap <buffer> <C-j> :wincmd j<cr>
nnoremap <buffer> <C-k> :wincmd k<cr>
nnoremap <buffer> <C-l> :wincmd l<cr>
endfunction
" fzf functions
" -------------
function! s:list_buffers()
redir => list
silent ls
redir END
return split(list, "\n")
endfunction
function! s:delete_buffers(lines)
execute 'bwipeout' join(map(a:lines, {_, line -> split(line)[0]}))
endfunction
" CoC functions
" -------------
function! s:show_documentation()
if (index(['vim','help'], &filetype) >= 0)
execute 'h '.expand('<cword>')
else
call CocAction('doHover')
endif
endfunction
" SETTINGS
" ========
" General configuration
" ---------------------
set nocompatible
language en_US.utf-8
set encoding=utf-8
set backspace=indent,eol,start
set hidden
set history=1000
set exrc
" User Interface
" --------------
colorscheme solarized8
set background=dark
let g:solarized_diffmode="high"
set title
set laststatus=2
set number
set splitright
set splitbelow
set listchars=tab:▸\ ,space:·,trail:·,eol:¬
set cursorline
set colorcolumn=+1
set termguicolors
set guifont=Victor\ Mono:h16
set wildmenu
set showmatch
syntax enable
" Turn on omni completion
filetype plugin on
set omnifunc=syntaxcomplete#Complete
" Cursor behaviour
set guicursor=n-v-c-ci-i:block-Cursor-blinkwait1-blinkon150-blinkoff150
" Don't offer to open certain files/folders
set wildignore+=*.bmp,*.gif,*.ico,*.jpg,*.png,*.ico
set wildignore+=*.pdf,*.psd
set wildignore+=*.map,*.min.css,*.min.css
set wildignore+=*/node_modules/*,*/bower_components/*
" Outside vim file changes tracking
set updatetime=250
set autoread
" Indentation
" -----------
set autoindent
filetype plugin indent on
set noexpandtab
set tabstop=4
set shiftwidth=4
set softtabstop=4
set shiftround
" Search
" ------
set incsearch
set hlsearch
set ignorecase
set smartcase
" Swap and backup file strategy
" -----------------------------
set directory=$HOME/.vim-directory//
set nobackup
set nowritebackup
" HIGHLIGHTS
" ==========
" Italicised comments and attributes.
highlight Comment cterm=italic gui=italic guifg=#5f87df
highlight htmlArg cterm=italic gui=italic guifg=#af8700
highlight StatuslineFilename cterm=bold ctermfg=136 gui=bold guifg=#b58900
highlight StatuslineCustom ctermfg=252 ctermbg=238 guifg=#D9D9D9 guibg=#565656
" MAPPINGS
" ========
let mapleader = "\<Space>"
nnoremap <leader>ev :tabnew ~/.vimrc<CR>
nnoremap <leader>rv :source $MYVIMRC<CR>
nnoremap j gj
nnoremap k gk
" <S-arrow> to resize splits (not optimal yet).
nnoremap <S-right> :vertical resize +2<CR>
nnoremap <S-left> :vertical resize -2<CR>
nnoremap <S-down> :resize -2<CR>
nnoremap <S-up> :resize +2<CR>
nnoremap <leader>w :write!<cr>
nnoremap <leader>q :quit<cr>
" Easier window navigation.
map <C-h> <C-w>h
map <C-j> <C-w>j
map <C-k> <C-w>k
map <C-l> <C-w>l
" Easilly search for things.
nnoremap <silent> <C-p> :Files<CR>
nnoremap <silent> gb :Buffers<CR>
nnoremap <silent> gl :BLines<CR>
nnoremap <leader>f :Ack! "
vnoremap <leader>f y:Ack! "<C-R>"" --
vnoremap <leader>/ y/\V\<<C-R>"\><CR>
vnoremap <leader>? y?\V\<<C-R>"\><CR>
autocmd FileType vimwiki nnoremap <buffer> <Leader>f :Ack! ~/notebook/notes/<C-B><right><right><right><right><right>
" Swap booleans.
nnoremap <leader>1 :s/false/true/<CR>
nnoremap <leader>0 :s/true/false/<CR>
nnoremap <leader>h :nohl<CR>
nmap <leader>l :set list!<CR>
nnoremap <Leader>c :let &cole=(&cole == 2) ? 0 : 2 <bar> echo 'conceallevel ' . &cole <CR>
nnoremap <leader>r :set relativenumber!<CR>
" Copy current file path to clipboard.
nnoremap gcp :let @+=@%<CR>
" Copy current git branch to clipboard.
nnoremap <leader>cb :!git cp<CR><CR>
" Open active buffer's folder in netrw.
nnoremap <silent> -- :Ex<CR>
nnoremap <silent> =ie =<Plug>(textobj-entire-i)``zz
nnoremap [s i<Space><Esc>l
nnoremap ]s a<Space><Esc>h
nnoremap n nzz
nnoremap N Nzz
nnoremap <C-u> <C-u>zz
nnoremap <C-d> <C-d>zz
nmap ]q :cn<CR>zz
nmap [q :cN<CR>zz
" Move visual selection
vnoremap J :m '>+1<CR>gv=gv
vnoremap K :m '<-2<CR>gv=gv
" Forgiving mappings
" ------------------
cmap Qa qa
cmap Wq wq
" Notes (VimWiki) management
" --------------------------
nnoremap <leader>np :!notes p<CR>
nnoremap <leader>nf :!notes f<CR>
" CoC mappings
" ------------
" Remap keys for gotos
nmap <silent> <leader>gd <Plug>(coc-definition)
nmap <silent> <leader>gy <Plug>(coc-type-definition)
nmap <silent> <leader>gi <Plug>(coc-implementation)
nmap <silent> <leader>gr <Plug>(coc-references)
nmap <silent> [g <Plug>(coc-diagnostic-prev)
nmap <silent> ]g <Plug>(coc-diagnostic-next)
nnoremap <silent> K :call <SID>show_documentation()<CR>
" Personally used for local scope symbol renaming.
nmap <leader>ln <Plug>(coc-rename)
" Project wide rename of current symbol.
nnoremap <leader>pr :CocSearch <C-R>=expand('<cword>')<CR><CR>
" Fix autofix problem of current line
nmap <leader>af <Plug>(coc-fix-current)
" CoC snippets mappings
" ---------------------
" Use <C-l> for trigger snippet expand.
imap <C-l> <Plug>(coc-snippets-expand)
" Use <C-j> for trigger snippet expand.
vmap <C-l> <Plug>(coc-snippets-select)
" vim-easy-align mappings
" -----------------------
" Interactive mode
xmap ga <Plug>(EasyAlign)
nmap ga <Plug>(EasyAlign)
" VimWiki
" -------
vmap <leader><leader> ygv<CR>%la./<esc>f)i.md<esc>mmvi)gugv:s/\%V /-/ge<CR>:w<CR>gv<esc><CR>i# <C-r>"<CR><CR><esc>:w<CR>i
" GotoSymbol
" ----------
nmap <leader>@ :GotoSymbol
" AUTOCOMMANDS
" ============
autocmd VimEnter * nested call MyVimEnter()
" Use zsh rather
autocmd vimenter * let &shell='/bin/zsh -i'
" Outside vim file changes tracking
autocmd CursorHold,CursorHoldI * silent! checktime
autocmd FileChangedShellPost *
\ echohl WarningMsg | echo "File changed on disk. Buffer reloaded." | echohl None
autocmd ColorScheme * highlight CursorLineNr ctermbg=magenta ctermfg=white guibg=magenta guifg=white
autocmd ColorScheme * highlight Cursor ctermbg=yellow ctermfg=black guibg=yellow guifg=black
autocmd ColorScheme * highlight ColorColumn ctermbg=darkgrey guibg=#073642
autocmd VimResized * wincmd =
autocmd BufNewFile,BufRead *.md setlocal filetype=markdown
autocmd BufNewFile,BufRead *.md setlocal textwidth=80
" netrw
augroup netrw_mappings
autocmd!
autocmd filetype netrw call NetrwMappings()
augroup END
" emmet-vim
autocmd FileType html,hbs,css,scss EmmetInstall
" vimwiki
autocmd BufRead */notebook/notes/index.md silent !notes f
autocmd FileType vimwiki autocmd BufWritePost <buffer> silent !notes p
" COMMANDS
" ========
" fzf commands
" ------------
command! -bang -nargs=? -complete=dir Files
\ call fzf#vim#files(<q-args>, fzf#vim#with_preview(), <bang>0)
command! Folders call fzf#run(fzf#wrap({'source': 'find * -type d \( ! -path "node_modules/*" \)'}))
command! NodeModules call fzf#run(fzf#wrap({'source': 'find node_modules/* -type d'}))
command! DeleteBuffers call fzf#run(fzf#wrap({
\ 'source': s:list_buffers(),
\ 'sink*': { lines -> s:delete_buffers(lines) },
\ 'options': '--multi --reverse --bind ctrl-a:select-all+accept'
\ }))
" formatting commands
" -------------------
command! -range=% -nargs=0 Tabs2SpacesOfTwo execute '<line1>,<line2>s#^\t\+#\=repeat(" ", len(submatch(0))*2)'
command! -range=% -nargs=0 SpacesOfTwo2Tabs execute '<line1>,<line2>s#^\( \{2\}\)\+#\=repeat("\t", len(submatch(0))/2)'
command! -range=% -nargs=0 Tabs2SpacesOfFour execute '<line1>,<line2>s#^\t\+#\=repeat(" ", len(submatch(0))*4)'
command! -range=% -nargs=0 SpacesOfFour2Tabs execute '<line1>,<line2>s#^\( \{4\}\)\+#\=repeat("\t", len(submatch(0))/4)'
" STATUSLINE
" ==========
" Preview
" -------------------------------------------------
" W1・<vim> master・☰ 98%・362,1 .vimrc [+]
" -------------------------------------------------
set statusline=%#StatuslineCustom#
set statusline+=\ W%{winnr()}・
set statusline+=%{len(&filetype)?'<'.&filetype.'>':''}
set statusline+=%=
set statusline+=%{exists('g:loaded_fugitive')&&len(FugitiveHead())?'\ '.FugitiveHead():''}
set statusline+=・☰\
set statusline+=%P・
set statusline+=%l,
set statusline+=%c
set statusline+=\
set statusline+=%#StatuslineFilename#
set statusline+=\ %t\
set statusline+=%#ErrorMsg#%m