-
Notifications
You must be signed in to change notification settings - Fork 25
/
init.vim
759 lines (621 loc) · 24.4 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
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
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
set encoding=utf-8
scriptencoding utf-8
"{ Builtin optional plugins
" Activate matchit plugin
runtime! macros/matchit.vim
" Activate man page plugin
runtime! ftplugin/man.vim
"}
"{ Builtin options and settings
if !has('nvim')
" Change cursor shapes based on whether we are in insert mode,
" see https://vi.stackexchange.com/questions/9131/i-cant-switch-to-cursor-in-insert-mode
let &t_SI = "\<esc>[6 q"
let &t_EI = "\<esc>[2 q"
if exists('&t_SR')
let &t_SR = "\<esc>[4 q"
endif
" The number of color to use
set t_Co=256
endif
" Use English as default
language en_US.utf-8
filetype plugin indent on
syntax enable
" Set height of status line
set laststatus=2
" Changing fillchars for folding, so there is no garbage charactes
set fillchars=fold:\ ,vert:\|
" Paste mode toggle, it seems that Neovim's bracketed paste mode
" does not work very well for nvim-qt, so we use good-old paste mode
set pastetoggle=<F12>
" Split window below/right when creating horizontal/vertical windows
set splitbelow splitright
" Time in milliseconds to wait for a mapped sequence to complete,
" see https://unix.stackexchange.com/q/36882/221410 for more info
set timeoutlen=500
" For CursorHold events
set updatetime=800
" Clipboard settings, always use clipboard for all delete, yank, change, put
" operation, see https://stackoverflow.com/q/30691466/6064933
set clipboard+=unnamed
set clipboard+=unnamedplus
" Disable creating swapfiles, see https://stackoverflow.com/q/821902/6064933
set noswapfile
" General tab settings
set tabstop=4 " number of visual spaces per TAB
set softtabstop=4 " number of spaces in tab when editing
set shiftwidth=4 " number of spaces to use for autoindent
set expandtab " expand tab to spaces so that tabs are spaces
" Set matching pairs of characters and highlight matching brackets
set matchpairs+=<:>,「:」
" Show line number and relative line number
set number relativenumber
" Ignore case in general, but become case-sensitive when uppercase is present
set ignorecase smartcase
" File and script encoding settings for vim
set fileencoding=utf-8
set fileencodings=ucs-bom,utf-8,cp936,gb18030,big5,euc-jp,euc-kr,latin1
" Break line at predefined characters
set linebreak
" Character to show before the lines that have been soft-wrapped
set showbreak=↪
" List all items and start selecting matches in cmd completion
set wildmode=list:full
" Show current line where the cursor is
set cursorline
" Set a ruler at column 80, see https://stackoverflow.com/q/2447109/6064933
set colorcolumn=80
" Minimum lines to keep above and below cursor when scrolling
set scrolloff=3
" Use mouse to select and resize windows, etc.
if has('mouse')
set mouse=nic " Enable mouse in several mode
set mousemodel=popup " Set the behaviour of mouse
endif
" Do not show mode on command line since vim-airline can show it
set noshowmode
" Fileformats to use for new files
set fileformats=unix,dos
" The mode in which cursorline text can be concealed
set concealcursor=nc
" The way to show the result of substitution in real time for preview
if exists('&inccommand')
set inccommand=nosplit
endif
" Ignore certain files and folders when globbing
set wildignore+=*.o,*.obj,*.bin,*.dll,*.exe
set wildignore+=*/.git/*,*/.svn/*,*/__pycache__/*,*/build/**
set wildignore+=*.pyc
set wildignore+=*.DS_Store
set wildignore+=*.aux,*.bbl,*.blg,*.brf,*.fls,*.fdb_latexmk,*.synctex.gz,*.pdf
" Ask for confirmation when handling unsaved or read-only files
set confirm
" Do not use visual and error bells
set novisualbell noerrorbells
" The level we start to fold
set foldlevel=0
" The number of command and search history to keep
set history=500
" Use list mode and customized listchars
set list listchars=tab:▸\ ,extends:❯,precedes:❮,nbsp:+
" Auto-write the file based on some condition
set autowrite
" Show hostname, full path of file and last-mod time on the window title. The
" meaning of the format str for strftime can be found in
" http://man7.org/linux/man-pages/man3/strftime.3.html. The function to get
" lastmod time is drawn from https://stackoverflow.com/q/8426736/6064933
set title
set titlestring=
set titlestring+=%(%{hostname()}\ \ %)
set titlestring+=%(%{expand('%:p')}\ \ %)
set titlestring+=%{strftime('%Y-%m-%d\ %H:%M',getftime(expand('%')))}
" Persistent undo even after you close a file and re-open it.
" For vim, we need to set up an undodir so that $HOME is not cluttered with
" undo files.
if !has('nvim')
if !isdirectory($HOME . '/.local/vim/undo')
call mkdir($HOME . '/.local/vim/undo', 'p', 0700)
endif
set undodir=~/.local/vim/undo
endif
set undofile
" Completion behaviour
set completeopt+=menuone " Show menu even if there is only one item
set completeopt-=preview " Disable the preview window
" Settings for popup menu
set pumheight=15 " Maximum number of items to show in popup menu
if exists('&pumblend')
set pumblend=5 " Pesudo blend effect for popup menu
endif
" Scan files given by `dictionary` option
set complete+=k,kspell complete-=w complete-=b complete-=u complete-=t
set spelllang=en,cjk " Spell languages
" Align indent to next multiple value of shiftwidth. For its meaning,
" see http://vim.1045645.n5.nabble.com/shiftround-option-td5712100.html
set shiftround
" Virtual edit is useful for visual block edit
set virtualedit=block
" Correctly break multi-byte characters such as CJK,
" see https://stackoverflow.com/q/32669814/6064933
set formatoptions+=mM
" Tilde (~) is an operator, thus must be followed by motions like `e` or `w`.
set tildeop
" Do not add two spaces after a period when joining lines or formatting texts,
" see https://stackoverflow.com/q/4760428/6064933
set nojoinspaces
" Text after this column is not highlighted
set synmaxcol=500
" Increment search
set incsearch
set wildmenu
" Do not use corsorcolumn
set nocursorcolumn
set backspace=indent,eol,start " Use backsapce to delete
"}
"{ Functions
" Remove trailing white space, see https://vi.stackexchange.com/a/456/15292
function! StripTrailingWhitespaces() abort
let l:save = winsaveview()
keeppatterns %s/\v\s+$//e
call winrestview(l:save)
endfunction
" Custom fold expr, adapted from https://vi.stackexchange.com/a/9094/15292
function! VimFolds(lnum)
" get content of current line and the line below
let l:cur_line = getline(a:lnum)
let l:next_line = getline(a:lnum+1)
if l:cur_line =~# '^"{'
return '>' . (matchend(l:cur_line, '"{*') - 1)
else
if l:cur_line ==# '' && (matchend(l:next_line, '"{*') - 1) == 1
return 0
else
return '='
endif
endif
endfunction
" Custom fold text, adapted from https://vi.stackexchange.com/a/3818/15292
" and https://vi.stackexchange.com/a/6608/15292
function! MyFoldText()
let line = getline(v:foldstart)
let folded_line_num = v:foldend - v:foldstart
let line_text = substitute(line, '^"{\+', '', 'g')
let fillcharcount = &textwidth - len(line_text) - len(folded_line_num) - 10
return '+'. repeat('-', 4) . line_text . repeat('.', fillcharcount) . ' ('. folded_line_num . ' L)'
endfunction
"}
"{ Variables
let mapleader = ','
" Do not load netrw by default since I do not use it, see
" https://github.com/bling/dotvim/issues/4
let g:loaded_netrwPlugin = 1
" Do not load tohtml.vim
let g:loaded_2html_plugin = 1
"}
"{ Auto commands
" Do not use smart case in command line mode,
" extracted from https://vi.stackexchange.com/q/16509/15292
if exists('##CmdLineEnter')
augroup dynamic_smartcase
autocmd!
autocmd CmdLineEnter : set nosmartcase
autocmd CmdLineLeave : set smartcase
augroup END
endif
" Set textwidth for text file types
augroup text_file_width
autocmd!
" Sometimes, automatic filetype detection is not right, so we need to
" detect the filetype based on the file extensions
autocmd BufNewFile,BufRead *.md,*.MD,*.markdown setlocal textwidth=79
augroup END
if exists('##TermOpen')
augroup term_settings
autocmd!
" Do not use number and relative number for terminal inside nvim
autocmd TermOpen * setlocal norelativenumber nonumber
" Go to insert mode by default to start typing command
autocmd TermOpen * startinsert
augroup END
endif
" More accurate syntax highlighting? (see `:h syn-sync`)
augroup accurate_syn_highlight
autocmd!
autocmd BufEnter * :syntax sync fromstart
augroup END
" Return to last edit position when opening a file
augroup resume_edit_position
autocmd!
autocmd BufReadPost *
\ if line("'\"") > 1 && line("'\"") <= line("$") && &ft !~# 'commit'
\ | execute "normal! g`\"zvzz"
\ | endif
augroup END
" Display a message when the current file is not in utf-8 format.
" Note that we need to use `unsilent` command here because of this issue:
" https://github.com/vim/vim/issues/4379. For older Vim (version 7.4), the
" help file are in gzip format, do not warn this.
augroup non_utf8_file_warn
autocmd!
autocmd BufRead * if &fileencoding != 'utf-8' && expand('%:e') != 'gz'
\ | unsilent echomsg 'File not in UTF-8 format!' | endif
augroup END
augroup vimfile_setting
autocmd!
autocmd FileType vim setlocal foldmethod=expr foldlevel=0 foldlevelstart=-1
\ foldexpr=VimFolds(v:lnum) foldtext=MyFoldText()
\ keywordprg=:help formatoptions-=o formatoptions-=r
augroup END
augroup number_toggle
autocmd!
autocmd BufEnter,FocusGained,InsertLeave,WinEnter * if &number | set relativenumber | endif
autocmd BufLeave,FocusLost,InsertEnter,WinLeave * if &number | set norelativenumber | endif
augroup END
"}
"{ Custom key mappings
" Save key strokes (now we do not need to press shift to enter command mode).
" Vim-sneak has also mapped `;`, so using the below mapping will break the map
" used by vim-sneak
nnoremap ; :
xnoremap ; :
" Quicker way to open command window
nnoremap q; q:
" Quicker <Esc> in insert mode
inoremap <silent> jk <Esc>
" Turn the word under cursor to upper case
inoremap <silent> <c-u> <Esc>viwUea
" Turn the current word into title case
inoremap <silent> <c-t> <Esc>b~lea
" Paste non-linewise text above or below current cursor,
" see https://stackoverflow.com/a/1346777/6064933
nnoremap <leader>p m`o<ESC>p``
nnoremap <leader>P m`O<ESC>p``
" Shortcut for faster save and quit
nnoremap <silent> <leader>w :update<CR>
" Saves the file if modified and quit
nnoremap <silent> <leader>q :x<CR>
" Quit all opened buffers
nnoremap <silent> <leader>Q :qa<CR>
" Navigation in the location and quickfix list
nnoremap [l :lprevious<CR>zv
nnoremap ]l :lnext<CR>zv
nnoremap [L :lfirst<CR>zv
nnoremap ]L :llast<CR>zv
nnoremap [q :cprevious<CR>zv
nnoremap ]q :cnext<CR>zv
nnoremap [Q :cfirst<CR>zv
nnoremap ]Q :clast<CR>zv
" Close location list or quickfix list if they are present,
" see https://superuser.com/q/355325/736190
nnoremap<silent> \x :windo lclose <bar> cclose<CR>
" Close a buffer and switching to another buffer, do not close the
" window, see https://stackoverflow.com/q/4465095/6064933
nnoremap <silent> \d :bprevious <bar> bdelete #<CR>
" Toggle search highlight, see https://stackoverflow.com/q/9054780/6064933
nnoremap <silent><expr> <Leader>hl (&hls && v:hlsearch ? ':nohls' : ':set hls')."\n"
" Insert a blank line below or above current line (do not move the cursor),
" see https://stackoverflow.com/a/16136133/6064933
nnoremap <expr> oo 'm`' . v:count1 . 'o<Esc>``'
nnoremap <expr> OO 'm`' . v:count1 . 'O<Esc>``'
" nnoremap oo @='m`o<c-v><Esc>``'<cr>
" nnoremap OO @='m`O<c-v><Esc>``'<cr>
" the following two mappings work, but if you change double quote to single, it
" will not work
" nnoremap oo @="m`o\<lt>Esc>``"<cr>
" nnoremap oo @="m`o\e``"<cr>
" Insert a space after current character
nnoremap <silent> <Space><Space> a<Space><ESC>h
" Yank from current cursor position to the end of the line (make it
" consistent with the behavior of D, C)
nnoremap Y y$
" Move the cursor based on physical lines, not the actual lines.
nnoremap <silent> <expr> j (v:count == 0 ? 'gj' : 'j')
nnoremap <silent> <expr> k (v:count == 0 ? 'gk' : 'k')
nnoremap <silent> ^ g^
nnoremap <silent> 0 g0
" Do not include white space characters when using $ in visual mode,
" see https://vi.stackexchange.com/a/18571/15292
xnoremap $ g_
" Jump to matching pairs easily in normal mode
nnoremap <Tab> %
" Go to start or end of line easier
nnoremap H ^
xnoremap H ^
nnoremap L g_
xnoremap L g_
" Resize windows using <Alt> and h,j,k,l, inspiration from
" https://vim.fandom.com/wiki/Fast_window_resizing_with_plus/minus_keys (bottom page).
" If you enable mouse support, shorcuts below may not be necessary.
nnoremap <silent> <M-h> <C-w><
nnoremap <silent> <M-l> <C-w>>
nnoremap <silent> <M-j> <C-W>-
nnoremap <silent> <M-k> <C-W>+
" Fast window switching, inspiration from
" https://stackoverflow.com/a/4373470/6064933
nnoremap <silent> <M-left> <C-w>h
nnoremap <silent> <M-right> <C-w>l
nnoremap <silent> <M-down> <C-w>j
nnoremap <silent> <M-up> <C-w>k
" Continuous visual shifting (does not exit Visual mode), `gv` means
" to reselect previous visual area, see https://superuser.com/q/310417/736190
xnoremap < <gv
xnoremap > >gv
" When completion menu is shown, use <cr> to select an item
" and do not add an annoying newline. Otherwise, <enter> is what it is.
" For more info , see https://superuser.com/q/246641/736190 and
" https://unix.stackexchange.com/q/162528/221410
inoremap <expr> <cr> ((pumvisible())?("\<C-Y>"):("\<cr>"))
" Use <esc> to close auto-completion menu
inoremap <expr> <esc> ((pumvisible())?("\<C-e>"):("\<esc>"))
" Use <tab> to navigate down the completion menu.
inoremap <expr> <tab> pumvisible()?"\<C-n>":"\<tab>"
" Edit and reload init.vim quickly
nnoremap <silent> <leader>ev :edit $MYVIMRC<cr>
nnoremap <silent> <leader>sv :silent update $MYVIMRC <bar> source $MYVIMRC <bar>
\ echomsg "Nvim config successfully reloaded!"<cr>
" Reselect the text that has just been pasted
nnoremap <leader>v `[V`]
" Search in selected region
vnoremap / :<C-U>call feedkeys('/\%>'.(line("'<")-1).'l\%<'.(line("'>")+1)."l")<CR>
" Find and replace (like Sublime Text 3)
nnoremap <C-H> :%s/
xnoremap <C-H> :s/
" Change current working directory locally and print cwd after that,
" see https://vim.fandom.com/wiki/Set_working_directory_to_the_current_file
nnoremap <silent> <leader>cd :lcd %:p:h<CR>:pwd<CR>
" Use Esc to quit builtin terminal
if exists(':tnoremap')
tnoremap <ESC> <C-\><C-n>
endif
" Toggle spell checking
nnoremap <silent> <F11> :set spell!<cr>
inoremap <silent> <F11> <C-O>:set spell!<cr>
" Decrease indent level in insert mode with shift+tab
inoremap <S-Tab> <ESC><<i
" Change text without putting the text into register,
" see https://stackoverflow.com/q/54255/6064933
nnoremap c "_c
nnoremap C "_C
nnoremap cc "_cc
" Remove trailing whitespace characters
nnoremap <silent> <leader><Space> :call StripTrailingWhitespaces()<CR>
" Clear highlighting
if maparg('<C-L>', 'n') ==# ''
nnoremap <silent> <C-L> :nohlsearch<C-R>=has('diff')?'<Bar>diffupdate':''<CR><CR><C-L>
endif
nnoremap <up> :echoerr "Don't use arrow keys, use H, J, K, L instead!"<CR>
nnoremap <down> :echoerr "Don't use arrow keys, use H, J, K, L instead!"<CR>
nnoremap <right> :echoerr "Don't use arrow keys, use H, J, K, L instead!"<CR>
nnoremap <left> :echoerr "Don't use arrow keys, use H, J, K, L instead!"<CR>
"}
"{ UI settings
if !has('gui_running')
augroup MyColors
autocmd!
autocmd ColorScheme * call MyHighlights()
augroup END
else
set guioptions-=T
set guioptions-=m
set guioptions-=r
set guioptions-=L
endif
function! MyHighlights() abort
highlight clear
" The following colors are taken from ayu_mirage vim-airline theme,
" link: https://github.com/vim-airline/vim-airline-themes/
hi User1 ctermfg=0 ctermbg=114
hi User2 ctermfg=114 ctermbg=0
" The following colors are taken from vim-gruvbox8,
" link: https://github.com/lifepillar/vim-gruvbox8
hi Normal ctermfg=187 ctermbg=NONE cterm=NONE
hi CursorLineNr ctermfg=214 ctermbg=NONE cterm=NONE
hi FoldColumn ctermfg=102 ctermbg=NONE cterm=NONE
hi SignColumn ctermfg=187 ctermbg=NONE cterm=NONE
hi VertSplit ctermfg=59 ctermbg=NONE cterm=NONE
hi ColorColumn ctermfg=NONE ctermbg=237 cterm=NONE
hi Comment ctermfg=102 ctermbg=NONE cterm=italic
hi CursorLine ctermfg=NONE ctermbg=237 cterm=NONE
hi Error ctermfg=203 ctermbg=234 cterm=bold,reverse
hi ErrorMsg ctermfg=234 ctermbg=203 cterm=bold
hi Folded ctermfg=102 ctermbg=237 cterm=italic
hi LineNr ctermfg=243 ctermbg=NONE cterm=NONE
hi MatchParen ctermfg=NONE ctermbg=59 cterm=bold
hi NonText ctermfg=239 ctermbg=NONE cterm=NONE
hi Pmenu ctermfg=187 ctermbg=239 cterm=NONE
hi PmenuSbar ctermfg=NONE ctermbg=239 cterm=NONE
hi PmenuSel ctermfg=239 ctermbg=109 cterm=bold
hi PmenuThumb ctermfg=NONE ctermbg=243 cterm=NONE
hi SpecialKey ctermfg=102 ctermbg=NONE cterm=NONE
hi StatusLine ctermfg=239 ctermbg=187 cterm=reverse
hi StatusLineNC ctermfg=237 ctermbg=137 cterm=reverse
hi TabLine ctermfg=243 ctermbg=237 cterm=NONE
hi TabLineFill ctermfg=243 ctermbg=237 cterm=NONE
hi TabLineSel ctermfg=142 ctermbg=237 cterm=NONE
hi ToolbarButton ctermfg=230 ctermbg=59 cterm=bold
hi ToolbarLine ctermfg=NONE ctermbg=59 cterm=NONE
hi Visual ctermfg=NONE ctermbg=59 cterm=NONE
hi WildMenu ctermfg=109 ctermbg=239 cterm=bold
hi Conceal ctermfg=109 ctermbg=NONE cterm=NONE
hi Cursor ctermfg=NONE ctermbg=NONE cterm=reverse
hi DiffAdd ctermfg=142 ctermbg=234 cterm=reverse
hi DiffChange ctermfg=107 ctermbg=234 cterm=reverse
hi DiffDelete ctermfg=203 ctermbg=234 cterm=reverse
hi DiffText ctermfg=214 ctermbg=234 cterm=reverse
hi Directory ctermfg=142 ctermbg=NONE cterm=bold
hi EndOfBuffer ctermfg=234 ctermbg=NONE cterm=NONE
hi IncSearch ctermfg=208 ctermbg=234 cterm=reverse
hi ModeMsg ctermfg=214 ctermbg=NONE cterm=bold
hi MoreMsg ctermfg=214 ctermbg=NONE cterm=bold
hi Question ctermfg=208 ctermbg=NONE cterm=bold
hi Search ctermfg=214 ctermbg=234 cterm=reverse
hi SpellBad ctermfg=203 ctermbg=NONE cterm=italic,underline
hi SpellCap ctermfg=109 ctermbg=NONE cterm=italic,underline
hi SpellLocal ctermfg=107 ctermbg=NONE cterm=italic,underline
hi SpellRare ctermfg=175 ctermbg=NONE cterm=italic,underline
hi Title ctermfg=142 ctermbg=NONE cterm=bold
hi WarningMsg ctermfg=203 ctermbg=NONE cterm=bold
hi Boolean ctermfg=175 ctermbg=NONE cterm=NONE
hi Character ctermfg=175 ctermbg=NONE cterm=NONE
hi Conditional ctermfg=203 ctermbg=NONE cterm=NONE
hi Constant ctermfg=175 ctermbg=NONE cterm=NONE
hi Define ctermfg=107 ctermbg=NONE cterm=NONE
hi Debug ctermfg=203 ctermbg=NONE cterm=NONE
hi Delimiter ctermfg=208 ctermbg=NONE cterm=NONE
hi Error ctermfg=203 ctermbg=234 cterm=bold,reverse
hi Exception ctermfg=203 ctermbg=NONE cterm=NONE
hi Float ctermfg=175 ctermbg=NONE cterm=NONE
hi Function ctermfg=142 ctermbg=NONE cterm=bold
hi Identifier ctermfg=109 ctermbg=NONE cterm=NONE
hi Ignore ctermfg=fg ctermbg=NONE cterm=NONE
hi Include ctermfg=107 ctermbg=NONE cterm=NONE
hi Keyword ctermfg=203 ctermbg=NONE cterm=NONE
hi Label ctermfg=203 ctermbg=NONE cterm=NONE
hi Macro ctermfg=107 ctermbg=NONE cterm=NONE
hi Number ctermfg=175 ctermbg=NONE cterm=NONE
hi Operator ctermfg=107 ctermbg=NONE cterm=NONE
hi PreCondit ctermfg=107 ctermbg=NONE cterm=NONE
hi PreProc ctermfg=107 ctermbg=NONE cterm=NONE
hi Repeat ctermfg=203 ctermbg=NONE cterm=NONE
hi SpecialChar ctermfg=203 ctermbg=NONE cterm=NONE
hi SpecialComment ctermfg=203 ctermbg=NONE cterm=NONE
hi Statement ctermfg=203 ctermbg=NONE cterm=NONE
hi StorageClass ctermfg=208 ctermbg=NONE cterm=NONE
hi Special ctermfg=208 ctermbg=NONE cterm=italic
hi String ctermfg=142 ctermbg=NONE cterm=italic
hi Structure ctermfg=107 ctermbg=NONE cterm=NONE
hi Todo ctermfg=fg ctermbg=234 cterm=bold,italic
hi Type ctermfg=214 ctermbg=NONE cterm=NONE
hi Typedef ctermfg=214 ctermbg=NONE cterm=NONE
hi Underlined ctermfg=109 ctermbg=NONE cterm=underline
hi CursorIM ctermfg=NONE ctermbg=NONE cterm=reverse
hi Comment cterm=NONE
hi Folded cterm=NONE
hi SpellBad cterm=underline
hi SpellCap cterm=underline
hi SpellLocal cterm=underline
hi SpellRare cterm=underline
hi Special cterm=NONE
hi String cterm=NONE
hi Todo cterm=bold
hi NormalMode ctermfg=137 ctermbg=234 cterm=reverse
hi InsertMode ctermfg=109 ctermbg=234 cterm=reverse
hi ReplaceMode ctermfg=107 ctermbg=234 cterm=reverse
hi VisualMode ctermfg=208 ctermbg=234 cterm=reverse
hi CommandMode ctermfg=175 ctermbg=234 cterm=reverse
hi Warnings ctermfg=208 ctermbg=234 cterm=reverse
endfunction
if exists('&termguicolors')
" If we want to use true colors, we must a color scheme which support true
" colors, for example, https://github.com/sickill/vim-monokai
set notermguicolors
endif
set background=dark
colorscheme desert
" Highlight trailing white spaces and leading tabs
if has('gui_running')
hi Warnings guifg=#ff0000 guibg=yellow
endif
call matchadd("Warnings", '\s\+$')
call matchadd("Warnings", '^\t\+')
" statusline settings
let g:currentmode={
\ 'n' : 'NORMAL ',
\ 'v' : 'VISUAL ',
\ 'V' : 'V·Line ',
\ "\<C-V>" : 'V·Block ',
\ 'i' : 'INSERT ',
\ 'R' : 'R ',
\ 'Rv' : 'V·Replace ',
\ 'c' : 'Command ',
\ 't' : 'TERMINAL'
\}
set statusline=
set statusline+=%1*
" Show current mode
set statusline+=\ %{toupper(g:currentmode[mode()])}
set statusline+=%{&spell?'[SPELL]':''}
set statusline+=%#WarningMsg#
set statusline+=%{&paste?'[PASTE]':''}
set statusline+=%2*
" File path, as typed or relative to current directory
set statusline+=\ %F
set statusline+=%{&modified?'\ [+]':''}
set statusline+=%{&readonly?'\ []':''}
" Truncate line here
set statusline+=%<
" Separation point between left and right aligned items.
set statusline+=%=
set statusline+=%{&filetype!=#''?&filetype.'\ ':'none\ '}
" Encoding & Fileformat
set statusline+=%#WarningMsg#
set statusline+=%{&fileencoding!='utf-8'?'['.&fileencoding.']':''}
set statusline+=%2*
set statusline+=%-7([%{&fileformat}]%)
" Warning about byte order
set statusline+=%#WarningMsg#
set statusline+=%{&bomb?'[BOM]':''}
set statusline+=%1*
" Location of cursor line
set statusline+=[%l/%L]
" Column number
set statusline+=\ col:%2c
" Warning about trailing spaces.
set statusline+=%#WarningMsg#
set statusline+=%{StatuslineTrailingSpaceWarning()}
set statusline+=%{StatuslineTabWarning()}
" Recalculate the trailing whitespace warning when idle, and after saving.
augroup check_trailing_space
autocmd!
autocmd CursorHold,BufWritePost * unlet! b:statusline_trailing_space_warning
\ | let &statusline=&statusline
augroup END
augroup check_mixed_tabs
autocmd!
autocmd CursorHold,BufWritePost * unlet! b:statusline_tab_warning
\ | let &statusline=&statusline
augroup END
" Find if trailing spaces exist.
function! StatuslineTrailingSpaceWarning()
if !exists('b:statusline_trailing_space_warning')
" If the file is unmodifiable, do not warn this.
if !&modifiable
let b:statusline_trailing_space_warning = ''
return b:statusline_trailing_space_warning
endif
let l:line_num = search('\s\+$', 'nw')
if l:line_num != 0
let b:statusline_trailing_space_warning = ' [' . l:line_num . ']' . 'trailing space'
else
let b:statusline_trailing_space_warning = ''
endif
endif
return b:statusline_trailing_space_warning
endfunction
" Find if they are mixed indentings.
function! StatuslineTabWarning()
if !exists('b:statusline_tab_warning')
" If the file is unmodifiable, do not warn this.
if !&modifiable
let b:statusline_trailing_space_warning = ''
return b:statusline_trailing_space_warning
endif
let has_leading_tabs = search('^\t\+', 'nw') != 0
let has_leading_spaces = search('^ \+', 'nw') != 0
if has_leading_tabs && has_leading_spaces
let b:statusline_tab_warning = ' [mixed-indenting]'
elseif has_leading_tabs
let b:statusline_tab_warning = ' [tabbed-indenting]'
else
let b:statusline_tab_warning = ''
endif
endif
return b:statusline_tab_warning
endfunction
"}
"{ Some good references
" 1. https://gist.github.com/suderman/1243665
" 2. https://gist.github.com/autrimpo/f40e4eda233977dd3a619c6083d9bebd
" 3. https://gist.github.com/romainl/379904f91fa40533175dfaec4c833f2f
"}