diff options
| author | Hsieh Chin Fan <pham@topo.tw> | 2024-08-05 18:41:51 +0800 |
|---|---|---|
| committer | Hsieh Chin Fan <pham@topo.tw> | 2024-08-05 18:41:51 +0800 |
| commit | b57c461014f585655d897abf0e0ac982807396b7 (patch) | |
| tree | d3b10761cb75d52ff41b0822bc646c9d1c08d935 /vim/init | |
| parent | cc96870ff94afba7b0f2dc18f0209611ff7201f7 (diff) | |
Update
Diffstat (limited to 'vim/init')
| -rw-r--r-- | vim/init/basic.vim | 35 | ||||
| -rw-r--r-- | vim/init/config.vim | 24 | ||||
| -rw-r--r-- | vim/init/keymaps.vim | 71 |
3 files changed, 75 insertions, 55 deletions
diff --git a/vim/init/basic.vim b/vim/init/basic.vim index c4dfa61..fd20476 100644 --- a/vim/init/basic.vim +++ b/vim/init/basic.vim | |||
| @@ -4,6 +4,17 @@ | |||
| 4 | " Used for general usecases. No keymap and personal preference | 4 | " Used for general usecases. No keymap and personal preference |
| 5 | "====================================================================== | 5 | "====================================================================== |
| 6 | 6 | ||
| 7 | " Initial for terminal emulator {{{ | ||
| 8 | augroup Enter | ||
| 9 | au! | ||
| 10 | function! SetEmulaterBackground() | ||
| 11 | redir => output | hi Normal | redir END | ||
| 12 | let bg_color = matchstr(output, 'guibg=\zs[^\s]\+\ze') | ||
| 13 | exe "!alacritty msg config 'colors.primary.background=\"\\"..bg_color.."\"'" | ||
| 14 | endfunc | ||
| 15 | autocmd VimEnter * call SetEmulaterBackground() | ||
| 16 | augroup END | ||
| 17 | "}}} | ||
| 7 | " For Vimscript {{{ | 18 | " For Vimscript {{{ |
| 8 | 19 | ||
| 9 | " Usage: type --- for foldmark | 20 | " Usage: type --- for foldmark |
| @@ -27,7 +38,9 @@ augroup tabinfo | |||
| 27 | endfunc | 38 | endfunc |
| 28 | function! RemoveBufFromTabs() | 39 | function! RemoveBufFromTabs() |
| 29 | for tab in gettabinfo() | 40 | for tab in gettabinfo() |
| 30 | call filter(tab.variables.bufs, "v:val != "..expand('<abuf>')) | 41 | if has_key(t:, 'bufs') |
| 42 | call filter(tab.variables.bufs, "v:val != "..expand('<abuf>')) | ||
| 43 | endif | ||
| 31 | endfor | 44 | endfor |
| 32 | endfunc | 45 | endfunc |
| 33 | 46 | ||
| @@ -78,7 +91,7 @@ set showtabline=2 | |||
| 78 | set number relativenumber | 91 | set number relativenumber |
| 79 | 92 | ||
| 80 | " Cursor | 93 | " Cursor |
| 81 | set cursorline | 94 | " set cursorline |
| 82 | set guicursor=n-v-c-sm:block,i-ci-ve:ver25,r-cr-o:hor20 | 95 | set guicursor=n-v-c-sm:block,i-ci-ve:ver25,r-cr-o:hor20 |
| 83 | set matchtime=2 | 96 | set matchtime=2 |
| 84 | 97 | ||
| @@ -95,7 +108,7 @@ set errorformat+=[%f:%l]\ ->\ %m,[%f:%l]:%m | |||
| 95 | set splitright | 108 | set splitright |
| 96 | 109 | ||
| 97 | " Set signcolumn | 110 | " Set signcolumn |
| 98 | set signcolumn=auto:3 | 111 | set signcolumn=yes:3 |
| 99 | " Custom sign from help page :h sign | 112 | " Custom sign from help page :h sign |
| 100 | sign define piet text=>> texthl=Search | 113 | sign define piet text=>> texthl=Search |
| 101 | 114 | ||
| @@ -107,7 +120,7 @@ sign define piet text=>> texthl=Search | |||
| 107 | " Don't wrap line when typing CJK characters | 120 | " Don't wrap line when typing CJK characters |
| 108 | " Don't add spaces for CJK | 121 | " Don't add spaces for CJK |
| 109 | " Don't add comment at next line | 122 | " Don't add comment at next line |
| 110 | autocmd Filetype * set fo+=mB fo-=cro | 123 | autocmd Filetype * set formatoptions+=mB formatoptions-=cro |
| 111 | 124 | ||
| 112 | set shiftwidth=2 | 125 | set shiftwidth=2 |
| 113 | set autoindent smartindent | 126 | set autoindent smartindent |
| @@ -140,10 +153,9 @@ set suffixesadd=.md " Enable reference markdown file without | |||
| 140 | " }}} | 153 | " }}} |
| 141 | " SEARCH {{{ | 154 | " SEARCH {{{ |
| 142 | 155 | ||
| 143 | set ignorecase " Search case without case sensation | 156 | set ignorecase smartcase " Search case without case sensation |
| 144 | set smartcase | 157 | set hlsearch " Highlight all matched texts |
| 145 | set hlsearch " Highlight all matched texts | 158 | set incsearch " Show matched strings when typing |
| 146 | set incsearch " Show matched strings when typing | ||
| 147 | 159 | ||
| 148 | " }}} | 160 | " }}} |
| 149 | " BUFFERS {{{ | 161 | " BUFFERS {{{ |
| @@ -209,16 +221,17 @@ set writebackup | |||
| 209 | " HIGHLIGHT {{{ | 221 | " HIGHLIGHT {{{ |
| 210 | 222 | ||
| 211 | syntax enable | 223 | syntax enable |
| 212 | set conceallevel=1 | 224 | set syntax=filetype |
| 225 | set conceallevel=2 | ||
| 213 | 226 | ||
| 214 | " Defualt highlight for matched parenthesis is so weird in many colorscheme | 227 | " Defualt highlight for matched parenthesis is so weird in many colorscheme |
| 215 | " Why the background color is lighter than my caret !? | 228 | " Why the background color is lighter than my caret !? |
| 216 | " highlight MatchParen ctermfg=NONE ctermbg=darkgrey cterm=NONE | 229 | " highlight MatchParen ctermfg=NONE ctermbg=darkgrey cterm=NONE |
| 217 | highlight LuaParen ctermfg=NONE ctermbg=darkgrey cterm=NONE | 230 | hi LuaParen ctermfg=NONE ctermbg=darkgrey cterm=NONE |
| 218 | 231 | ||
| 219 | " Show trailing spaces | 232 | " Show trailing spaces |
| 220 | highlight ExtraWhitespace ctermbg=red guibg=red | ||
| 221 | match ExtraWhitespace /\s\+$/ | 233 | match ExtraWhitespace /\s\+$/ |
| 234 | hi ExtraWhitespace ctermbg=red guibg=red | ||
| 222 | 235 | ||
| 223 | " }}} | 236 | " }}} |
| 224 | " MISC {{{ | 237 | " MISC {{{ |
diff --git a/vim/init/config.vim b/vim/init/config.vim index 318bc58..3870ac4 100644 --- a/vim/init/config.vim +++ b/vim/init/config.vim | |||
| @@ -20,7 +20,7 @@ augroup TerminalSize | |||
| 20 | if &lines < a:bound || g:alacritty_extra_padding | 20 | if &lines < a:bound || g:alacritty_extra_padding |
| 21 | silent! set laststatus=0 showtabline=0 signcolumn=0 nowrap scrolloff=1 | 21 | silent! set laststatus=0 showtabline=0 signcolumn=0 nowrap scrolloff=1 |
| 22 | else | 22 | else |
| 23 | silent! set laststatus& showtabline& signcolumn& scrolloff& | 23 | silent! set laststatus& showtabline=2 signcolumn& scrolloff& |
| 24 | endif | 24 | endif |
| 25 | endfunc | 25 | endfunc |
| 26 | autocmd VimEnter,VimResized * silent call LayoutForSmallTerminal(20) | 26 | autocmd VimEnter,VimResized * silent call LayoutForSmallTerminal(20) |
| @@ -147,17 +147,23 @@ augroup InitFileTypes | |||
| 147 | 147 | ||
| 148 | augroup Config_Markdown | 148 | augroup Config_Markdown |
| 149 | au! | 149 | au! |
| 150 | au FileType markdown call InitMarkdown() | ||
| 151 | au FileType markdown let b:in_frontmatter = 0 | ||
| 152 | 150 | ||
| 153 | function! InitMarkdown() | 151 | au FileType markdown call InitMarkdownFile() |
| 152 | function! InitMarkdownFile() | ||
| 154 | setlocal wrap sw=2 ts=2 | 153 | setlocal wrap sw=2 ts=2 |
| 154 | |||
| 155 | let b:in_frontmatter = 0 | ||
| 155 | setlocal foldexpr=MarkdownLevel() foldmethod=expr | 156 | setlocal foldexpr=MarkdownLevel() foldmethod=expr |
| 156 | setlocal foldtext=MarkdownFoldTextHeading() | 157 | setlocal foldtext=MarkdownFoldTextHeading() |
| 157 | syn match Details '^<details>' conceal cchar=▶ | 158 | |
| 158 | syn match Summary '<summary>' conceal cchar= | 159 | call MarkdownHighlights() |
| 159 | syn match SummaryEnd '</summary>' conceal | 160 | endfunc |
| 160 | syn match DetailsEnd '^</details>' conceal cchar=E | 161 | |
| 162 | function MarkdownHighlights() | ||
| 163 | syn match MarkdownHtmlDetails '^<details>' conceal cchar=▶ | ||
| 164 | syn match MarkdownHtmlSummary '<summary>' conceal cchar= | ||
| 165 | syn match MarkdownHtmlSummaryEnd '</summary>' conceal | ||
| 166 | syn match MarkdownHtmlDetailsEnd '^</details>' conceal cchar=E | ||
| 161 | endfunc | 167 | endfunc |
| 162 | 168 | ||
| 163 | function! MarkdownLevel() | 169 | function! MarkdownLevel() |
| @@ -196,7 +202,7 @@ augroup InitFileTypes | |||
| 196 | let origin = split(MarkdownFoldText()[2:], ' ') | 202 | let origin = split(MarkdownFoldText()[2:], ' ') |
| 197 | let heading = substitute(join(origin[:-3], ' '), '\#', ' ', 'g') | 203 | let heading = substitute(join(origin[:-3], ' '), '\#', ' ', 'g') |
| 198 | let lines = join(origin[-2:], ' ')[1:-2] | 204 | let lines = join(origin[-2:], ' ')[1:-2] |
| 199 | let fills = repeat('.', 48 - len(heading) - len(lines)) | 205 | let fills = repeat('.', 48 - strwidth(heading) - len(lines)) |
| 200 | return heading.." "..fills.." "..lines | 206 | return heading.." "..fills.." "..lines |
| 201 | endfunc | 207 | endfunc |
| 202 | 208 | ||
diff --git a/vim/init/keymaps.vim b/vim/init/keymaps.vim index a423c20..e8cb61d 100644 --- a/vim/init/keymaps.vim +++ b/vim/init/keymaps.vim | |||
| @@ -3,7 +3,7 @@ | |||
| 3 | "====================================================================== | 3 | "====================================================================== |
| 4 | " vim: sw=2 ts=2 foldmethod=marker foldmarker={{{,}}} | 4 | " vim: sw=2 ts=2 foldmethod=marker foldmarker={{{,}}} |
| 5 | 5 | ||
| 6 | " COMMON_MAPPING {{{ | 6 | " COMMON {{{ |
| 7 | 7 | ||
| 8 | " Space for searching | 8 | " Space for searching |
| 9 | map <space> / | 9 | map <space> / |
| @@ -37,9 +37,7 @@ augroup vimrc_CRfix | |||
| 37 | augroup END | 37 | augroup END |
| 38 | 38 | ||
| 39 | " Spell | 39 | " Spell |
| 40 | nnoremap \s :set spell!<CR>:set spell?<CR> | 40 | nnoremap \sp :set spell!<CR>:set spell?<CR> |
| 41 | nnoremap <leader>ss ]s | ||
| 42 | nnoremap <leader>S [s | ||
| 43 | 41 | ||
| 44 | " Show full path by default | 42 | " Show full path by default |
| 45 | nnoremap <C-g> 1<C-g> | 43 | nnoremap <C-g> 1<C-g> |
| @@ -48,6 +46,8 @@ nnoremap <C-g> 1<C-g> | |||
| 48 | vnoremap Tz :!trans -t zh-TW -b<CR> | 46 | vnoremap Tz :!trans -t zh-TW -b<CR> |
| 49 | vnoremap Te :!trans -t en-US -b<CR> | 47 | vnoremap Te :!trans -t en-US -b<CR> |
| 50 | 48 | ||
| 49 | nnoremap q: : | ||
| 50 | |||
| 51 | " }}} | 51 | " }}} |
| 52 | " WORKING_DIR {{{ | 52 | " WORKING_DIR {{{ |
| 53 | 53 | ||
| @@ -158,6 +158,16 @@ inoremap <silent><M-9> <Esc>:tablast<CR> | |||
| 158 | " }}} | 158 | " }}} |
| 159 | 159 | ||
| 160 | " }}} | 160 | " }}} |
| 161 | " EDIT {{{ | ||
| 162 | |||
| 163 | " Move one line up and down | ||
| 164 | nnoremap <C-j> ddp | ||
| 165 | nnoremap <C-k> ddkP | ||
| 166 | |||
| 167 | " Clear current line | ||
| 168 | nnoremap S S<ESC> | ||
| 169 | |||
| 170 | " }}} | ||
| 161 | " REGISTER {{{ | 171 | " REGISTER {{{ |
| 162 | " Paste register 0 | 172 | " Paste register 0 |
| 163 | nnoremap <C-p> "0p | 173 | nnoremap <C-p> "0p |
| @@ -176,7 +186,7 @@ vnoremap Y "+y | |||
| 176 | function! DeleteMark(mark) | 186 | function! DeleteMark(mark) |
| 177 | let mark = nr2char(a:mark) | 187 | let mark = nr2char(a:mark) |
| 178 | echo mark | 188 | echo mark |
| 179 | if mark =~ '[a-Z]' | 189 | if mark =~ '\a' |
| 180 | execute "delmarks " . mark | 190 | execute "delmarks " . mark |
| 181 | endif | 191 | endif |
| 182 | endfunc | 192 | endfunc |
| @@ -259,7 +269,7 @@ function! ChangeUnfold(downward, count) | |||
| 259 | let foldend -= move | 269 | let foldend -= move |
| 260 | endif | 270 | endif |
| 261 | norm! zd | 271 | norm! zd |
| 262 | exe foldstart..","..foldend.."fold" | 272 | try | silent! exe foldstart..","..foldend.."fold" | endtry |
| 263 | 273 | ||
| 264 | " Get back to origin cursor position | 274 | " Get back to origin cursor position |
| 265 | norm! '' | 275 | norm! '' |
| @@ -268,16 +278,6 @@ nnoremap <expr> z> ":\<C-u>call ChangeUnfold(1,"..v:count..")\<CR>" | |||
| 268 | nnoremap <expr> z< ":\<C-u>call ChangeUnfold(0,"..v:count..")\<CR>" | 278 | nnoremap <expr> z< ":\<C-u>call ChangeUnfold(0,"..v:count..")\<CR>" |
| 269 | 279 | ||
| 270 | "}}} | 280 | "}}} |
| 271 | " EDIT {{{ | ||
| 272 | |||
| 273 | " Move one line up and down | ||
| 274 | nnoremap <C-j> ddp | ||
| 275 | nnoremap <C-k> ddkP | ||
| 276 | |||
| 277 | " Clear current line | ||
| 278 | nnoremap S S<ESC> | ||
| 279 | |||
| 280 | " }}} | ||
| 281 | " TERMINAL {{{ | 281 | " TERMINAL {{{ |
| 282 | 282 | ||
| 283 | " Use <leader>z to toggle | 283 | " Use <leader>z to toggle |
| @@ -285,13 +285,17 @@ let g:alacritty_extra_padding = 0 | |||
| 285 | function! ToggleWinPadding() | 285 | function! ToggleWinPadding() |
| 286 | if g:alacritty_extra_padding | 286 | if g:alacritty_extra_padding |
| 287 | !alacritty msg config --window-id $WINDOWID --reset | 287 | !alacritty msg config --window-id $WINDOWID --reset |
| 288 | call SetEmulaterBackground() | ||
| 288 | hi EndOfBuffer None | 289 | hi EndOfBuffer None |
| 289 | hi MsgArea None | 290 | hi MsgArea None |
| 290 | else | 291 | else |
| 291 | redir => output | hi LineNr | redir END | 292 | redir => output | hi LineNr | redir END |
| 292 | let bg_color = matchstr(output, 'guibg=\zs[^\s]\+\ze') | 293 | let bg_color = matchstr(output, 'guibg=\zs[^\s]\+\ze') |
| 293 | exe "hi EndOfBuffer guifg="..bg_color.." guibg="..bg_color | 294 | |
| 294 | exe "hi MsgArea guibg="..bg_color | 295 | try |
| 296 | exe "hi EndOfBuffer guifg="..bg_color.." guibg="..bg_color | ||
| 297 | exe "hi MsgArea guibg="..bg_color | ||
| 298 | endtry | ||
| 295 | exe "!alacritty msg config --window-id $WINDOWID window.padding.x=300 'colors.primary.background=\"\\"..bg_color.."\"'" | 299 | exe "!alacritty msg config --window-id $WINDOWID window.padding.x=300 'colors.primary.background=\"\\"..bg_color.."\"'" |
| 296 | endif | 300 | endif |
| 297 | 301 | ||
| @@ -380,24 +384,16 @@ function! CloseBufferSafely() | |||
| 380 | if answer == "" | return | endif | 384 | if answer == "" | return | endif |
| 381 | endif | 385 | endif |
| 382 | 386 | ||
| 383 | let l:bufnr = bufnr() | 387 | let bufnr = bufnr() |
| 384 | |||
| 385 | if len(t:bufs) == 1 | 388 | if len(t:bufs) == 1 |
| 386 | " Close tab for last buffer | 389 | " Close tab for last buffer |
| 387 | tabclose | 390 | tabclose |
| 388 | else | 391 | else |
| 389 | " Switch to proper buffer | 392 | " Switch to proper buffer |
| 390 | let l:next_buf = get(t:bufs, bufnr('#')) ? bufnr('#') : filter(t:bufs, 'v:val != '..l:bufnr)[0] | 393 | let next_buf = get(t:bufs, bufnr('#')) ? bufnr('#') : filter(t:bufs, 'v:val != '..bufnr)[0] |
| 391 | exe "b "..l:next_buf | 394 | exe "b "..next_buf |
| 392 | call filter(t:bufs, 'v:val != '..l:bufnr) | 395 | call filter(t:bufs, 'v:val != '..bufnr) |
| 393 | endif | 396 | endif |
| 394 | |||
| 395 | " Delete buffer if every t:buf doesn't have it | ||
| 396 | for tab in gettabinfo() | ||
| 397 | if get(tab.variables.bufs, l:bufnr) | return | endif | ||
| 398 | endfor | ||
| 399 | exe "bd! "..l:bufnr | ||
| 400 | |||
| 401 | endfunction | 397 | endfunction |
| 402 | function! Bye() | 398 | function! Bye() |
| 403 | let windows = gettabinfo(tabpagenr())[0]['windows'] | 399 | let windows = gettabinfo(tabpagenr())[0]['windows'] |
| @@ -493,10 +489,10 @@ endif | |||
| 493 | " MANAGE_TABS {{{ | 489 | " MANAGE_TABS {{{ |
| 494 | 490 | ||
| 495 | " Useful mappings for managing tabs | 491 | " Useful mappings for managing tabs |
| 496 | map <leader>tn :tabnew<CR> | 492 | nnoremap <leader>tn :tabnew<CR> |
| 497 | map <leader>tc :tabclose<CR> | 493 | nnoremap <leader>tc :tabclose<CR> |
| 498 | map <leader>tm :tabmove<SPACE> | 494 | nnoremap <leader>tm :tabmove<SPACE> |
| 499 | map <leader>to :tabonly<CR> | 495 | nnoremap <leader>to :tabonly<CR> |
| 500 | 496 | ||
| 501 | nnoremap <silent><m-h> :call Tab_MoveLeft()<CR> | 497 | nnoremap <silent><m-h> :call Tab_MoveLeft()<CR> |
| 502 | nnoremap <silent><m-l> :call Tab_MoveRight()<CR> | 498 | nnoremap <silent><m-l> :call Tab_MoveRight()<CR> |
| @@ -508,7 +504,7 @@ autocmd TabLeave * let g:lasttab = tabpagenr() | |||
| 508 | 504 | ||
| 509 | " Opens a new tab with the current buffer's path | 505 | " Opens a new tab with the current buffer's path |
| 510 | " Super useful when editing files in the same directory | 506 | " Super useful when editing files in the same directory |
| 511 | map <leader>te :tabedit <C-r>=expand("%:p:h")<CR> | 507 | nnoremap <leader>te :tabedit <C-r>=expand("%:p:h")<CR> |
| 512 | 508 | ||
| 513 | " Tab move functions | 509 | " Tab move functions |
| 514 | function! Tvab_MoveLeft() | 510 | function! Tvab_MoveLeft() |
| @@ -598,6 +594,11 @@ endfunction | |||
| 598 | " }}} | 594 | " }}} |
| 599 | " HIGHLIGHT {{{ | 595 | " HIGHLIGHT {{{ |
| 600 | 596 | ||
| 597 | nnoremap <expr> \sy exists("g:syntax_on") ? ":syntax off <CR>" : ":syntax enable<CR>" | ||
| 598 | |||
| 599 | " Toggle conceallevel0/2 | ||
| 600 | nnoremap <expr> \c ":set conceallevel="..(&cole ? 0 : 2).."<CR>:set cole?<CR>" | ||
| 601 | |||
| 601 | " Disable highlight when <leader><CR> is pressed | 602 | " Disable highlight when <leader><CR> is pressed |
| 602 | nnoremap <silent> <leader><CR> :noh<CR> | 603 | nnoremap <silent> <leader><CR> :noh<CR> |
| 603 | 604 | ||