-
Notifications
You must be signed in to change notification settings - Fork 0
/
dot_vimrc
281 lines (260 loc) · 7.54 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
" fold this file with [[[ and ]]]
" vim:foldmethod=marker:foldmarker=[[[,]]]
" dependencies[[[1
" nodejs: coc.nvim, markdown-preview.nvim
" yarn: markdown-preview.nvim
" ]]]
" fix E474 caused by vim in nix-shell
" https://stackoverflow.com/q/18321538/14399237
" set encoding=utf-8
" default configs[[[1
" Get the defaults that most users want.
source $VIMRUNTIME/defaults.vim
" backup, undo [[[2
if has("vms")
set nobackup " do not keep a backup file, use versions instead
else
set backup " keep a backup file (restore to previous version)
if has('persistent_undo')
" set undodir=~/.vim/undo_dir " todo: create dir if notexit
set undofile " keep an undo file (undo changes after closing)
endif
endif
" ]]]
" hlsearch[[[2
if &t_Co > 2 || has("gui_running")
" Switch on highlighting the last used search pattern.
set hlsearch
endif
" ]]]
" autocmd group[[[2
" Put these in an autocmd group, so that we can delete them easily.
augroup vimrcEx
au!
" For all text files set 'textwidth' to 78 characters.
autocmd FileType text setlocal textwidth=78
augroup END
" ]]]
" matchit[[[2
" Add optional packages.
"
" The matchit plugin makes the % command work better, but it is not backwards
" compatible.
" The ! means the package won't be loaded right away but when plugins are
" loaded during initialization.
if has('syntax') && has('eval')
packadd! matchit
endif
" ]]]
" ]]]
" my configs[[[1
" number, clipboard[[[2
set clipboard^=unnamed,unnamedplus
set number relativenumber numberwidth=1
autocmd FileType help setlocal number relativenumber numberwidth=1
let g:netrw_bufsettings = 'number relativenumber numberwidth=1 noma nomod ro nobl'
"]]]
" indent, tab, case, whitespaces [[[2
" indent
set smartindent
set autoindent
" tab
" set smarttab
set tabstop=2 " The width of a TAB is set to 2.
set shiftwidth=2 " Indents will have a width of 2
" set softtabstop=2 " Sets the number of columns for a TAB
set expandtab " Expand TABs to spaces
" case insensitive
set ignorecase smartcase
" whitespaces
set listchars=eol:¬,tab:>␣,trail:~,extends:>,precedes:<,space:·
":set listchars=eol:¬,tab:>·,trail:~,extends:>,precedes:<,space:␣
set list
"]]]
" true color, background, mouse[[[2
" true color
if (has("termguicolors"))
set termguicolors
endif
if $TERM == "xterm-256color"
set t_Co=256
endif
" tmux color
set term=xterm-256color
if &term =~ '256color'
" Disable Background Color Erase (BCE) so that color schemes work
" properly within 256-color terminals
set t_ut=
endif
" mouse in tmux
set ttymouse=xterm2
"]]]
" cursor shape[[[2
" https://stackoverflow.com/a/70135079/14399237
let &t_SI.="\e[6 q" "SI = INSERT mode, 6 = solid line
let &t_SR.="\e[4 q" "SR = REPLACE mode, 4 = solid underscore
let &t_EI.="\e[2 q" "EI = NORMAL mode (ELSE), 2 = solid block
"]]]
" other[[[2
" filetype plugin
filetype plugin indent on
" switch buffers without saving
set hidden
" search all subdirectory of current directory
set path+=**
" vertical and fuzzy wildmenu
set wildoptions=fuzzy,pum
" auto wrap in vimdiff
au VimEnter * if &diff | execute 'windo set wrap' | endif
" ]]]
" ]]]
" keybindings, commands[[[1
" clear search highlight
nnoremap <esc><esc> :noh<return><esc>
" replace grep with rg
set grepprg=rg\ --vimgrep\ --smart-case\ --follow
" <Leader> to space
let mapleader = "\<space>"
" Cv: clean vim, used for fast macro replaying
command Cv w | wviminfo | !vim -c 'set nu rnu nuw=1' --clean -i ~/.viminfo %
" UP: upgrade all plugins and managers
command! UP PlugClean | PlugUpdate | PlugUpgrade | JetpackSync
" ]]]
" only load plugins after installing vim-jetpack
if !empty(glob('~/.vim/autoload/jetpack.vim'))
" plugins[[[1
call jetpack#begin()
Jetpack 'alker0/chezmoi.vim'
Jetpack 'iamcco/markdown-preview.nvim', { 'do': { -> mkdp#util#install() }, 'for': ['markdown', 'vim-jetpack']}
Jetpack 'itchyny/lightline.vim'
Jetpack 'preservim/vim-markdown', { 'for': 'markdown' }
Jetpack 'sainnhe/everforest'
call jetpack#end()
" ]]]
" configs[[[1
" dark background for tty, light for terminal[[[2
if $TERM == 'linux'
set background=dark
else
set background=light
endif
" ]]]
" everforest[[[2
let g:everforest_better_performance = 1
let g:everforest_background = 'soft'
let g:everforest_enable_italic = 1
" let g:everforest_transparent_background = 2 " transparent status line
let g:everforest_ui_contrast = 'high'
colorscheme everforest
" ]]]
" lightline[[[2
set laststatus=2
set noshowmode
let g:lightline = {
\ 'colorscheme': 'everforest',
\ }
" ]]]
" vim-markdown[[[2
let g:vim_markdown_toc_autofit = 1
let g:vim_markdown_frontmatter = 1
let g:vim_markdown_strikethrough = 1
let g:vim_markdown_conceal_code_blocks = 0
autocmd FileType markdown setlocal conceallevel=2 " syntax concealing
" ]]]
" gruvbox[[[2
" let g:gruvbox_italic=1
" set background=light
" colorscheme gruvbox
" ]]]
" ]]]
endif
" only load plugins after installing vim-plug
if !empty(glob('~/.vim/autoload/plug.vim'))
" load after start
function DelayLoading(id)
" delayed plugins[[[1
call plug#begin()
" no dependencies[[[2
Plug '907th/vim-auto-save'
Plug 'AndrewRadev/tagalong.vim'
Plug 'easymotion/vim-easymotion'
Plug 'godlygeek/tabular' " for vim-markdown
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim'
Plug 'junegunn/goyo.vim'
Plug 'junegunn/vim-peekaboo'
Plug 'lilydjwg/fcitx.vim'
Plug 'luochen1990/rainbow'
Plug 'machakann/vim-highlightedyank'
Plug 'simnalamburt/vim-mundo'
Plug 'tpope/vim-commentary'
Plug 'tpope/vim-sleuth'
Plug 'tpope/vim-surround'
" ]]]
" need dependencies[[[2
if executable('node')
Plug 'neoclide/coc.nvim', {'branch': 'release'}
endif
" ]]]
" profile[[[2
" Plug 'dstein64/vim-startuptime'
" Plug 'tweekmonster/startuptime.vim'
" ]]]
call plug#end()
" ]]]
" delayed plugin configs[[[1
" explicitly initialize plugins[[[2
call peekaboo#on()
execute 'Sleuth'
" ]]]
" rainbow[[[2
let g:rainbow_active = 1
" ]]]
" goyo callbacks[[[2
function! s:goyo_enter()
set number relativenumber
" cursor location
:file
nnoremap <esc><esc> <c-g>
" list without eol
set listchars=tab:>␣,trail:~,extends:>,precedes:<,space:·
" highlight! NonText guifg=#6c767f guibg=NONE gui=NONE
endfunction
function! s:goyo_leave()
set listchars=eol:¬,tab:>␣,trail:~,extends:>,precedes:<,space:·
endfunction
autocmd! User GoyoEnter nested call <SID>goyo_enter()
autocmd! User GoyoLeave nested call <SID>goyo_leave()
" ]]]
" coc.nvim keybindings[[[2
" Use tab for trigger completion with characters ahead and navigate.
" NOTE: Use command ':verbose imap <tab>' to make sure tab is not mapped by
" other plugin before putting this into your config.
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.
if has('nvim')
inoremap <silent><expr> <c-space> coc#refresh()
else
inoremap <silent><expr> <c-@> coc#refresh()
endif
" Make <CR> auto-select the first completion item and notify coc.nvim to
" format on enter, <cr> could be remapped by other vim plugin
inoremap <silent><expr> <cr> pumvisible() ? coc#_select_confirm()
\: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"
" ]]]
" ]]]
endfunction
if has('timers')
call timer_start(500, 'DelayLoading')
else
call DelayLoading('')
endif
endif