From 7a98c89f22253177d9f5a0f83c9dbaa297eb54b0 Mon Sep 17 00:00:00 2001 From: Hsieh Chin Fan Date: Mon, 8 Jul 2024 23:24:22 +0800 Subject: Update --- vim/init/config.vim | 169 +++++++++++++++++++++++----------------------------- 1 file changed, 73 insertions(+), 96 deletions(-) (limited to 'vim/init/config.vim') diff --git a/vim/init/config.vim b/vim/init/config.vim index ec9f090..b34ed81 100644 --- a/vim/init/config.vim +++ b/vim/init/config.vim @@ -1,29 +1,40 @@ "====================================================================== -" " init-config.vim - 正常模式下的配置,在 init-basic.vim 后调用 -" -" Created by skywind on 2018/05/30 -" Last Modified: 2018/05/30 19:20:46 -" "====================================================================== -"---------------------------------------------------------------------- -" -"---------------------------------------------------------------------- -augroup LeavingBuffer! +" Unnamed Buffer ----------------{{{ +augroup DeleteUnnamedEmptBuffer! au BufLeave {} if getline(1, '$') == [''] | setlocal bufhidden=wipe | endif augroup END +" }}} +" 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 @@ -50,9 +61,8 @@ if has('nvim') == 0 && has('gui_running') == 0 endfor endif - "---------------------------------------------------------------------- -" 终端下功能键设置 +" 功能键终端码矫正 "---------------------------------------------------------------------- function! s:key_escape(name, code) if has('nvim') == 0 && has('gui_running') == 0 @@ -60,10 +70,6 @@ function! s:key_escape(name, code) endif endfunc - -"---------------------------------------------------------------------- -" 功能键终端码矫正 -"---------------------------------------------------------------------- call s:key_escape('', 'OP') call s:key_escape('', 'OQ') call s:key_escape('', 'OR') @@ -81,55 +87,23 @@ call s:key_escape('', '[21;2~') call s:key_escape('', '[23;2~') call s:key_escape('', '[24;2~') - -"---------------------------------------------------------------------- -" 防止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 - - -"---------------------------------------------------------------------- -" 配置微调 -"---------------------------------------------------------------------- - -" 打开文件时恢复上一次光标所在位置 -autocmd BufReadPost * - \ if line("'\"") > 1 && line("'\"") <= line("$") | - \ exe "normal! g`\"" | - \ endif - -" 定义一个 DiffOrig 命令用于查看文件改动 -if !exists(":DiffOrig") - command DiffOrig vert new | set bt=nofile | r ++edit # | 0d_ | diffthis - \ | wincmd p | diffthis -endif - - -"---------------------------------------------------------------------- -" 文件类型微调 +" }}} +" Filetype ----------------{{{ "---------------------------------------------------------------------- augroup InitFileTypesGroup - " 清除同组的历史 autocommand au! - " help page: open in a new tab + " Filetype for Vim ----------------{{{ + + " Help page autocmd BufEnter *.txt if &filetype == 'help' | wincmd T | endif - " shegang: Automatically apply filetype by shebang + " 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:]]\+$') let l:shebangMatch = #{ node: "javascript" } @@ -142,8 +116,31 @@ augroup InitFileTypesGroup endif endfunction autocmd BufReadPost * call ApplyShebang() + " }}} + " Markdown ----------------{{{ + au FileType markdown setlocal wrap + au FileType markdown set sw=2 ts=2 + " Fold by heading level + function! MarkdownLevel() + let hash_num = matchstr(getline(v:lnum), '^#\+') + let hash_num_at_top = matchstr(getline(v:lnum-1), '^#\+') + if empty(hash_num) + if empty(hash_num_at_top) + return "=" + else + return ">"..(len(hash_num_at_top)) + endif + else + return len(hash_num)-1 + endif + endfunction + au FileType markdown setlocal foldexpr=MarkdownLevel() + au FileType markdown setlocal foldmethod=expr + + " }}} + " HTML ----------------{{{ - " html: Quickly edit html tag class + " Usage: cl(ass) or id to edit html tag attribute function! s:ChangeAttr(pattern) let l:attr = matchstr(getline('.'), a:pattern.'="') if l:attr == '' @@ -160,29 +157,20 @@ augroup InitFileTypesGroup startinsert endif endfunction - " Edit class and id for javascript files autocmd FileType html,markdown nnoremap cl :call ChangeAttr("class") autocmd FileType html,markdown nnoremap id :call ChangeAttr("id") - " markdown - au FileType markdown setlocal wrap - au FileType markdown set sw=2 ts=2 - " Fold by heading level - function! MarkdownLevel() - let hash_num = matchstr(getline(v:lnum), '^#\+') - let hash_num_at_top = matchstr(getline(v:lnum-1), '^#\+') - if empty(hash_num) - if empty(hash_num_at_top) - return "=" - else - return ">"..(len(hash_num_at_top)) - endif - else - return len(hash_num)-1 - endif + " Reload preview server + autocmd BufWrite *.html,*.js,*.css call ReloadServer() + function ReloadServer() + silent !browser-sync reload &>/dev/null endfunction - au FileType markdown setlocal foldexpr=MarkdownLevel() - au FileType markdown setlocal foldmethod=expr + + " }}} + " Mail ----------------{{{ + autocmd BufRead /tmp/mutt-* set tw=72 + " }}} + " Password ----------------{{{ " Hide the first line of a file if editing password file " TODO a better way to determine a file is related to password-store, now use @@ -197,6 +185,8 @@ augroup InitFileTypesGroup setlocal foldtext=s:custom() norm! ggzfl endfunction + " }}} + " Beancount ----------------{{{ " Set filetype for beancount autocmd BufRead,BufNewFile *.bean call PrepareBean() @@ -206,21 +196,8 @@ augroup InitFileTypesGroup autocmd VimLeave * silent !killall fava endfunction - " Set filetype for index.html - autocmd BufWrite *.html,*.js,*.css call ReloadServer() - function ReloadServer() - silent !browser-sync reload &>/dev/null - endfunction - - " quickfix: hide line number - au FileType quickfix setlocal nonumber - - " 强制对某些扩展名的 filetype 进行纠正 - au BufNewFile,BufRead *.as setlocal filetype=actionscript - au BufNewFile,BufRead *.pro setlocal filetype=prolog - au BufNewFile,BufRead *.es setlocal filetype=erlang - au BufNewFile,BufRead *.asc setlocal filetype=asciidoc - au BufNewFile,BufRead *.vl setlocal filetype=verilog - au BufRead /tmp/mutt-* set tw=72 + " }}} augroup END + +" }}} -- cgit v1.2.3-70-g09d2