-
Notifications
You must be signed in to change notification settings - Fork 0
/
dot_vimrc
457 lines (403 loc) · 11.2 KB
/
dot_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
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
" Require Vim ≥8.0 or Neovim
" See https://github.com/simnalamburt/.dotfiles/blob/master/.vimrc
"
" General configs
"
scriptencoding utf-8
set encoding=utf-8
set fileencoding=utf-8
set fileencodings=utf-8,cp949,default,latin1
set diffopt+=iwhite,vertical
set pastetoggle=<F8>
set scrolloff=3
set switchbuf+=usetab,split
set startofline
set splitbelow
set nobackup
set nowritebackup
set nocompatible
set nofoldenable
set noshowmode
set noswapfile
set nowrap
set updatetime=500
set termguicolors
" History
if has('persistent_undo')
set undofile
let &undodir = $HOME . '/.vim/undodir'
silent! call mkdir(&undodir, 'p')
endif
" Indentation
set cindent
set autoindent
set smartindent
" Tab
set softtabstop=2
set shiftwidth=2
set expandtab
" Searching
set incsearch
set ignorecase
set smartcase
set hlsearch | nohlsearch
set nowrapscan
" Line number column
set number
set cursorline
" 80th column color
set textwidth=80
set formatoptions-=t
set colorcolumn=+1,+2,+3
" Listchars
set list
let &listchars = 'tab:› ,extends:»,precedes:«'
" Pair matching
set matchpairs+=<:>
set showmatch
" Wildmenu
set wildmode=longest,full
" Completion
set hidden
set completeopt=preview,menuone,noinsert,noselect
set shortmess+=c
if has('patch-8.1.1564')
set signcolumn=number
elseif has('nvim') ? has('nvim-0.2') : 1
set signcolumn=yes
endif
"
" Key mappings
"
let g:mapleader = ','
" Easy file save without switching IME
cabbrev ㅈ w
cabbrev ㅂ q
cabbrev ㅈㅂ wq
cabbrev ㅌ x
" Easy command-line mode
nnoremap ; :
" Easy home/end
inoremap <C-a> <ESC>I
inoremap <C-e> <End>
nnoremap <C-a> ^
nnoremap <C-e> $
vnoremap <C-a> ^
vnoremap <C-e> $
" Easy horizontal scrolling
noremap <esc>l 3zl
noremap <esc>h 3zh
noremap <a-l> 3zl
noremap <a-h> 3zh
" Easy delete key
vnoremap <backspace> "_d
" Easy file save
nnoremap <silent> <C-s> :update<CR>
inoremap <silent> <C-s> <ESC>:update<CR>
vnoremap <silent> <C-s> <ESC>:update<CR>
" Easy indentation
vnoremap <Tab> >gv
vnoremap <S-Tab> <gv
" Easy splitting & resizing
nnoremap <silent> <esc>- :split<CR>
nnoremap <silent> <esc>\ :vertical split<CR>
nnoremap <silent> <esc>h :vertical resize -5<CR>
nnoremap <silent> <esc>j :resize -3<CR>
nnoremap <silent> <esc>k :resize +3<CR>
nnoremap <silent> <esc>l :vertical resize +5<CR>
nnoremap <silent> <a--> :split<CR>
nnoremap <silent> <a-\> :vertical split<CR>
nnoremap <silent> <a-h> :vertical resize -5<CR>
nnoremap <silent> <a-j> :resize -3<CR>
nnoremap <silent> <a-k> :resize +3<CR>
nnoremap <silent> <a-l> :vertical resize +5<CR>
" Tab navigations
nnoremap <esc>t :tabnew<CR>
nnoremap <esc>T :-tabnew<CR>
nnoremap <esc>1 1gt
nnoremap <esc>2 2gt
nnoremap <esc>3 3gt
nnoremap <esc>4 4gt
nnoremap <esc>5 5gt
nnoremap <esc>6 6gt
nnoremap <esc>7 7gt
nnoremap <esc>8 8gt
nnoremap <esc>9 9gt
nnoremap <a-t> :tabnew<CR>
nnoremap <a-T> :-tabnew<CR>
nnoremap <a-1> 1gt
nnoremap <a-2> 2gt
nnoremap <a-3> 3gt
nnoremap <a-4> 4gt
nnoremap <a-5> 5gt
nnoremap <a-6> 6gt
nnoremap <a-7> 7gt
nnoremap <a-8> 8gt
nnoremap <a-9> 9gt
" Easy newline insert
function! s:CustomEnter()
if &modifiable
normal! o
else
" Exception for quickfix buffer and other unmodifiable buffers.
" See https://vi.stackexchange.com/a/3129
execute 'normal! \<CR>'
endif
endfunction
nnoremap <CR> :call <SID>CustomEnter()<CR>
" Easy drag select
function! s:DragSelectMode()
if &signcolumn != 'no'
" Enable DragSelectMode
let s:previous_scl = &signcolumn
set signcolumn=no
set nonumber
call nvim_buf_clear_namespace(0, -1, 0, -1)
if s:use_coc
call coc#config('git', {'addGBlameToVirtualText': 0})
endif
else
" Disable DragSelectMode
let &signcolumn = s:previous_scl
set number
if s:use_coc
call coc#config('git', {'addGBlameToVirtualText': 1})
endif
endif
endfunction
nnoremap <F9> :call <SID>DragSelectMode()<CR>
" Nasty hacks for Windows
if has('win32')
" https://github.com/junegunn/vim-plug/issues/852#issuecomment-696431055
set shell=cmd.exe
endif
"
" List of plugins
"
let s:use_coc = (has('nvim') ? has('nvim-0.3.2') : has('patch-8.0.1453')) && executable('yarn')
try
call plug#begin('~/.vim/plugged')
" Configs
Plug 'tpope/vim-sensible'
Plug 'vim-utils/vim-interruptless'
" IDE
if s:use_coc
Plug 'neoclide/coc.nvim', {'branch': 'master', 'do': 'yarn install --frozen-lockfile'}
Plug 'neoclide/coc-git', {'do': 'yarn install --frozen-lockfile'}
Plug 'neoclide/coc-highlight', {'do': 'yarn install --frozen-lockfile'}
Plug 'neoclide/coc-prettier', {'do': 'yarn install --frozen-lockfile'}
Plug 'neoclide/coc-tsserver', {'do': 'yarn install --frozen-lockfile'}
Plug 'neoclide/coc-json', {'do': 'yarn install --frozen-lockfile'}
Plug 'neoclide/coc-yaml', {'do': 'yarn install --frozen-lockfile'}
Plug 'neoclide/coc-css', {'do': 'yarn install --frozen-lockfile'}
Plug 'neoclide/coc-stylelint', {'do': 'yarn install --frozen-lockfile'}
Plug 'neoclide/coc-html', {'do': 'yarn install --frozen-lockfile'}
Plug 'fannheyward/coc-rust-analyzer', {'do': 'yarn install --frozen-lockfile'}
Plug 'neoclide/coc-sources', {'do': 'yarn install --frozen-lockfile', 'rtp': 'packages/emoji'}
if executable('clangd')
Plug 'clangd/coc-clangd', {'do': 'yarn install --frozen-lockfile'}
endif
if executable('go')
Plug 'josa42/coc-go', {'do': 'yarn install --frozen-lockfile'}
endif
"Plug 'fannheyward/coc-rust-analyzer', {'do': 'yarn install --frozen-lockfile'}
Plug 'ervandew/supertab'
Plug 'junegunn/fzf'
endif
Plug 'ryanoasis/vim-devicons'
Plug 'preservim/nerdtree'
Plug 'tpope/vim-fugitive'
" Neovim only
if has('nvim-0.6')
Plug 'github/copilot.vim'
Plug 'akinsho/toggleterm.nvim', {'tag' : 'v2.*'}
endif
" Visual
Plug 'vim-airline/vim-airline'
Plug 'nathanaelkane/vim-indent-guides'
Plug 'ntpeters/vim-better-whitespace'
Plug 'phanviet/vim-monokai-pro'
Plug 'machakann/vim-highlightedyank'
" Syntax
let g:polyglot_disabled = ['v'] | Plug 'sheerun/vim-polyglot'
Plug 'hashivim/vim-terraform'
" Format
Plug 'sgur/vim-editorconfig'
" Blink
Plug 'farmergreg/vim-lastplace'
Plug 'rhysd/clever-f.vim'
Plug 'easymotion/vim-easymotion'
Plug 'michaeljsmith/vim-indent-object'
Plug 'haya14busa/incsearch.vim'
Plug 'haya14busa/incsearch-easymotion.vim'
" Util
Plug 'simnalamburt/vim-mundo'
Plug 'godlygeek/tabular'
Plug 'justinmk/vim-dirvish'
Plug 'tpope/vim-surround'
Plug 'tpope/vim-fugitive'
Plug 'tpope/vim-commentary'
Plug 'vim-scripts/ReplaceWithRegister'
Plug 'chrisbra/matchit'
Plug 'junegunn/goyo.vim'
Plug 'junegunn/gv.vim'
Plug 'mg979/vim-visual-multi', {'branch': 'master'}
call plug#end()
"
" Configs for plugins
"
if s:use_coc
" coc.nvim
let g:coc_disable_startup_warning = 1
nnoremap <silent> K :call <SID>show_documentation()<CR>
function! s:show_documentation()
if (index(['vim','help'], &filetype) >= 0)
execute 'h '.expand('<cword>')
else
call CocActionAsync('doHover')
endif
endfunction
" coc-highlight
augroup vimrc_highlight
autocmd!
autocmd CursorHold * silent call <SID>highlight()
augroup END
function! s:highlight()
if exists('*CocActionAsync')
call CocActionAsync('highlight')
endif
endfunction
" coc-yank
nnoremap <silent> <leader>y :<C-u>CocList -A --normal yank<CR>
" coc-prettier
command! -nargs=0 Prettier :CocCommand prettier.formatFile
" supertab
let g:SuperTabDefaultCompletionType = "<c-n>"
" fzf
nnoremap <F5> :call <SID>lsp_menu()<CR>
function! s:lsp_menu()
call fzf#run({
\ 'source': [
\ 'rename',
\ 'jumpDefinition',
\ 'jumpDeclaration',
\ 'jumpImplementation',
\ 'jumpTypeDefinition',
\ 'jumpReferences',
\ 'diagnosticInfo',
\ 'diagnosticNext',
\ 'diagnosticPrevious',
\ 'format',
\ 'openLink',
\ 'doQuickfix',
\ 'doHover',
\ 'refactor',
\ ],
\ 'sink': function('CocActionAsync'),
\ 'options': '+m',
\ 'down': 10 })
endfunction
endif
" nerdtree
noremap <silent> <C-n> :NERDTreeToggle<CR>
function! s:nerdtree_startup()
if exists('s:std_in') || argc() != 1 || !isdirectory(argv()[0])
return
endif
execute 'NERDTree' argv()[0]
wincmd p
enew
execute 'cd '.argv()[0]
NERDTreeFocus
endfunction
augroup vimrc_nerdtree
autocmd!
autocmd StdinReadPre * let s:std_in=1
autocmd VimEnter * call s:nerdtree_startup()
autocmd BufEnter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif
augroup END
" vim-indent-guides
nmap <leader>i <Plug>IndentGuidesToggle
let g:indent_guides_enable_on_vim_startup = 1
let g:indent_guides_auto_colors = 0
let g:indent_guides_guide_size = 1
let g:indent_guides_start_level = 2
let g:indent_guides_default_mapping = 0
" vim-terraform
let g:terraform_fmt_on_save=1
" clever-f.vim
let g:clever_f_across_no_line = 1
let g:clever_f_smart_case = 1
" incsearch.vim
let g:incsearch#auto_nohlsearch = 1
map n <Plug>(incsearch-nohl-n)
map N <Plug>(incsearch-nohl-N)
map * <Plug>(incsearch-nohl-*)
map # <Plug>(incsearch-nohl-#)
map g* <Plug>(incsearch-nohl-g*)
map g# <Plug>(incsearch-nohl-g#)
" incsearch-easymotion.vim
function! s:incsearch_config(...) abort
return incsearch#util#deepextend(deepcopy({
\ 'modules': [incsearch#config#easymotion#module({'overwin': 1})],
\ 'keymap': {
\ "\<tab>": '<Over>(easymotion)'
\ },
\ 'is_expr': 0
\ }), get(a:, 1, {}))
endfunction
noremap <silent><expr> / incsearch#go(<SID>incsearch_config())
noremap <silent><expr> ? incsearch#go(<SID>incsearch_config({'command': '?'}))
noremap <silent><expr> g/ incsearch#go(<SID>incsearch_config({'is_stay': 1}))
" mundo.vim
let g:mundo_right = 1
nnoremap <leader>g :MundoToggle<CR>
catch /^Vim\%((\a\+)\)\=:E117/
endtry
"
" My vim theme
"
set termguicolors
colorscheme monokai_pro
function! s:fg(item, color)
execute printf('highlight %s guifg=%s', a:item, a:color)
endfunction
function! s:bg(item, color)
execute printf('highlight %s guibg=%s', a:item, a:color)
endfunction
" TabLine
let s:tab_color = '#1c2328'
highlight TabLine cterm=NONE gui=NONE
call s:fg('TabLine', '#62788c')
call s:bg('TabLine', s:tab_color)
call s:fg('TabLineSel', '#FFFFFF')
call s:bg('TabLineSel', s:tab_color)
call s:fg('TabLineFill', s:tab_color)
" Pretty vimdiff colorscheme
call s:fg('DiffDelete', '#232b32')
call s:bg('DiffDelete', 'NONE')
" IndentGuides
let s:indent_color = '#151a1e'
call s:bg('IndentGuidesEven', s:indent_color)
call s:bg('IndentGuidesOdd', s:indent_color)
" Matching
let s:match_color = '#232b32'
highlight MatchParen cterm=NONE gui=NONE
call s:bg('MatchParen', s:match_color)
call s:bg('CocHighlightText', s:match_color)
"
" Define a 'vimrc' augroup
"
augroup vimrc
autocmd!
" Vim automatic reload
autocmd FocusGained,BufEnter,CursorHold,CursorHoldI * if mode() != 'c' | checktime | endif
autocmd FileChangedShellPost *
\ echohl WarningMsg | echo 'File changed on disk. Buffer reloaded.' | echohl None
augroup END
"
" Local configs
"
if filereadable($HOME . '/.vimrc.local')
source $HOME/.vimrc.local
endif