From 0f098771b18d6d6525fc771bd85c822ab89365f0 Mon Sep 17 00:00:00 2001 From: Hsieh Chin Fan Date: Thu, 7 Nov 2024 10:58:29 +0800 Subject: Update --- vim/init/config.vim | 244 +++++++++++++++++++++++++++------------------------- 1 file changed, 125 insertions(+), 119 deletions(-) (limited to 'vim/init') 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 @@ -11,116 +11,6 @@ augroup DeleteUnnamedEmptBuffer! au BufLeave {} if getline(1, '$') == [''] | setlocal bufhidden=wipe | endif augroup END -" }}} -" Small Terminal {{{ - -augroup TerminalSize - au! - function! LayoutForSmallTerminal(bound) - if &lines < a:bound || g:alacritty_extra_padding - silent! set laststatus=0 showtabline=0 signcolumn=0 nowrap scrolloff=1 - else - silent! set laststatus& showtabline=2 signcolumn& scrolloff& - endif - endfunc - autocmd VimEnter,VimResized * silent call LayoutForSmallTerminal(20) - autocmd VimLeave,VimSuspend * if g:alacritty_extra_padding | silent call ToggleWinPadding(100) | endif -augroup END - -" }}} -" Big File {{{ - -augroup BigFileDisable - autocmd! - autocmd BufReadPre,FileReadPre * if getfsize(expand("%")) > 512 * 1024 | setlocal eventignore=all | endif -augroup END -"}}} -" X11 {{{ - -" Change IM to US when exit to Normal mode -autocmd InsertLeave * :silent !fcitx-remote -c &>/dev/null || true - -" }}} -" TMUX {{{ - -" 有 tmux 何没有的功能键超时(毫秒) -if $TMUX != '' - set ttimeoutlen=30 -elseif &ttimeoutlen > 80 || &ttimeoutlen <= 0 - set ttimeoutlen=80 -endif - -" 防止tmux下vim的背景色显示异常 -" Refer: http://sunaku.github.io/vim-256color-bce.html -if &term =~ '256color' && $TMUX != '' - " disable Background Color Erase (BCE) so that color schemes - " render properly when inside 256-color tmux and GNU screen. - set t_ut= -endif - - -" Ref: https://gist.github.com/andersevenrud/015e61af2fd264371032763d4ed965b6 -" You might have to force true color when using regular vim inside tmux as the -" colorscheme can appear to be grayscale with 'termguicolors' option enabled. -if !has('gui_running') && &term =~ '^\%(screen\|tmux\)' - let &t_8f = "\[38;2;%lu;%lu;%lum" - let &t_8b = "\[48;2;%lu;%lu;%lum" -endif - -" }}} -" KeyCode {{{ - -"---------------------------------------------------------------------- -" 终端下允许 ALT,详见:http://www.skywind.me/blog/archives/2021 -" 记得设置 ttimeout (见 init-basic.vim) 和 ttimeoutlen (上面) -"---------------------------------------------------------------------- -if has('nvim') == 0 && has('gui_running') == 0 - function! s:metacode(key) - exec "set =\e".a:key - endfunc - " set 0-9 - for i in range(10) - call s:metacode(nr2char(char2nr('0') + i)) - endfor - " set a-z A-Z - for i in range(26) - call s:metacode(nr2char(char2nr('a') + i)) - call s:metacode(nr2char(char2nr('A') + i)) - endfor - for c in [',', '.', '/', ';', '{', '}'] - call s:metacode(c) - endfor - for c in ['?', ':', '-', '_', '+', '=', "'"] - call s:metacode(c) - endfor -endif - -"---------------------------------------------------------------------- -" 功能键终端码矫正 -"---------------------------------------------------------------------- -function! s:key_escape(name, code) - if has('nvim') == 0 && has('gui_running') == 0 - exec "set ".a:name."=\e".a:code - endif -endfunc - -call s:key_escape('', 'OP') -call s:key_escape('', 'OQ') -call s:key_escape('', 'OR') -call s:key_escape('', 'OS') -call s:key_escape('', '[1;2P') -call s:key_escape('', '[1;2Q') -call s:key_escape('', '[1;2R') -call s:key_escape('', '[1;2S') -call s:key_escape('', '[15;2~') -call s:key_escape('', '[17;2~') -call s:key_escape('', '[18;2~') -call s:key_escape('', '[19;2~') -call s:key_escape('', '[20;2~') -call s:key_escape('', '[21;2~') -call s:key_escape('', '[23;2~') -call s:key_escape('', '[24;2~') - " }}} " Filetype {{{ @@ -128,15 +18,6 @@ augroup InitFileTypes au! - " Filetype for Vim {{{ - - " Help page - autocmd BufEnter * if &filetype == 'help' | wincmd T | set buflisted nofoldenable | endif - - " quickfix: hide line number - autocmd FileType quickfix setlocal nonumber - - " }}} " Shebeng: Set filetype from shebeng {{{ function! s:ApplyShebang() let l:filetype = matchstr(getline(1), '^#!.*[ /]\zs[[:alnum:]]\+$') @@ -149,6 +30,18 @@ augroup InitFileTypes endif endfunc autocmd BufReadPost * call ApplyShebang() + " }}} + " Conf {{{ + autocmd FileType conf set foldmethod=marker + " }}} + " Vim {{{ + + " Help page + autocmd BufEnter * if &filetype == 'help' | wincmd T | set buflisted nofoldenable | endif + + " quickfix: hide line number + autocmd FileType quickfix setlocal nonumber + " }}} " Markdown {{{ @@ -341,6 +234,119 @@ augroup InitFileTypes " }}} augroup END +" }}} +" Small Terminal {{{ + +augroup TerminalSize + au! + function! LayoutForSmallTerminal(bound) + if &lines < a:bound || g:alacritty_extra_padding + silent! set laststatus=0 showtabline=0 signcolumn=0 nowrap scrolloff=1 + else + silent! set laststatus& showtabline=2 signcolumn& scrolloff& + endif + endfunc + autocmd VimEnter,VimResized * silent call LayoutForSmallTerminal(20) + autocmd VimLeave,VimSuspend * if g:alacritty_extra_padding | silent call ToggleWinPadding(100) | endif +augroup END + +" }}} +" Big File {{{ + +augroup BigFileDisable + autocmd! + autocmd BufReadPre,FileReadPre * if getfsize(expand("%")) > 512 * 1024 | setlocal eventignore=all | endif +augroup END +"}}} +" X11 {{{ + +" Change IM to US when exit to Normal mode +autocmd InsertLeave * :silent !fcitx-remote -c &>/dev/null || true + +" }}} +" TMUX {{{ + +" 有 tmux 何没有的功能键超时(毫秒) +if $TMUX != '' + set ttimeoutlen=30 +elseif &ttimeoutlen > 80 || &ttimeoutlen <= 0 + set ttimeoutlen=80 +endif + +" 防止tmux下vim的背景色显示异常 +" Refer: http://sunaku.github.io/vim-256color-bce.html +if &term =~ '256color' && $TMUX != '' + " disable Background Color Erase (BCE) so that color schemes + " render properly when inside 256-color tmux and GNU screen. + set t_ut= +endif + + +" Ref: https://gist.github.com/andersevenrud/015e61af2fd264371032763d4ed965b6 +" You might have to force true color when using regular vim inside tmux as the +" colorscheme can appear to be grayscale with 'termguicolors' option enabled. +if !has('gui_running') && &term =~ '^\%(screen\|tmux\)' + let &t_8f = "\[38;2;%lu;%lu;%lum" + let &t_8b = "\[48;2;%lu;%lu;%lum" +endif + +" }}} +" KeyCode {{{ + +"---------------------------------------------------------------------- +" 终端下允许 ALT,详见:http://www.skywind.me/blog/archives/2021 +" 记得设置 ttimeout (见 init-basic.vim) 和 ttimeoutlen (上面) +"---------------------------------------------------------------------- +if has('nvim') == 0 && has('gui_running') == 0 + function! s:metacode(key) + exec "set =\e".a:key + endfunc + " set 0-9 + for i in range(10) + call s:metacode(nr2char(char2nr('0') + i)) + endfor + " set a-z A-Z + for i in range(26) + call s:metacode(nr2char(char2nr('a') + i)) + call s:metacode(nr2char(char2nr('A') + i)) + endfor + for c in [',', '.', '/', ';', '{', '}'] + call s:metacode(c) + endfor + for c in ['?', ':', '-', '_', '+', '=', "'"] + call s:metacode(c) + endfor +endif + +"---------------------------------------------------------------------- +" 功能键终端码矫正 +"---------------------------------------------------------------------- +function! s:key_escape(name, code) + if has('nvim') == 0 && has('gui_running') == 0 + exec "set ".a:name."=\e".a:code + endif +endfunc + +call s:key_escape('', 'OP') +call s:key_escape('', 'OQ') +call s:key_escape('', 'OR') +call s:key_escape('', 'OS') +call s:key_escape('', '[1;2P') +call s:key_escape('', '[1;2Q') +call s:key_escape('', '[1;2R') +call s:key_escape('', '[1;2S') +call s:key_escape('', '[15;2~') +call s:key_escape('', '[17;2~') +call s:key_escape('', '[18;2~') +call s:key_escape('', '[19;2~') +call s:key_escape('', '[20;2~') +call s:key_escape('', '[21;2~') +call s:key_escape('', '[23;2~') +call s:key_escape('', '[24;2~') + +" }}} +" Others {{{ let g:ale_lint_on_save = 1 let g:ale_fix_on_save = 1 +" }}} -- cgit v1.2.3-70-g09d2