-
Notifications
You must be signed in to change notification settings - Fork 27
/
init.vim
executable file
·499 lines (438 loc) · 14.9 KB
/
init.vim
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
call plug#begin()
" Some Git stuff
Plug 'tpope/vim-fugitive'
" EditorConfig
Plug 'editorconfig/editorconfig-vim'
" Execute code in current buffer
Plug 'huytd/vim-quickrun'
" Language support things
Plug 'sheerun/vim-polyglot'
Plug 'rust-lang/rust.vim'
Plug 'othree/html5.vim'
Plug 'cakebaker/scss-syntax.vim'
" LSP support
Plug 'neoclide/coc.nvim', {'branch': 'release'}
Plug 'neoclide/coc-denite'
" Fancy UI stuff
Plug 'scrooloose/nerdtree'
Plug 'itchyny/lightline.vim'
Plug 'ryanoasis/vim-devicons'
Plug 'Shougo/denite.nvim'
Plug 'raghur/fruzzy', {'do': { -> fruzzy#install()}}
Plug 'tyrannicaltoucan/vim-quantum'
" Auto root folder switcher
Plug 'airblade/vim-rooter'
" Moving around easier
Plug 'easymotion/vim-easymotion'
" Improving editing experience
Plug 'vim-scripts/matchit.zip'
Plug 'tpope/vim-surround'
Plug 'jiangmiao/auto-pairs'
Plug 'haya14busa/incsearch.vim'
Plug 'tpope/vim-abolish' " For case perserved subtitue :%S
Plug 'scrooloose/nerdcommenter'
Plug 'terryma/vim-multiple-cursors'
" Display source outline
Plug 'liuchengxu/vista.vim'
call plug#end()
filetype plugin indent on
" Auto remove trailing spaces
autocmd BufWritePre * %s/\s\+$//e
set encoding=UTF-8
set hidden
set nobackup
set nowritebackup
set mouse=a " enable mouse for all mode
set wildoptions=pum
set pumblend=20
set cursorline
let g:is_posix = 1
set noswapfile
set nojoinspaces
set nowrap
set number
set ttyfast
set laststatus=2
set ttimeout
set ttimeoutlen=10
set termguicolors
set ignorecase
" Tweak for Markdown mode
autocmd FileType markdown call s:markdown_mode_setup()
function! s:markdown_mode_setup()
set wrap
set nonumber
set textwidth=80
set formatoptions+=t
CocDisable
endfunction
" Custom icon for coc.nvim statusline
let g:coc_status_error_sign=" "
let g:coc_status_warning_sign=" "
" I don't use recording, don't judge me
map q <Nop>
inoremap jk <ESC>
vnoremap <M-/> <Esc>/\%V
nnoremap <Left> :echoe "Use h"<CR>
nnoremap <Right> :echoe "Use l"<CR>
nnoremap <Up> :echoe "Use k"<CR>
nnoremap <Down> :echoe "Use j"<CR>
nnoremap <ESC><ESC> :nohlsearch<CR>
" Duplicate everything selected
vmap D y'>p
" Map Emacs like movement in Insert mode
inoremap <C-n> <Down>
inoremap <C-p> <Up>
inoremap <C-e> <C-o>$
inoremap <C-a> <C-o>^
" Remap scrolling
nnoremap <C-k> <C-u>
nnoremap <C-j> <C-d>
set background=dark
let g:quantum_italics=1
colorscheme quantum
if (&t_Co > 2 || has("gui_running")) && !exists("syntax_on")
syntax on
endif
set listchars=eol:¬,tab:>·,trail:~,extends:>,precedes:<,space:·
set list
set backspace=eol,start,indent
set whichwrap+=<,>,h,l
set tabstop=2
set softtabstop=2
set shiftwidth=2
set shiftround
set expandtab
set autoindent
set smartindent
map mm <Plug>NERDCommenterToggle
map / <Plug>(incsearch-forward)
map ? <Plug>(incsearch-backward)
map g/ <Plug>(incsearch-stay)
" Floating Term
let s:float_term_border_win = 0
let s:float_term_win = 0
function! FloatTerm()
" Configuration
let height = float2nr((&lines - 2) * 0.6)
let row = float2nr((&lines - height) / 2)
let width = float2nr(&columns * 0.6)
let col = float2nr((&columns - width) / 2)
" Border Window
let border_opts = {
\ 'relative': 'editor',
\ 'row': row - 1,
\ 'col': col - 2,
\ 'width': width + 4,
\ 'height': height + 2,
\ 'style': 'minimal'
\ }
let border_buf = nvim_create_buf(v:false, v:true)
let s:float_term_border_win = nvim_open_win(border_buf, v:true, border_opts)
" Terminal Window
let opts = {
\ 'relative': 'editor',
\ 'row': row,
\ 'col': col,
\ 'width': width,
\ 'height': height,
\ 'style': 'minimal'
\ }
let buf = nvim_create_buf(v:false, v:true)
let s:float_term_win = nvim_open_win(buf, v:true, opts)
" Styling
hi FloatTermNormal term=None guibg=#2d3d45
call setwinvar(s:float_term_border_win, '&winhl', 'Normal:FloatTermNormal')
call setwinvar(s:float_term_win, '&winhl', 'Normal:FloatTermNormal')
terminal
startinsert
" Close border window when terminal window close
autocmd CursorMoved * ++once call nvim_win_close(s:float_term_border_win, v:true)
endfunction
"-----------------------------------
let mapleader=" "
nnoremap <Leader>w :w<CR>
nnoremap <Leader>l :vsplit<CR>
nnoremap <Leader>k :split<CR>
nnoremap <Leader>wh :wincmd h<CR>
nnoremap <Leader>wl :wincmd l<CR>
nnoremap <Leader>wk :wincmd k<CR>
nnoremap <Leader>wj :wincmd j<CR>
nnoremap <Leader>w= :wincmd =<CR>
nnoremap <Leader>e :QuickRunExecute<CR>
nnoremap <Leader>wb :e#<CR>
nnoremap <Leader>qq :bd<CR>
nnoremap <Leader>ss :mksession! .work<CR>
nnoremap <Leader>sr :so .work<CR>
nnoremap <Leader><Leader>r :so ~/.config/nvim/init.vim<CR>
nnoremap <Leader>n :NERDTree<CR>
nnoremap <Leader>f :NERDTreeFind<CR>
nnoremap <Leader><Leader>o :Vista coc<CR>
"Buffer
nnoremap <Leader>tn :tabn<CR>
nnoremap <Leader>tp :tabp<CR>
nnoremap <Leader>tc :tabe<CR>
nnoremap <Leader>tx :tabclose<CR>
" Open terminal
nnoremap <Leader>at :call FloatTerm()<CR>
" NERDTree config
let NERDTreeMinimalUI=1
" Turn off whitespaces compare and folding in vimdiff
set splitright
silent! set splitvertical
set diffopt+=iwhite
set diffopt+=vertical
nnoremap <Leader>1 :diffget 1<CR>:diffupdate<CR>
nnoremap <Leader>2 :diffget 2<CR>:diffupdate<CR>
set clipboard=unnamed
function! DeleteCurrentFileAndBuffer()
call delete(expand('%'))
bdelete!
endfunction
function! NearestMethodOrFunction() abort
let fname = get(b:, 'vista_nearest_method_or_function', '')
return len(fname) > 0 ? "\u0192 " . fname : ""
endfunction
function! DrawGitBranchInfo()
let branch = fugitive#head()
return len(branch) > 0 ? " " . branch : ""
endfunction
function! MyFiletype()
return winwidth(0) > 70 ? (strlen(&filetype) ? WebDevIconsGetFileTypeSymbol() : '') : ''
endfunction
function! LightLineFilename()
let name = ""
let subs = split(expand('%'), "/")
let i = 1
for s in subs
let parent = name
if i == len(subs)
let name = len(parent) > 0 ? parent . '/' . s : s
elseif i == 1
let name = s
else
let part = strpart(s, 0, 10)
let name = len(parent) > 0 ? parent . '/' . part : part
endif
let i += 1
endfor
return name
endfunction
let g:lightline = {
\ 'colorscheme': 'quantum',
\ 'active': {
\ 'left': [ ['fileicon'], [ 'cocstatus' ], [ 'filename', 'nearmethod' ] ],
\ 'right': [ [ 'icongitbranch' ], [ 'lineinfo' ] ]
\ },
\ 'inactive': {
\ 'left': [ [], ['fileicon'], [ 'filename' ] ],
\ 'right': []
\ },
\ 'component': { 'lineinfo': ' %2p%% %3l:%-2v' },
\ 'component_function': {
\ 'fileicon': 'MyFiletype',
\ 'icongitbranch': 'DrawGitBranchInfo',
\ 'iconline': 'DrawLineInfo',
\ 'gitbranch': 'fugitive#head',
\ 'cocstatus': 'coc#status',
\ 'filename': 'LightLineFilename',
\ 'nearmethod': 'NearestMethodOrFunction'
\ },
\ }
" Use auocmd to force lightline update.
autocmd User CocStatusChange,CocDiagnosticChange call lightline#update()
autocmd VimEnter * call vista#RunForNearestMethodOrFunction()
set shortmess+=c
set signcolumn=yes
" Use tab for trigger completion with characters ahead and navigate.
" Use command ':verbose imap <tab>' to make sure tab is not mapped by other plugin.
inoremap <silent><expr> <TAB>
\ pumvisible() ? "\<C-n>" :
\ <SID>check_back_space() ? "\<TAB>" :
\ coc#refresh()
inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"
function! s:check_back_space() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~# '\s'
endfunction
" Use <c-space> to trigger completion.
inoremap <silent><expr> <c-space> coc#refresh()
" Use <cr> to confirm completion, `<C-g>u` means break undo chain at current position.
" Coc only does snippet and additional edit on confirm.
inoremap <expr> <cr> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>"
" Remap keys for gotos
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>
" Use L to highlight the symbol under the cursor
nnoremap <silent> L :call CocActionAsync('highlight')<CR>
function! s:show_documentation()
if (index(['vim','help'], &filetype) >= 0)
execute 'h '.expand('<cword>')
else
call CocAction('doHover')
endif
endfunction
" Highlight symbol under cursor on CursorHold
autocmd CursorHold * silent call CocActionAsync('highlight')
" Use `:Fold` to fold current buffer
command! -nargs=? Fold :call CocAction('fold', <f-args>)
" Remap for format selected region
xmap <leader><leader>f <Plug>(coc-format-selected)
nmap <leader><leader>f <Plug>(coc-format-selected)
" Create mappings for function text object, requires document symbols feature of languageserver.
xmap if <Plug>(coc-funcobj-i)
xmap af <Plug>(coc-funcobj-a)
omap if <Plug>(coc-funcobj-i)
omap af <Plug>(coc-funcobj-a)
" Remap for do codeAction of selected region, ex: `<leader>aap` for current paragraph
xmap <leader>a <Plug>(coc-codeaction-selected)
nmap <leader>a <Plug>(coc-codeaction-selected)
" Remap for do codeAction of current line
nmap <leader>ac <Plug>(coc-codeaction)
" Fix autofix problem of current line
nmap <leader>qf <Plug>(coc-fix-current)
function! StatusDiagnostic() abort
let info = get(b:, 'coc_diagnostic_info', {})
if empty(info) | return '' | endif
let msgs = []
if get(info, 'error', 0)
call add(msgs, 'E' . info['error'])
endif
if get(info, 'warning', 0)
call add(msgs, 'W' . info['warning'])
endif
return join(msgs, ' ') . ' ' . get(g:, 'coc_status', '')
endfunction
" Add status line support, for integration with other plugin, checkout `:h coc-status`
set statusline^=%{coc#status()}%{StatusDiagnostic()}
" Vim easymotion
nmap <silent> ;; <Plug>(easymotion-overwin-f)
nmap <silent> ;l <Plug>(easymotion-overwin-line)
" Show the style name of thing under the cursor
" Shamelessly taken from https://github.com/tpope/vim-scriptease
function! FaceNames(...) abort
if a:0
let [line, col] = [a:1, a:2]
else
let [line, col] = [line('.'), col('.')]
endif
return reverse(map(synstack(line, col), 'synIDattr(v:val,"name")'))
endfunction
function! DescribeFace(count) abort
if a:count
let name = get(FaceNames(), a:count-1, '')
if name !=# ''
return 'syntax list '.name
endif
else
echo join(FaceNames(), ' ')
endif
return ''
endfunction
nnoremap zs :<C-U>exe DescribeFace(v:count)<CR>
" Auto change root of the project
let g:rooter_change_directory_for_non_project_files = 'current'
let g:rooter_patterns = ['Cargo.tom', 'package.json', '.git/']
" DENITE
let g:fruzzy#sortonempty = 1
let g:fruzzy#usenative = 1
call denite#custom#source('_', 'matchers', ['matcher/fruzzy'])
call denite#custom#var('file/rec', 'command', ['rg', '--files', '--glob', '!.git'])
call denite#custom#var('grep', 'command', ['rg'])
call denite#custom#var('grep', 'default_opts', ['--hidden', '--vimgrep', '--heading', '-S'])
call denite#custom#var('grep', 'recursive_opts', [])
call denite#custom#var('grep', 'pattern_opt', ['--regexp'])
call denite#custom#var('grep', 'separator', ['--'])
call denite#custom#var('grep', 'final_opts', [])
call denite#custom#source('grep', 'converters', ['converter/abbr_word'])
call denite#custom#option('_', 'max_dynamic_update_candidates', 100000)
call denite#custom#var('outline', 'command', ['ctags'])
" Tell ctags write tags to stdin, so Denite can pick it up
call denite#custom#var('outline', 'options', ['-f -', '--excmd=number'])
let s:denite_options = {
\ 'prompt' : '',
\ 'split': 'floating',
\ 'start_filter': 1,
\ 'auto_resize': 1,
\ 'source_names': 'short',
\ 'direction': 'botright',
\ 'statusline': 0,
\ 'cursorline': 0,
\ 'highlight_matched_char': 'WildMenu',
\ 'highlight_matched_range': 'WildMenu',
\ 'highlight_window_background': 'Visual',
\ 'highlight_filter_background': 'CocListMagentaGray',
\ 'highlight_preview_line': 'Cursor',
\ 'vertical_preview': 1
\ }
call denite#custom#option('default', s:denite_options)
autocmd FileType denite call s:denite_my_settings()
function! s:denite_my_settings() abort
nnoremap <silent><buffer><expr> <CR>
\ denite#do_map('do_action')
nnoremap <silent><buffer><expr> d
\ denite#do_map('do_action', 'delete')
nnoremap <silent><buffer><expr> <c-t>
\ denite#do_map('do_action', 'tabopen')
nnoremap <silent><buffer><expr> <c-v>
\ denite#do_map('do_action', 'vsplit')
nnoremap <silent><buffer><expr> <c-k>
\ denite#do_map('do_action', 'split')
nnoremap <silent><buffer><expr> p
\ denite#do_map('do_action', 'preview')
nnoremap <silent><buffer><expr> q
\ denite#do_map('quit')
nnoremap <silent><buffer><expr> i
\ denite#do_map('open_filter_buffer')
nnoremap <silent><buffer><expr> <c-a>
\ denite#do_map('toggle_select_all')
endfunction
autocmd FileType denite-filter call s:denite_filter_my_settings()
function! s:denite_filter_my_settings() abort
imap <silent><buffer> <tab> <Plug>(denite_filter_quit)
inoremap <silent><buffer><expr> <CR> denite#do_map('do_action')
inoremap <silent><buffer><expr> <c-t>
\ denite#do_map('do_action', 'tabopen')
inoremap <silent><buffer><expr> <c-a>
\ denite#do_map('toggle_select_all')
inoremap <silent><buffer><expr> <c-o>
\ denite#do_map('do_action', 'quickfix')
inoremap <silent><buffer><expr> <esc>
\ denite#do_map('quit')
inoremap <silent><buffer> <C-j>
\ <Esc><C-w>p:call cursor(line('.')+1,0)<CR><C-w>pA
inoremap <silent><buffer> <C-k>
\ <Esc><C-w>p:call cursor(line('.')-1,0)<CR><C-w>pA
endfunction
nnoremap \ :Denite grep<CR>
nnoremap <Leader>pf :Denite file/rec<CR>
nnoremap <Leader>pr :Denite file/old buffer<CR>
nnoremap <C-o> :Denite outline<CR>
map * :Denite -resume -refresh<CR>
" Multiple Cursor
let g:multi_cursor_use_default_mapping=0
let g:multi_cursor_start_word_key = '<C-d>'
let g:multi_cursor_select_all_word_key = '<C-L>'
let g:multi_cursor_start_key = 'g<C-d>'
let g:multi_cursor_select_all_key = 'g<C-L>'
let g:multi_cursor_next_key = '<C-d>'
let g:multi_cursor_prev_key = '<C-p>'
let g:multi_cursor_skip_key = '<C-i>'
let g:multi_cursor_quit_key = '<Esc>'
set termguicolors
let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum"
let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"
" Some custom style
highlight Normal guibg=NONE
highlight EasyMotionTargetDefault guifg=#ffb400
highlight NonText guifg=#354751
highlight VertSplit guifg=#212C32
highlight link deniteSource_SymbolsName Symbol
highlight link deniteSource_SymbolsHeader String
highlight link deniteSource_grepLineNR deniteSource_grepFile
highlight WildMenu guibg=NONE guifg=#87bb7c
highlight CursorLineNr guibg=NONE