-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvimrc
More file actions
310 lines (257 loc) · 9.6 KB
/
Copy pathvimrc
File metadata and controls
310 lines (257 loc) · 9.6 KB
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
" Functions {{{
function! Autosave(enabled) " {{{
augroup Autosave | au! * <buffer>
if a:enabled
setlocal autowrite
autocmd InsertLeave,CursorHold <buffer> update
endif
augroup end
endfunction " }}}
function! Mkdir(path) " {{{
let l:path = expand(a:path)
if !filereadable(l:path) && filewritable(l:path) != 1
try
call mkdir(l:path, 'p')
return 1
catch /E739/ | endtry
endif
return 0
endfunction " }}}
function! Grep(local, open, ...) " {{{
let search = get(a:000, len(a:000)-1, '')
let @/ = search
silent execute (a:local ? 'l' : '').'grep! '.join(a:000, ' ')
if a:open
execute (a:local ? 'l' : 'c').'open'
end
endfunction " }}}
function! NormFile(path) " {{{
let normalized = substitute(a:path, '[\\/]\+', g:slash, 'g')
let normalized = substitute(a:path, ',', '\\,', 'g')
return expandcmd(normalized)
endfunction " }}}
function! NormPath(path, ...) " {{{
let useslash = get(a:, 1, v:true)
let expanded = NormFile(a:path)
if useslash && expanded[strlen(expanded)-1] != g:slash
let expanded .= g:slash
elseif !useslash && expanded[strlen(expanded)-1] == g:slash
let expanded = strpart(expanded, 0, strlen(expanded)-1)
endif
return expanded
endfunction " }}}
function! s:GenerateCAbbrev(orig, complStart, new) " {{{
let len = len(a:orig) | if a:complStart > len | let a:complStart = len | endif
while len >= a:complStart
let s = strpart(a:orig, 0, len) | let len = len - 1
execute "cabbrev ".s." <C-R>=(getcmdtype()==':' && getcmdpos()==1 ? '".a:new."' : '".s."')<CR>"
endwhile
endfunction " }}}
function! s:IsEmptyFile() " {{{
return !(@%!='' || filereadable(@%)!=0 || line('$')!=1 || col('$')!=1)
endfunction " }}}
function! s:TrySourceFile(path, backup) " {{{
let l:path = filereadable(a:path) ? a:path : filereadable(a:backup) ? a:backup : ''
if l:path != '' | silent execute 'source '.l:path | endif
return escape(l:path, '\')
endfunction " }}}
" }}}
" Meta Config {{{
" Source vimrc.leader before performing additional configuration.
let g:vimrc = NormFile(stdpath('config').'/vimrc')
let g:vimrc_leader = s:TrySourceFile(g:vimrc.'.leader', g:vimrc.'.before')
" Update packpath
if exists('&packpath')
if match(&packpath, substitute(stdpath('config'), '[\\/]', '[\\\\/]', 'g')) == -1
let &packpath .= ','.stdpath('config')
endif
endif
" }}}
" Preferences and Settings {{{
" Application settings
syntax on
filetype plugin indent on
set title
set mouse=a
set scrolloff=2 sidescrolloff=1
set splitbelow splitright
set switchbuf=usetab
set updatetime=500
set sessionoptions=curdir,folds,help,tabpages,winsize,terminal,globals
set shada+="%"
if exists('&termguicolors')
if !has('gui_running') && &term =~ '^\%(screen\|tmux\)'
let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum"
let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"
endif
set termguicolors
endif
" Command bar
set completeopt=menuone,preview,noinsert,noselect,fuzzy
set gdefault ignorecase infercase smartcase
set wildmenu wildoptions=fuzzy,pum wildmode=list:lastused:full
set suffixes=~,.bak,.swp,.info,.aux,.log,.dvi,.bbl,.blg,.brf,.cb,.ind,.idx,.ilg,.inx,.out,.toc,.o,.class
set wildignore+=**/.git/**,**/.jj/**,**/tags/**,**/build/**,**/bin/**,**/dist/**
set wildignore+=*~,*.bak,*.aux,*.cache,*.dll,*.min,*.min.*,*.pdb,*.swp,*.tar,*.tar.*
set wildignorecase
if executable('rg')
set grepprg=rg\ --vimgrep\ --no-heading\ --smart-case
set grepformat=%f:%l:%c:%m,%f:%l:%m
endif
" Text options
set breakindent smartindent nowrap
set conceallevel=2
set cursorline
set tabstop=2 shiftwidth=0 softtabstop=-1
set number
set listchars=tab:»\ ,extends:›,precedes:‹,nbsp:·,trail:·
let &thesaurus = NormFile(stdpath('data').'/moby-thesaurus/words.txt')
" GUI settings
if exists('&guifont')
set guifont=Atkinson_Hyperlegible_Mono,Symbols_Nerd_Font:h13:#h-none
endif
if exists("g:vscode")
" VSCode Neovim is a common ShaDa issue culprit, use VSCode features instead.
set shada=""
endif
" }}}
" Keybindings and Commands {{{
" Sort via :sort /.*\%17v/
noremap ; :
noremap : ;
noremap <silent> <c-w>t <cmd>tabnew<cr>
noremap <silent> <c-h> <c-w>h
noremap <silent> <c-j> <c-w>j
noremap <silent> <c-k> <c-w>k
noremap <silent> <c-l> <c-w>l
noremap <silent> <leader>/ <cmd>nohlsearch<cr>
noremap <silent> <leader>c, <cmd>cd ..<cr><cmd>echo ':cd '.getcwd()<cr>
noremap <silent> <leader>cd <cmd>execute 'cd '.expand('%:p:h')<cr><cmd>echo ':cd '.getcwd()<cr>
noremap <silent> <leader>rg <cmd>Grep <cword><cr>
noremap <silent> <leader>va <cmd>execute 'e '.g:vimrc_custom<cr>
noremap <silent> <leader>vb <cmd>execute 'e '.g:vimrc_leader<cr>
noremap <silent> <leader>vp <cmd>execute 'e '.NormFile(stdpath('config').'/lua/plugins/init.lua')<cr>
noremap <silent> <leader>vr <cmd>execute 'e '.g:vimrc<cr>
noremap <silent> <leader>vi <cmd>execute 'e '.NormFile(stdpath('config').'/init.lua')<cr>
noremap <silent> <leader>vv <cmd>source $MYVIMRC<cr>
noremap <silent> ]w <cmd>setlocal wrap!<cr><cmd>setlocal wrap?<cr>
noremap <silent> ]W <cmd>set wrap!<cr><cmd>setlocal wrap?<cr>
noremap <silent> [w <cmd>setlocal list!<cr><cmd>setlocal list?<cr>
noremap <silent> [W <cmd>set list!<cr><cmd>setlocal list?<cr>
noremap [Q <cmd>colder<cr>
noremap ]Q <cmd>cnewer<cr>
noremap [L <cmd>lolder<cr>
noremap ]L <cmd>lnewer<cr>
noremap <plug>JoinUp ddpkJ<cmd>silent! call repeat#set("\<plug>JoinUp", 1)<cr>
noremap <silent> <leader>j <plug>JoinUp
nmap <silent> <leader>J <leader>j
noremap Q <c-q>
noremap <silent> gV `[v`]
noremap <silent> g. g;
inoremap <silent> <C-Backspace> <C-W>
inoremap <silent> <D-Backspace> <C-U>
inoremap <silent><expr> <tab> pumvisible() ? "\<C-N>" : "\<tab>"
inoremap <silent><expr> <s-tab> pumvisible() ? "\<C-P>" : "\<s-tab>"
inoremap <expr> <cr> pumvisible() ? "\<C-Y>" : "\<C-G>u\<cr>"
" System (Ctrl- / Cmd-) commands
noremap <silent> <leader>a <c-c>ggVG
if has('clipboard')
nnoremap ygf <cmd>execute 'let @'.v:register.'="'.expand('%:p').'"'<cr>
noremap <leader>v "+gp
noremap <leader>V "+gP
noremap <leader>x "+x
noremap <leader>X "+X
noremap <leader>y "+y
noremap <leader>Y "+Y
nmap <leader>ygf "+ygf
endif
tnoremap <c-n> <c-\><c-n>
tnoremap <esc><esc> <c-\><c-n>
tnoremap <c-w> <c-\><c-n><c-w>
" Commands
command! -nargs=0 Autosave call Autosave(1)
command! -nargs=0 NoAutosave call Autosave(0)
command! -nargs=+ Grep call Grep(0, 0, <f-args>)
command! -nargs=+ OGrep call Grep(0, 1, <f-args>)
command! -nargs=+ LGrep call Grep(1, 0, <f-args>)
command! -nargs=+ OLGrep call Grep(1, 1, <f-args>)
call s:GenerateCAbbrev('grep', 2, 'Grep' )
call s:GenerateCAbbrev('ogrep', 2, 'OGrep' )
call s:GenerateCAbbrev('lgrep', 2, 'LGrep')
call s:GenerateCAbbrev('olgrep', 3, 'OLGrep')
call s:GenerateCAbbrev('rg', 2, 'Grep' )
" Lua CAbbrevs
call s:GenerateCAbbrev('restart', 4, 'Restart' )
" }}}
" Auto Commands {{{
augroup RememberCursor | autocmd!
autocmd BufReadPost * if &filetype!='gitcommit' && line("'\"")>0 && line("'\"")<=line('$') |
\ execute "normal! g`\"" | else | call setpos('.', [0, 1, 1, 0]) | endif
augroup end
augroup MkdirOnWrite | autocmd!
autocmd BufWritePre * silent call Mkdir('<afile>:p:h')
augroup end
augroup Filetypes | autocmd!
autocmd BufNew,BufReadPre *.xaml,*.targets,*.props setf xml
autocmd BufNew,BufReadPost *.c,*.h syn match QmkKcAux /_\{7}\|X\{7}\|__MIS__/ | hi! link QmkKcAux LineNr
autocmd FileType gitcommit setlocal tw=72 fo+=t cc=50,+0
augroup end
augroup HelpFiles | autocmd!
autocmd!
autocmd BufRead,BufWinEnter * if (&buftype == 'help') |
\ setlocal noequalalways nonumber norelativenumber scrolloff=0 sidescrolloff=0 |
\ if &columns > 160 | wincmd L | vert resize 84 | endif |
\ endif
augroup end
augroup TerminalAutoInsert | autocmd!
autocmd TermOpen,TermEnter * startinsert
autocmd BufEnter term://* startinsert
augroup end
augroup TerminalAutoClose | autocmd!
autocmd TermClose * if v:event.status == 0 | bdelete | endif
augroup end
augroup QuickExit | autocmd!
autocmd BufWinEnter * if (&buftype =~ 'help\|quickfix' || &previewwindow) | noremap <buffer> q <C-W>c | endif
augroup end
augroup Spelling | autocmd!
autocmd ColorScheme * hi clear SpellRare | hi clear SpellLocal
autocmd BufRead * if &l:modifiable == 0 | setlocal nospell | endif
augroup end
" }}}
" Backup and Undo {{{
let s:backup_dir = NormPath(stdpath('cache').'/backup', v:false)
if Mkdir(s:backup_dir)
set backup writebackup
" Double slash extends files to their full path to avoid collisions.
let &backupdir = s:backup_dir.'//,.'
endif
let s:swap_dir = NormPath(stdpath('cache').'/swap', v:false)
if Mkdir(s:swap_dir)
" Double slash extends files to their full path to avoid collisions.
let &directory = s:swap_dir.'//,.'
endif
if has('persistent_undo')
let s:undo_dir = NormPath(stdpath('data').'/undo', v:false)
if Mkdir(s:undo_dir)
set undofile
let &undodir = s:undo_dir
endif
endif
" }}}
" Diff Settings {{{
set diffopt=filler,internal,algorithm:histogram,indent-heuristic
augroup DiffLayout | autocmd!
autocmd VimEnter * if &diff | call s:SetDiffLayout() | endif
augroup end
function! s:SetDiffLayout()
augroup RememberCursor " Clear cursor jump command
autocmd!
augroup end
execute 'vertical resize '.((&columns * get(g:, 'diff_width', 50)) / 100)
wincmd l | call setpos('.', [0, 1, 1, 0])
set equalalways nohidden bufhidden=delete
noremap q :qa<cr>
endfunction
" }}}
let g:vimrc_custom = s:TrySourceFile(g:vimrc.'.custom', g:vimrc.'.after')
" vim: foldmethod=marker