-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.vim
298 lines (239 loc) · 9.3 KB
/
main.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
" (jump to the topic)
"
" OPTIONS
" PLUGIN_INSTALL
" UTILITIES
" PLUGIN_CONFIGURATION " THEME_CONFIGURATION
" KEY_MAPS
" OTHER_CONFIGS
let g:high_performence = v:false
let g:autocomplte_enable = v:true
let g:copilot_enable = v:true
" only in nvim (using which-key)
let g:key_prompt = v:false
" only used by neovim
let g:classic_vim_ui = v:true
let g:animation_enable = v:false
let g:swap_dict = [
\ ['v:false', '0', 'dark', 'false' ],
\ ['v:true' , '1', 'light', 'true']]
" convinient function to swap between two options
nmap <leader><leader>t :call utils#swapword()<CR>
"""""" PLUGIN_INSTALL """"""
let g:dotvimdir = expand(g:dotfiledir . 'config/vim/')
let g:plugin_dir = expand(g:vim_dir . 'plugged/')
let g:theme_config_path = expand(g:vim_dir . ".config.vim")
call plug#begin(g:plugin_dir)
" https://github.com/junegunn/vim-plug/wiki/tips
function! Cond(cond, ...)
let opts = get(a:000, 0, {})
return a:cond ? opts : extend(opts, { 'on': [], 'for': [] })
endfunction
let g:animation_enable = g:high_performence ? v:false : g:animation_enable
if !g:high_performence
Plug 'aditya-azad/candle-grey'
Plug 't184256/vim-boring'
Plug 'tek256/simple-dark'
Plug 'sainnhe/everforest'
Plug 'bluz71/vim-moonfly-colors', { 'as': 'moonfly' }
Plug 'cocopon/iceberg.vim'
Plug 'catppuccin/nvim', Cond( has('nvim-0.8.2') \|\| g:vim_v >= 900 , { 'as': 'catppuccin' })
Plug 'NLKNguyen/papercolor-theme'
Plug 'EdenEast/nightfox.nvim', Cond(has('nvim-0.5'))
Plug 'projekt0n/github-nvim-theme', Cond(has('nvim-0.5'), { 'tag': 'v0.0.7' })
Plug 'folke/tokyonight.nvim', Cond(g:vim_type == 'nvim', { 'branch': 'main' })
Plug 'andymass/vim-matchup'
endif
Plug 'Donaldttt/fuzzyy'
Plug 'tpope/vim-repeat'
Plug 'tpope/vim-fugitive'
Plug 'tpope/vim-surround'
" Plug 'lervag/vimtex'
Plug 'github/copilot.vim', Cond(( g:vim_type == 'nvim' \|\| g:vim_v >= 900 )
\ && g:copilot_enable && executable('node'))
Plug 'nanotee/zoxide.vim', Cond(executable('zoxide'))
Plug 'godlygeek/tabular'
Plug 'preservim/vim-markdown'
Plug 'dstein64/vim-startuptime', Cond(!g:high_performence)
Plug 'simeji/winresizer', Cond(!g:high_performence)
" Plug 'rust-lang/rust.vim', { 'for': ['rust'] }
Plug 'rhysd/conflict-marker.vim'
Plug 'jiangmiao/auto-pairs'
" Plug 'mg979/vim-visual-multi'
Plug 'RRethy/vim-illuminate', Cond(!g:high_performence)
" Plug 'ludovicchabant/vim-gutentags'
" Plug 'ctrlpvim/ctrlp.vim'
"" ESSENTIAL_PLUGINS ""
Plug 'mhinz/vim-startify'
Plug 'christoomey/vim-tmux-navigator'
" Comment stuff out
Plug 'tpope/vim-commentary'
Plug 'vim-scripts/restore_view.vim'
" vim only plugins
Plug 'scrooloose/nerdtree', Cond(g:vim_type == 'vim' \|\| !has('nvim-0.8'), { 'on' : ['NERDTreeToggle', 'NERDTreeFind'] })
Plug 'tiagofumo/vim-nerdtree-syntax-highlight', Cond(g:vim_type == 'vim' && !g:high_performence)
Plug 'neoclide/coc.nvim', Cond(g:autocomplte_enable && executable('node'), {'branch': 'release'})
" only work with vim
if g:vim_type == 'vim'
if executable('ctags')
Plug 'preservim/tagbar'
else
Plug 'liuchengxu/vista.vim', Cond(!g:high_performence)
endif
Plug 'airblade/vim-rooter'
" Plug 'justinmk/vim-sneak'
Plug 'airblade/vim-gitgutter'
Plug 'chriskempson/base16-vim'
" Plug 'Yggdroot/indentLine'
" Plug 'Donaldttt/fzf-color-preview', Cond(g:vim_v >= 800, { 'on': ['ColorsPreview', 'AirlinePreview'] })
Plug 'markonm/traces.vim'
" Plug 'voldikss/vim-floaterm', Cond(has('terminal') && g:vim_type == 'vim')
set encoding=UTF-8
" Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
" Plug 'junegunn/fzf.vim'
" Plug 'antoinemadec/coc-fzf', Cond(g:os != 'Windows', {'on': ['CocFzfList']})
Plug 'Donaldttt/vim-bufferline'
Plug 'Donaldttt/vim-global-statusline', { 'branch': 'vim9' }
" Plug 'vim-airline/vim-airline'
" Plug 'vim-airline/vim-airline-themes'
Plug 'ryanoasis/vim-devicons'
" Plug 'wfxr/minimap.vim', Cond(executable('code-minimap'), {'on' : ['MinimapToggle']})
endif
if g:vim_type == 'nvim'
Plug 'RRethy/nvim-base16'
if has('nvim-0.5')
" Plug 'hkupty/iron.nvim'
" Plug 'metakirby5/codi.vim'
Plug 'lukas-reineke/indent-blankline.nvim', Cond(!g:animation_enable)
Plug 'echasnovski/mini.indentscope', Cond(g:animation_enable)
Plug 'echasnovski/mini.animate', Cond(g:animation_enable)
Plug 'nvim-lualine/lualine.nvim'
Plug 'petertriho/nvim-scrollbar', Cond(g:animation_enable)
Plug 'folke/which-key.nvim', Cond(!g:high_performence && g:key_prompt)
Plug 'ahmedkhalf/project.nvim'
endif
if has('nvim-0.7')
Plug 'stevearc/aerial.nvim'
Plug 'nvim-treesitter/nvim-treesitter', Cond(executable('make'), {'do': ':TSUpdate'})
" for telescope
Plug 'nvim-lua/plenary.nvim'
Plug 'nvim-telescope/telescope.nvim', Cond(g:vim_type == 'nvim', { 'branch': '0.1.x' })
" c plugin for telescope to make it faster
Plug 'nvim-telescope/telescope-fzf-native.nvim', Cond(executable('make'), { 'do': 'make' })
" comment out this plugin if the machine doesn't have required
" font install
Plug 'nvim-tree/nvim-web-devicons'
" Plug 'akinsho/toggleterm.nvim', Cond(g:vim_type == 'nvim', {'tag' : '*'})
Plug 'ggandor/leap.nvim'
endif
if has('nvim-0.8')
Plug 'nvim-tree/nvim-tree.lua'
Plug 'lewis6991/gitsigns.nvim'
Plug 'rcarriga/nvim-notify', Cond(!g:high_performence && !g:classic_vim_ui)
Plug 'folke/noice.nvim', Cond(!g:high_performence && !g:classic_vim_ui)
Plug 'MunifTanjim/nui.nvim', Cond(!g:high_performence && !g:classic_vim_ui)
endif
" nvim theme
if has('nvim-0.9')
Plug 'rebelot/kanagawa.nvim'
Plug 'rose-pine/neovim', { 'as': 'rose-pine' }
endif
endif
" custom plugin
Plug g:dotvimdir
call plug#end()
augroup InitConfig
" Automatically install missing plugins at startup
autocmd VimEnter *
\ if len(filter(values(g:plugs), '!isdirectory(v:val.dir)'))
\| PlugInstall --sync | q
\| endif
augroup end
"""""" UTILITIES """"""
" a list of funcref that will be initilized late
let g:post_init_func = []
function RegisterLateInit(func, delay, ...)
let Funcref = type(a:func) == 10 ? func : function(a:func)
let obj = [Funcref, a:delay, a:000]
call add(g:post_init_func, obj)
endfunction
function s:executeLateInit()
function s:lateInitHelper(...)
for obj in g:post_init_func
let Funcref = obj[0]
let delay = obj[1]
let args = obj[2]
if delay == 0
if len(args) > 0
call Funcref(args)
else
call Funcref()
endif
else
call timer_start(delay, Funcref)
endif
endfor
endfunction
autocmd VimEnter * call s:lateInitHelper()
endfunction
" source all vim specific config eg. gui vim
for f in split(glob(g:dotvimdir.'/configs/*-config.vim'), '\n')
exe 'source' f
endfor
" source all vim plugin config
for f in split(glob(g:dotvimdir.'/vim-plugin-settings/*.config.vim'), '\n')
exe 'source' f
endfor
" source all vim9 plugin configs
if g:vim_v >= 900
for f in split(glob(g:dotvimdir.'/vim-plugin-settings/vim9/*.config.vim'), '\n')
exe 'source' f
endfor
endif
" source lua plugins if in neovim
if has('nvim')
lua require('lua-plugin-settings')
endif
" source lua library
"""""" THEME_CONFIGURATION """"""
nmap <Leader>db :call utils#showHiGroup()<CR>
""" THEME_OPTIONS """
call theme#Init()
"""""" KEY_MAPS """"""
" (This doesn't include plugin specific mapping.
" For them check plugin Preferences)
nnoremap <leader>ws :call utils#trimwhitespace()<CR>
" Toggle dark/light theme
noremap <silent> <leader>cbg :call theme#toggleBg()<CR>
" Toggle transparent background
noremap <silent> <leader>ctb :call theme#toggleTransparent()<CR>
" Buffer navigation
nnoremap <silent> <space>q :bprevious<CR>
nnoremap <silent> <space>e :bnext<CR>
" leader s change all occurence
nnoremap <Leader>s :%s/\<<C-r><C-w>\>/<C-r><C-w>
noremap <leader>h :noh<CR> " turn off highlight
" disable two easily mispressed yet useless key
nnoremap q: <nop>
nnoremap Q <nop>
" we often press shift key by mistake
command WQ wq
command Wq wq
command W w
command Q q
" leader num change tab
" only for vim or nvim without lualine
if (g:vim_type == 'vim' || !has('nvim-0.5')) && utils#hasplug('vim-bufferline')
for i in range(1, 9)
execute "nnoremap <silent> <nowait> <leader>" . i .
\ " :call bufferline#jump(" . i . ")<CR>"
endfor
for i in range(10, 20)
execute "nnoremap <silent> <nowait> <leader><leader>" . i .
\ " :call bufferline#jump(" . i . ")<CR>"
endfor
end
" split window comform with other window management shortcuts
nnoremap <silent> <C-w>% :vsplit<CR>
nnoremap <silent> <C-w>" :split<CR>
call s:executeLateInit()