-
Notifications
You must be signed in to change notification settings - Fork 102
/
vimrc_mini
544 lines (471 loc) · 17.3 KB
/
vimrc_mini
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
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" _ _
" (_) __(_)___ ___
" / / | / / / __ `__ \
" / /| |/ / / / / / / /
" /_/ |___/_/_/ /_/ /_/ mini
"
" ivim mini (ivim for fast and easy usage, supports both vim 8.0+ and neovim)
" Main Contributor: Xiao-Ou Zhang (kepbod) <[email protected]>
" Version: 3.0
" Created: 2015-09-24
" Last Modified: 2021-08-11
"
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"------------------------------------------------
" => General
"------------------------------------------------
set nocompatible " Get out of vi compatible mode
filetype plugin indent on " Enable filetype
let mapleader=',' " Change the mapleader
let maplocalleader='\' " Change the maplocalleader
set timeoutlen=500 " Time to wait for a command
" Source the vimrc file after saving it
autocmd BufWritePost $MYVIMRC source $MYVIMRC
" Fast edit the .vimrc file using ,x
nnoremap <Leader>x :tabedit $MYVIMRC<CR>
set autoread " Set autoread when a file is changed outside
set autowrite " Write on make/shell commands
set hidden " Turn on hidden"
set history=1000 " Increase the lines of history
set modeline " Turn on modeline
set encoding=utf-8 " Set utf-8 encoding
set completeopt+=longest " Optimize auto complete
set completeopt-=preview " Optimize auto complete
set undofile " Set undo
" Set directories
function! InitializeDirectories()
let parent=$HOME
if has('nvim')
let prefix='.local/share/nvim'
let dir_list={'cache': ''}
else
let prefix='.vim'
let dir_list={
\ 'backup': 'backupdir',
\ 'view': 'viewdir',
\ 'swap': 'directory',
\ 'undo': 'undodir',
\ 'cache': ''}
endif
for [dirname, settingname] in items(dir_list)
let directory=parent.'/'.prefix.'/'.dirname.'/'
if !isdirectory(directory)
if exists('*mkdir')
let dir = substitute(directory, "/$", "", "")
call mkdir(dir, 'p')
else
echo 'Warning: Unable to create directory: '.directory
endif
endif
if settingname!=''
exe 'set '.settingname.'='.directory
endif
endfor
endfunction
call InitializeDirectories()
autocmd BufWinLeave *.* silent! mkview " Make Vim save view (state) (folds, cursor, etc)
autocmd BufWinEnter *.* silent! loadview " Make Vim load view (state) (folds, cursor, etc)
" Disable mouse
set mouse=
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"--------------------------------------------------
" => Vim-plug
"--------------------------------------------------
if has('nvim')
if empty(glob('~/.config/nvim/autoload/plug.vim'))
silent !curl -fLo ~/.config/nvim/autoload/plug.vim --create-dirs
\ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
autocmd VimEnter * PlugInstall | source $MYVIMRC
endif
call plug#begin('~/.config/nvim/plugged')
else
if empty(glob('~/.vim/autoload/plug.vim'))
silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs
\ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
autocmd VimEnter * PlugInstall | source $MYVIMRC
endif
call plug#begin('~/.vim/plugged')
endif
let g:plug_url_format='https://hub.fastgit.org/%s.git'
" Install plugins
Plug 'arcticicestudio/nord-vim' " Colorscheme Nord
Plug 'vim-airline/vim-airline' | Plug 'vim-airline/vim-airline-themes' " Status line
Plug 'Yggdroot/indentLine' " Indentation level
Plug 'ryanoasis/vim-devicons' " Devicons
Plug 'machakann/vim-highlightedyank' " highlight yanked region
Plug 'bling/vim-bufferline' " Buffer line
Plug 'mhinz/vim-startify' " Start page
Plug 'Raimondi/delimitMate' " Closing of quotes
Plug 'tomtom/tcomment_vim' " Commenter
Plug 'haya14busa/incsearch.vim' " Incremental highlighting
Plug 'haya14busa/vim-asterisk' " Improved asterisk
Plug 'easymotion/vim-easymotion' " Easy motion
Plug 'terryma/vim-multiple-cursors' " Multiple cursors
Plug 'tommcdo/vim-exchange' " Exchange text
Plug 'tpope/vim-surround' " Surround
Plug 'tpope/vim-repeat' " Repeat
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' } " Fuzzy finder
Plug 'junegunn/fzf.vim' " Fuzzy finder plugin
Plug 'junegunn/vim-easy-align', { 'on': ['<Plug>(EasyAlign)', 'EasyAlign'] } " Easy align
Plug 'roxma/vim-paste-easy' " Easy paste
Plug 'sickill/vim-pasta' " Vim pasta
Plug 'Keithbsmiley/investigate.vim' " Helper
Plug 'wellle/targets.vim' " Text objects
Plug 'roman/golden-ratio' " Resize windows
Plug 'chrisbra/vim-diff-enhanced' " Create better diffs
Plug 'tpope/vim-unimpaired' " Pairs of mappings
Plug 'bradford-smith94/quick-scope' " Quick scope
Plug 'yuttie/comfortable-motion.vim' " Comfortable motion
Plug 'sjl/gundo.vim' " Uundo tree
Plug 'bkad/CamelCaseMotion' " Camel case motion
Plug 'majutsushi/tagbar' " Tag bar
Plug 'ludovicchabant/vim-gutentags' " Manage tag files
Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' } " NERD tree
Plug 'Xuyuanp/nerdtree-git-plugin', { 'on': 'NERDTreeToggle' } " NERD tree git
Plug 'prabirshrestha/asyncomplete.vim' " Async autocompletion
Plug 'prabirshrestha/async.vim' " Normalize async job control api
Plug 'prabirshrestha/vim-lsp' " Async language server protocol
Plug 'mattn/vim-lsp-settings' " Auto configurations for language servers
Plug 'prabirshrestha/asyncomplete-lsp.vim' " Language server protocol
Plug 'prabirshrestha/asyncomplete-tags.vim' " Tag completions
Plug 'yami-beta/asyncomplete-omni.vim' " Omni completion
Plug 'prabirshrestha/asyncomplete-buffer.vim' " Buffer completion
Plug 'prabirshrestha/asyncomplete-file.vim' " File completion
Plug 'prabirshrestha/asyncomplete-neosnippet.vim' " Neosnippet autocompletion
Plug 'andreypopp/asyncomplete-ale.vim' " Ale autocompletion
Plug 'Shougo/neosnippet.vim' " Snippet engine
Plug 'Shougo/neosnippet-snippets' " Snippets
Plug 'wellle/tmux-complete.vim' " Completion for tmux panes
Plug 'Shougo/echodoc.vim' " Function signatures
Plug 'w0rp/ale' " Lint engine
Plug 'tpope/vim-fugitive' " Git wrapper
Plug 'airblade/vim-gitgutter' " Git diff sign
Plug 'mattn/emmet-vim', { 'for': ['html', 'css'] } " Emmet
Plug 'sheerun/vim-polyglot' " Language Support
call plug#end()
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"-------------------------------------------------
" => User Interface
"-------------------------------------------------
" Set status line
set laststatus=2 " Show the statusline
set noshowmode " Hide the default mode text
let g:airline_theme='nord'
set ttimeoutlen=50
let g:bufferline_echo=0
let g:bufferline_modified='[+]'
let g:airline_powerline_fonts=1
" Set tabline
let g:airline#extensions#tabline#enabled=1
" Only have cursorline in current window and in normal window
autocmd WinLeave * set nocursorline
autocmd WinEnter * set cursorline
autocmd InsertEnter * set nocursorline
autocmd InsertLeave * set cursorline
set wildmenu " Show list instead of just completing
set wildmode=list:longest,full " Use powerful wildmenu
set shortmess=at " Avoids hit enter
set showcmd " Show cmd
set backspace=indent,eol,start " Make backspaces delete sensibly
set whichwrap+=h,l,<,>,[,] " Backspace and cursor keys wrap to
set virtualedit=block,onemore " Allow for cursor beyond last character
set scrolljump=5 " Lines to scroll when cursor leaves screen
set scrolloff=3 " Minimum lines to keep above and below cursor
set sidescroll=1 " Minimal number of columns to scroll horizontally
set sidescrolloff=10 " Minimal number of screen columns to keep away from cursor
set showmatch " Show matching brackets/parenthesis
set matchtime=2 " Decrease the time to blink
set number " Show line numbers
set formatoptions+=rnlmM " Optimize format options
set wrap " Set wrap
set textwidth=80 " Change text width
set list " Show these tabs and spaces and so on
set listchars=tab:▸\ ,eol:¬,extends:❯,precedes:❮ " Change listchars
set linebreak " Wrap long lines at a blank
set showbreak=↪ " Change wrap line break
set fillchars=diff:⣿,vert:│ " Change fillchars
augroup trailing " Only show trailing whitespace when not in insert mode
autocmd!
autocmd InsertEnter * :set listchars-=trail:⌴
autocmd InsertLeave * :set listchars+=trail:⌴
augroup END
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"-------------------------------------------------
" => Colors and Fonts
"-------------------------------------------------
" Use true colors
if (empty($TMUX))
if (has('nvim'))
let $NVIM_TUI_ENABLE_TRUE_COLOR=1
endif
if (has('termguicolors'))
set termguicolors
endif
endif
syntax on " Enable syntax
set background=dark " Set background
set t_Co=256 " Use 256 colors
" Enable italic
let g:nord_italic=1
let g:nord_italic_comments=1
let &t_ZH="\e[3m"
let &t_ZR="\e[23m"
" Set mode-specific cursor shapes
let &t_SI = "\<Esc>[6 q"
let &t_SR = "\<Esc>[4 q"
let &t_EI = "\<Esc>[2 q"
" Load a colorscheme
colorscheme nord
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"-------------------------------------------------
" => Indent Related
"-------------------------------------------------
set autoindent " Preserve current indent on new lines
set cindent " set C style indent
set expandtab " Convert all tabs typed to spaces
set softtabstop=4 " Indentation levels every four columns
set shiftwidth=4 " Indent/outdent by four columns
set shiftround " Indent/outdent to nearest tabstop
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"-------------------------------------------------
" => Search Related
"-------------------------------------------------
set ignorecase " Case insensitive search
set smartcase " Case sensitive when uc present
set hlsearch " Highlight search terms
set incsearch " Find as you type search
set gdefault " turn on g flag
if has('nvim')
set inccommand=nosplit " live substitution
endif
" incsearch & asterisk
let g:incsearch#magic='\m'
let g:incsearch#auto_nohlsearch=1
map / <Plug>(incsearch-forward)
map ? <Plug>(incsearch-backward)
map g/ <Plug>(incsearch-stay)
map n <Plug>(incsearch-nohl-n)
map N <Plug>(incsearch-nohl-N)
map * <Plug>(incsearch-nohl0)<Plug>(asterisk-z*)
map g* <Plug>(incsearch-nohl0)<Plug>(asterisk-gz*)
map # <Plug>(incsearch-nohl0)<Plug>(asterisk-z#)
map g# <Plug>(incsearch-nohl0)<Plug>(asterisk-gz#)
" Toggle relativenumber
nnoremap <Leader>n :set relativenumber!<CR>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"-------------------------------------------------
" => Fold Related
"-------------------------------------------------
set foldlevelstart=0 " Start with all folds closed
set foldcolumn=1 " Set fold column
" Space to toggle and create folds.
nnoremap <silent> <Space> @=(foldlevel('.') ? 'za' : '\<Space>')<CR>
vnoremap <Space> zf
" Set foldtext
function! MyFoldText()
let line=getline(v:foldstart)
let nucolwidth=&foldcolumn+&number*&numberwidth
let windowwidth=winwidth(0)-nucolwidth-3
let foldedlinecount=v:foldend-v:foldstart+1
let onetab=strpart(' ', 0, &tabstop)
let line=substitute(line, '\t', onetab, 'g')
let line=strpart(line, 0, windowwidth-2-len(foldedlinecount))
let fillcharcount=windowwidth-len(line)-len(foldedlinecount)
return line.'…'.repeat(' ',fillcharcount).foldedlinecount.'L'.' '
endfunction
set foldtext=MyFoldText()
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"-------------------------------------------------
" => Key Mapping
"-------------------------------------------------
" Make j and k work the way you expect
nnoremap j gj
nnoremap k gk
vnoremap j gj
vnoremap k gk
" Navigation between windows
nnoremap <C-J> <C-W>j
nnoremap <C-K> <C-W>k
nnoremap <C-H> <C-W>h
nnoremap <C-L> <C-W>l
" Same when jumping around
nnoremap g; g;zz
nnoremap g, g,zz
" Reselect visual block after indent/outdent
vnoremap < <gv
vnoremap > >gv
" Keep the cursor in place while joining lines
nnoremap J mzJ`z
" Strip all trailing whitespace in the current file
nnoremap <Leader>q :%s/\s\+$//<CR>:let @/=''<CR>
" Modify all the indents
nnoremap \= gg=G
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"--------------------------------------------------
" => Plugin Setting
"--------------------------------------------------
" -> Startify
if has('nvim')
let g:startify_session_dir=$HOME . '/.config/nvim/cache/session'
else
let g:startify_session_dir=$HOME .'/.vim/cache/session'
endif
let g:startify_custom_header=[
\' _ _ ',
\' (_) __(_)___ ___ ',
\' / / | / / / __ `__ \',
\' / /| |/ / / / / / / /',
\' /_/ |___/_/_/ /_/ /_/ ',
\' ']
let g:startify_custom_footer=['', ' This configuration is maintained by Xiao-Ou Zhang <[email protected]> and other contributors. Thanks!']
hi StartifyHeader ctermfg=111
hi StartifyFooter ctermfg=111
hi StartifyBracket ctermfg=240
hi StartifyNumber ctermfg=215
hi StartifyPath ctermfg=245
hi StartifySlash ctermfg=240
" -> delimitMate
let delimitMate_expand_cr=1
let delimitMate_expand_space=1
let delimitMate_balance_matchpairs=1
" -> TComment
" Map \<Space> to commenting
function! IsWhiteLine()
if (getline('.')=~'^$')
exe 'TCommentBlock'
normal! j
else
normal! A
exe 'TCommentRight'
normal! l
normal! x
endif
startinsert!
endfunction
nnoremap <silent> <LocalLeader><Space> :call IsWhiteLine()<CR>
" -> Asyncomplete
let g:asyncomplete_remove_duplicates=1
let g:asyncomplete_smart_completion=1
let g:lsp_diagnostics_enabled=0
inoremap <expr> <Tab> pumvisible() ? "\<C-N>" : "\<Tab>"
inoremap <expr> <S-Tab> pumvisible() ? "\<C-P>" : "\<S-Tab>"
inoremap <expr> <CR> pumvisible() ? asyncomplete#close_popup() . "\<CR>" : "\<CR>"
nnoremap <silent> <LocalLeader>g :LspDefinition<CR>
" Omni
call asyncomplete#register_source(asyncomplete#sources#omni#get_source_options({
\ 'name': 'omni',
\ 'whitelist': ['*'],
\ 'blacklist': ['c', 'cpp', 'html'],
\ 'completor': function('asyncomplete#sources#omni#completor')
\ }))
" Ctags
au User asyncomplete_setup call asyncomplete#register_source(asyncomplete#sources#tags#get_source_options({
\ 'name': 'tags',
\ 'whitelist': ['c'],
\ 'completor': function('asyncomplete#sources#tags#completor'),
\ }))
" Buffer
call asyncomplete#register_source(asyncomplete#sources#buffer#get_source_options({
\ 'name': 'buffer',
\ 'whitelist': ['*'],
\ 'blacklist': ['go'],
\ 'completor': function('asyncomplete#sources#buffer#completor'),
\ }))
" File
au User asyncomplete_setup call asyncomplete#register_source(asyncomplete#sources#file#get_source_options({
\ 'name': 'file',
\ 'whitelist': ['*'],
\ 'priority': 10,
\ 'completor': function('asyncomplete#sources#file#completor')
\ }))
" Neosnippet
call asyncomplete#register_source(asyncomplete#sources#neosnippet#get_source_options({
\ 'name': 'neosnippet',
\ 'whitelist': ['*'],
\ 'completor': function('asyncomplete#sources#neosnippet#completor'),
\ }))
imap <C-K> <Plug>(neosnippet_expand_or_jump)
smap <C-K> <Plug>(neosnippet_expand_or_jump)
xmap <C-K> <Plug>(neosnippet_expand_target)
" Tmux-complete
let g:tmuxcomplete#asyncomplete_source_options = {
\ 'name': 'tmuxcomplete',
\ 'whitelist': ['*'],
\ 'config': {
\ 'splitmode': 'words',
\ 'filter_prefix': 1,
\ 'show_incomplete': 1,
\ 'sort_candidates': 0,
\ 'scrollback': 0
\ }
\ }
" Ale
au User asyncomplete_setup call asyncomplete#ale#register_source({
\ 'name': 'reason',
\ 'linter': 'flow',
\ })
" -> Easy Align
xmap ga <Plug>(EasyAlign)
nmap ga <Plug>(EasyAlign)
" -> Investigate.vim
nnoremap K :call investigate#Investigate()<CR>
let g:investigate_use_dash=1
" -> EnhancedDiff
let &diffexpr='EnhancedDiff#Diff("git diff", "--diff-algorithm=patience")'
" -> Quick-scope
let g:qs_max_chars=80
" -> Tag bar
nnoremap <Leader>t :TagbarToggle<CR>
let g:tagbar_autofocus=1
let g:tagbar_expand=1
let g:tagbar_foldlevel=2
let g:tagbar_autoshowtag=1
" -> Gutentags
if has('nvim')
let gutentags_cache_dir=$HOME . '/.local/share/nvim/cache/ctags'
else
let g:gutentags_cache_dir=$HOME . '/.vim/cache/ctags'
endif
" -> NERD Tree
nnoremap <Leader>f :NERDTreeToggle<CR>
let NERDTreeChDirMode=2
let NERDTreeShowBookmarks=1
let NERDTreeShowHidden=1
let NERDTreeShowLineNumbers=1
augroup nerd_loader
autocmd!
autocmd VimEnter * silent! autocmd! FileExplorer
autocmd BufEnter,BufNew *
\ if isdirectory(expand('<amatch>'))
\| call plug#load('nerdtree')
\| execute 'autocmd! nerd_loader'
\| endif
augroup END
" -> Ale
let g:airline#extensions#ale#enabled=1
let g:ale_sign_error='✗'
let g:ale_sign_warning='∆'
nmap <silent> [w <Plug>(ale_previous)
nmap <silent> ]w <Plug>(ale_next)
highlight ALEErrorSign guibg=NONE guifg=red
highlight ALEWarningSign guibg=NONE guifg=yellow
let g:ale_linters = {
\ 'python': ['flake8'],
\}
" -> Emmet
let g:user_emmet_leader_key='<C-Z>'
let g:user_emmet_settings={'indentation':' '}
let g:use_emmet_complete_tag=1
" -> Gundo
nnoremap <Leader>u :GundoToggle<CR>
" -> Matchit
if !has('nvim')
" Start matchit
packadd! matchit
endif
" Use Tab instead of % to switch
nmap <Tab> %
vmap <Tab> %
" -> Vim-polyglot
let g:vim_markdown_conceal=0