aboutsummaryrefslogtreecommitdiffhomepage
path: root/vim/init
diff options
context:
space:
mode:
Diffstat (limited to 'vim/init')
-rw-r--r--vim/init/config.vim244
1 files changed, 125 insertions, 119 deletions
diff --git a/vim/init/config.vim b/vim/init/config.vim
index 8be42b4..680a5fc 100644
--- a/vim/init/config.vim
+++ b/vim/init/config.vim
@@ -12,131 +12,12 @@ augroup DeleteUnnamedEmptBuffer!
12augroup END 12augroup END
13 13
14" }}} 14" }}}
15" Small Terminal {{{
16
17augroup TerminalSize
18 au!
19 function! LayoutForSmallTerminal(bound)
20 if &lines < a:bound || g:alacritty_extra_padding
21 silent! set laststatus=0 showtabline=0 signcolumn=0 nowrap scrolloff=1
22 else
23 silent! set laststatus& showtabline=2 signcolumn& scrolloff&
24 endif
25 endfunc
26 autocmd VimEnter,VimResized * silent call LayoutForSmallTerminal(20)
27 autocmd VimLeave,VimSuspend * if g:alacritty_extra_padding | silent call ToggleWinPadding(100) | endif
28augroup END
29
30" }}}
31" Big File {{{
32
33augroup BigFileDisable
34 autocmd!
35 autocmd BufReadPre,FileReadPre * if getfsize(expand("%")) > 512 * 1024 | setlocal eventignore=all | endif
36augroup END
37"}}}
38" X11 {{{
39
40" Change IM to US when exit to Normal mode
41autocmd InsertLeave * :silent !fcitx-remote -c &>/dev/null || true
42
43" }}}
44" TMUX {{{
45
46" 有 tmux 何没有的功能键超时(毫秒)
47if $TMUX != ''
48 set ttimeoutlen=30
49elseif &ttimeoutlen > 80 || &ttimeoutlen <= 0
50 set ttimeoutlen=80
51endif
52
53" 防止tmux下vim的背景色显示异常
54" Refer: http://sunaku.github.io/vim-256color-bce.html
55if &term =~ '256color' && $TMUX != ''
56 " disable Background Color Erase (BCE) so that color schemes
57 " render properly when inside 256-color tmux and GNU screen.
58 set t_ut=
59endif
60
61
62" Ref: https://gist.github.com/andersevenrud/015e61af2fd264371032763d4ed965b6
63" You might have to force true color when using regular vim inside tmux as the
64" colorscheme can appear to be grayscale with 'termguicolors' option enabled.
65if !has('gui_running') && &term =~ '^\%(screen\|tmux\)'
66 let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum"
67 let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"
68endif
69
70" }}}
71" KeyCode {{{
72
73"----------------------------------------------------------------------
74" 终端下允许 ALT,详见:http://www.skywind.me/blog/archives/2021
75" 记得设置 ttimeout (见 init-basic.vim) 和 ttimeoutlen (上面)
76"----------------------------------------------------------------------
77if has('nvim') == 0 && has('gui_running') == 0
78 function! s:metacode(key)
79 exec "set <M-".a:key.">=\e".a:key
80 endfunc
81 " set 0-9
82 for i in range(10)
83 call s:metacode(nr2char(char2nr('0') + i))
84 endfor
85 " set a-z A-Z
86 for i in range(26)
87 call s:metacode(nr2char(char2nr('a') + i))
88 call s:metacode(nr2char(char2nr('A') + i))
89 endfor
90 for c in [',', '.', '/', ';', '{', '}']
91 call s:metacode(c)
92 endfor
93 for c in ['?', ':', '-', '_', '+', '=', "'"]
94 call s:metacode(c)
95 endfor
96endif
97
98"----------------------------------------------------------------------
99" 功能键终端码矫正
100"----------------------------------------------------------------------
101function! s:key_escape(name, code)
102 if has('nvim') == 0 && has('gui_running') == 0
103 exec "set ".a:name."=\e".a:code
104 endif
105endfunc
106
107call s:key_escape('<F1>', 'OP')
108call s:key_escape('<F2>', 'OQ')
109call s:key_escape('<F3>', 'OR')
110call s:key_escape('<F4>', 'OS')
111call s:key_escape('<S-F1>', '[1;2P')
112call s:key_escape('<S-F2>', '[1;2Q')
113call s:key_escape('<S-F3>', '[1;2R')
114call s:key_escape('<S-F4>', '[1;2S')
115call s:key_escape('<S-F5>', '[15;2~')
116call s:key_escape('<S-F6>', '[17;2~')
117call s:key_escape('<S-F7>', '[18;2~')
118call s:key_escape('<S-F8>', '[19;2~')
119call s:key_escape('<S-F9>', '[20;2~')
120call s:key_escape('<S-F10>', '[21;2~')
121call s:key_escape('<S-F11>', '[23;2~')
122call s:key_escape('<S-F12>', '[24;2~')
123
124" }}}
125" Filetype {{{ 15" Filetype {{{
126 16
127augroup InitFileTypes 17augroup InitFileTypes
128 18
129 au! 19 au!
130 20
131 " Filetype for Vim {{{
132
133 " Help page
134 autocmd BufEnter * if &filetype == 'help' | wincmd T | set buflisted nofoldenable | endif
135
136 " quickfix: hide line number
137 autocmd FileType quickfix setlocal nonumber
138
139 " }}}
140 " Shebeng: Set filetype from shebeng {{{ 21 " Shebeng: Set filetype from shebeng {{{
141 function! s:ApplyShebang() 22 function! s:ApplyShebang()
142 let l:filetype = matchstr(getline(1), '^#!.*[ /]\zs[[:alnum:]]\+$') 23 let l:filetype = matchstr(getline(1), '^#!.*[ /]\zs[[:alnum:]]\+$')
@@ -150,6 +31,18 @@ augroup InitFileTypes
150 endfunc 31 endfunc
151 autocmd BufReadPost * call <SID>ApplyShebang() 32 autocmd BufReadPost * call <SID>ApplyShebang()
152 " }}} 33 " }}}
34 " Conf {{{
35 autocmd FileType conf set foldmethod=marker
36 " }}}
37 " Vim {{{
38
39 " Help page
40 autocmd BufEnter * if &filetype == 'help' | wincmd T | set buflisted nofoldenable | endif
41
42 " quickfix: hide line number
43 autocmd FileType quickfix setlocal nonumber
44
45 " }}}
153 " Markdown {{{ 46 " Markdown {{{
154 47
155 au FileType markdown call InitMarkdownFile() 48 au FileType markdown call InitMarkdownFile()
@@ -341,6 +234,119 @@ augroup InitFileTypes
341 " }}} 234 " }}}
342 235
343augroup END 236augroup END
237" }}}
238" Small Terminal {{{
239
240augroup TerminalSize
241 au!
242 function! LayoutForSmallTerminal(bound)
243 if &lines < a:bound || g:alacritty_extra_padding
244 silent! set laststatus=0 showtabline=0 signcolumn=0 nowrap scrolloff=1
245 else
246 silent! set laststatus& showtabline=2 signcolumn& scrolloff&
247 endif
248 endfunc
249 autocmd VimEnter,VimResized * silent call LayoutForSmallTerminal(20)
250 autocmd VimLeave,VimSuspend * if g:alacritty_extra_padding | silent call ToggleWinPadding(100) | endif
251augroup END
252
253" }}}
254" Big File {{{
255
256augroup BigFileDisable
257 autocmd!
258 autocmd BufReadPre,FileReadPre * if getfsize(expand("%")) > 512 * 1024 | setlocal eventignore=all | endif
259augroup END
344 260
261"}}}
262" X11 {{{
263
264" Change IM to US when exit to Normal mode
265autocmd InsertLeave * :silent !fcitx-remote -c &>/dev/null || true
266
267" }}}
268" TMUX {{{
269
270" 有 tmux 何没有的功能键超时(毫秒)
271if $TMUX != ''
272 set ttimeoutlen=30
273elseif &ttimeoutlen > 80 || &ttimeoutlen <= 0
274 set ttimeoutlen=80
275endif
276
277" 防止tmux下vim的背景色显示异常
278" Refer: http://sunaku.github.io/vim-256color-bce.html
279if &term =~ '256color' && $TMUX != ''
280 " disable Background Color Erase (BCE) so that color schemes
281 " render properly when inside 256-color tmux and GNU screen.
282 set t_ut=
283endif
284
285
286" Ref: https://gist.github.com/andersevenrud/015e61af2fd264371032763d4ed965b6
287" You might have to force true color when using regular vim inside tmux as the
288" colorscheme can appear to be grayscale with 'termguicolors' option enabled.
289if !has('gui_running') && &term =~ '^\%(screen\|tmux\)'
290 let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum"
291 let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"
292endif
293
294" }}}
295" KeyCode {{{
296
297"----------------------------------------------------------------------
298" 终端下允许 ALT,详见:http://www.skywind.me/blog/archives/2021
299" 记得设置 ttimeout (见 init-basic.vim) 和 ttimeoutlen (上面)
300"----------------------------------------------------------------------
301if has('nvim') == 0 && has('gui_running') == 0
302 function! s:metacode(key)
303 exec "set <M-".a:key.">=\e".a:key
304 endfunc
305 " set 0-9
306 for i in range(10)
307 call s:metacode(nr2char(char2nr('0') + i))
308 endfor
309 " set a-z A-Z
310 for i in range(26)
311 call s:metacode(nr2char(char2nr('a') + i))
312 call s:metacode(nr2char(char2nr('A') + i))
313 endfor
314 for c in [',', '.', '/', ';', '{', '}']
315 call s:metacode(c)
316 endfor
317 for c in ['?', ':', '-', '_', '+', '=', "'"]
318 call s:metacode(c)
319 endfor
320endif
321
322"----------------------------------------------------------------------
323" 功能键终端码矫正
324"----------------------------------------------------------------------
325function! s:key_escape(name, code)
326 if has('nvim') == 0 && has('gui_running') == 0
327 exec "set ".a:name."=\e".a:code
328 endif
329endfunc
330
331call s:key_escape('<F1>', 'OP')
332call s:key_escape('<F2>', 'OQ')
333call s:key_escape('<F3>', 'OR')
334call s:key_escape('<F4>', 'OS')
335call s:key_escape('<S-F1>', '[1;2P')
336call s:key_escape('<S-F2>', '[1;2Q')
337call s:key_escape('<S-F3>', '[1;2R')
338call s:key_escape('<S-F4>', '[1;2S')
339call s:key_escape('<S-F5>', '[15;2~')
340call s:key_escape('<S-F6>', '[17;2~')
341call s:key_escape('<S-F7>', '[18;2~')
342call s:key_escape('<S-F8>', '[19;2~')
343call s:key_escape('<S-F9>', '[20;2~')
344call s:key_escape('<S-F10>', '[21;2~')
345call s:key_escape('<S-F11>', '[23;2~')
346call s:key_escape('<S-F12>', '[24;2~')
347
348" }}}
349" Others {{{
345let g:ale_lint_on_save = 1 350let g:ale_lint_on_save = 1
346let g:ale_fix_on_save = 1 351let g:ale_fix_on_save = 1
352" }}}