aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorHsieh Chin Fan <pham@topo.tw>2024-08-13 00:49:46 +0800
committerHsieh Chin Fan <pham@topo.tw>2024-08-13 00:49:46 +0800
commit763bb27e3fa962315a3373934369d594d5a2a045 (patch)
tree5c6b5208efb6ba140558a188a53ab6a07afbd6ed
parentca4e5d232c35709c185fa64dcea9cf93e2723ff6 (diff)
Update
-rw-r--r--alias2
-rw-r--r--vim/init/config.vim7
-rw-r--r--vim/init/keymaps.vim58
-rw-r--r--vim/mini.lua21
4 files changed, 59 insertions, 29 deletions
diff --git a/alias b/alias
index 8d3f192..5af2f78 100644
--- a/alias
+++ b/alias
@@ -283,7 +283,7 @@ vp() {
283 283
284# __GIT__ 284# __GIT__
285unalias gc &> /dev/null # override zsh plugin alias 285unalias gc &> /dev/null # override zsh plugin alias
286gc() { git clone $@; if [ $# == 1 ]; then cd $(basename ${1%.git}); fi } 286gc() { git clone $@; if [ $# = 1 ]; then cd $(basename ${1%.git}); fi }
287gc1() { git clone --depth=1 $1 && cd $(basename $1); } 287gc1() { git clone --depth=1 $1 && cd $(basename $1); }
288gcv() { gc vps:$1; } 288gcv() { gc vps:$1; }
289alias gls='git log -S' 289alias gls='git log -S'
diff --git a/vim/init/config.vim b/vim/init/config.vim
index 8d84ff1..de7ee22 100644
--- a/vim/init/config.vim
+++ b/vim/init/config.vim
@@ -28,6 +28,13 @@ augroup TerminalSize
28augroup END 28augroup END
29 29
30" }}} 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"}}}
31" X11 {{{ 38" X11 {{{
32 39
33" Change IM to US when exit to Normal mode 40" Change IM to US when exit to Normal mode
diff --git a/vim/init/keymaps.vim b/vim/init/keymaps.vim
index f6bda45..d456791 100644
--- a/vim/init/keymaps.vim
+++ b/vim/init/keymaps.vim
@@ -8,16 +8,10 @@
8" Space for searching 8" Space for searching
9map <space> / 9map <space> /
10 10
11" Escape normal mode by <C-c>
12inoremap <C-c> <Esc>l
13
14" Set wrap
15nnoremap \w :set wrap!<CR>:set wrap?<CR>
16
17" Fast saving 11" Fast saving
18function! s:WriteOrEnterFileName() 12function! s:WriteOrEnterFileName()
19 if !empty(bufname('%')) | write! | else | call feedkeys(":w ") | endif 13 if !empty(bufname('%')) | write! | else | call feedkeys(":w ") | endif
20endfunction 14endfunc
21nnoremap <leader>w :call <SID>WriteOrEnterFileName()<CR> 15nnoremap <leader>w :call <SID>WriteOrEnterFileName()<CR>
22 16
23" :W sudo saves the file 17" :W sudo saves the file
@@ -99,7 +93,7 @@ xnoremap iq i"
99xnoremap aq a" 93xnoremap aq a"
100 94
101 95
102" READLINE_FEATURES {{{ 96" READLINE {{{
103 97
104inoremap <C-f> <Right> 98inoremap <C-f> <Right>
105inoremap <C-b> <Left> 99inoremap <C-b> <Left>
@@ -124,12 +118,10 @@ cnoremap <C-d> <Del>
124cnoremap <C-h> <BackSpace> 118cnoremap <C-h> <BackSpace>
125cnoremap <C-n> <Down> 119cnoremap <C-n> <Down>
126cnoremap <C-p> <Up> 120cnoremap <C-p> <Up>
127cnoremap <C-k> <C-x>d$<C-c> 121cnoremap <C-k> <C-x>d$<C-c><space><BS>
128cnoremap <M-d> <C-x>de<C-c> 122cnoremap <M-d> <C-x>de<C-c><space><BS>
129 123
130" Moving with wrap 124" Moving with wrap
131nnoremap <m-j> gj
132nnoremap <m-k> gk
133inoremap <m-j> <c-\><c-o>gj 125inoremap <m-j> <c-\><c-o>gj
134inoremap <m-k> <c-\><c-o>gk 126inoremap <m-k> <c-\><c-o>gk
135" }}} 127" }}}
@@ -159,6 +151,22 @@ inoremap <silent><M-9> <Esc>:tablast<CR>
159" }}} 151" }}}
160" EDIT {{{ 152" EDIT {{{
161 153
154" Escape normal mode by <C-c>
155inoremap <C-c> <Esc>l
156
157" Set wrap
158nnoremap \w :set wrap!<CR>:set wrap?<CR>
159
160" Set line numbers
161nnoremap \n :set nu!<CR>:set nu?<CR>
162nnoremap \r :set relativenumber!<CR>:set rnu?<CR>
163
164nnoremap \l :set list!<CR>:set list?<CR>
165
166" Set options for indent
167nnoremap <leader><leader>sw :<C-\>e'set shiftwidth='..&shiftwidth<CR>
168nnoremap <leader><leader>ts :<C-\>e'set tabstop='..&tabstop<CR>
169
162" Set text width for auto wrapping 170" Set text width for auto wrapping
163nnoremap <leader><leader>tw :set fo+=t<CR>:<C-\>e'set tw='..&tw<CR> 171nnoremap <leader><leader>tw :set fo+=t<CR>:<C-\>e'set tw='..&tw<CR>
164 172
@@ -222,7 +230,7 @@ let g:search_selection = 0
222" When leaving visual mode, resume search_selection 230" When leaving visual mode, resume search_selection
223autocmd Modechanged [vV\x16]*:* let g:search_selection = 0 231autocmd Modechanged [vV\x16]*:* let g:search_selection = 0
224xmap <expr> <TAB> g:search_selection ? "//e<CR>" : "*:let g:search_selection = 1<CR>gv//e<CR>" 232xmap <expr> <TAB> g:search_selection ? "//e<CR>" : "*:let g:search_selection = 1<CR>gv//e<CR>"
225xmap <expr> <S-TAB> g:search_selection ? "??<CR>" : "*:let g:search_selection = 1<CR>gv??<CR>" 233xmap <expr> <S-TAB> g:search_selection ? "??<CR>" : "*:let g:search_selection = 1<CR>gv??<CR>"
226vnoremap <CR> :s//<C-R>0/g<Left><Left> 234vnoremap <CR> :s//<C-R>0/g<Left><Left>
227 235
228" }}} 236" }}}
@@ -310,7 +318,7 @@ nnoremap \z :call GrayOutOthers()<CR>
310nnoremap <C-p> "0p 318nnoremap <C-p> "0p
311 319
312" Toggle paste mode on and off 320" Toggle paste mode on and off
313map <leader>pp :setlocal paste!<CR> 321nnoremap <leader><leader>p :setlocal paste!<CR>
314 322
315" Copy from system clipboard 323" Copy from system clipboard
316nnoremap gp "+p 324nnoremap gp "+p
@@ -415,7 +423,7 @@ nnoremap <expr> z> ":\<C-u>call ChangeUnfold(1,"..v:count..")\<CR>"
415nnoremap <expr> z< ":\<C-u>call ChangeUnfold(0,"..v:count..")\<CR>" 423nnoremap <expr> z< ":\<C-u>call ChangeUnfold(0,"..v:count..")\<CR>"
416 424
417"}}} 425"}}}
418" MANAGE_VIMRC {{{ 426" MANAGE_SCRIPTS {{{
419 427
420" source .vimrc 428" source .vimrc
421nnoremap <leader>so V:so<CR> 429nnoremap <leader>so V:so<CR>
@@ -424,7 +432,7 @@ vnoremap so :source<CR>
424autocmd! BUFWRITEPOST $MYVIMRC source $MYVIMRC 432autocmd! BUFWRITEPOST $MYVIMRC source $MYVIMRC
425 433
426" Find scripts 434" Find scripts
427nnoremap <leader>e :scriptnames<space> 435nnoremap <leader>es :scriptnames<space>
428nnoremap <leader>ee :edit $MYVIMRC<CR> 436nnoremap <leader>ee :edit $MYVIMRC<CR>
429 437
430" }}} 438" }}}
@@ -433,13 +441,8 @@ nnoremap <leader>ee :edit $MYVIMRC<CR>
433" Set options 441" Set options
434nnoremap so :set<space> 442nnoremap so :set<space>
435nnoremap <leader><leader>ft :<C-\>e'set filetype='..&filetype<CR> 443nnoremap <leader><leader>ft :<C-\>e'set filetype='..&filetype<CR>
436nnoremap <leader><leader>sw :<C-\>e'set shiftwidth='..&shiftwidth<CR>
437nnoremap <leader><leader>ts :<C-\>e'set tabstop='..&tabstop<CR>
438nnoremap \E :set expandtab!<CR>:set expandtab?<CR> 444nnoremap \E :set expandtab!<CR>:set expandtab?<CR>
439nnoremap \e :call ToggleEventIgnore()<CR> 445nnoremap \e :call ToggleEventIgnore()<CR>
440nnoremap \l :set list!<CR>:set list?<CR>
441nnoremap \n :set nu!<CR>:set nu?<CR>
442nnoremap \r :set relativenumber!<CR>:set rnu?<CR>
443 446
444function! ToggleEventIgnore() 447function! ToggleEventIgnore()
445 let operator = empty(&eventignore) ? "+=" : "-=" 448 let operator = empty(&eventignore) ? "+=" : "-="
@@ -628,8 +631,8 @@ endfunc
628 631
629" Use <leader>z to toggle window padding for alacritty 632" Use <leader>z to toggle window padding for alacritty
630let g:alacritty_extra_padding = 0 633let g:alacritty_extra_padding = 0
631function! ToggleWinPadding(padding) 634function! ToggleWinPadding(occupy)
632 if g:alacritty_extra_padding && !a:padding 635 if g:alacritty_extra_padding && !a:occupy
633 !alacritty msg config --window-id $WINDOWID --reset 636 !alacritty msg config --window-id $WINDOWID --reset
634 call SetEmulaterBackground() 637 call SetEmulaterBackground()
635 hi EndOfBuffer None 638 hi EndOfBuffer None
@@ -639,12 +642,18 @@ function! ToggleWinPadding(padding)
639 let bg_color = matchstr(output, 'guibg=\zs[^\s]\+\ze') 642 let bg_color = matchstr(output, 'guibg=\zs[^\s]\+\ze')
640 if empty(bg_color) | let bg_color = "#14161b" | endif 643 if empty(bg_color) | let bg_color = "#14161b" | endif
641 644
645 redir => win_width_str
646 !xdotool getactivewindow getwindowgeometry --shell | grep WIDTH | sed s/WIDTH=//
647 redir END
648 let win_width = str2nr(matchstr(win_width_str, '[0-9]\+'))
649
650 let padding = a:occupy ? (100-a:occupy) / 2 * win_width / 100 : 15 * win_width / 100
651
642 try 652 try
643 exe "hi EndOfBuffer guifg="..bg_color.." guibg="..bg_color 653 exe "hi EndOfBuffer guifg="..bg_color.." guibg="..bg_color
644 exe "hi MsgArea guibg="..bg_color 654 exe "hi MsgArea guibg="..bg_color
645 endtry 655 endtry
646 656
647 let padding = a:padding ? a:padding : "270"
648 exe "!alacritty msg config --window-id $WINDOWID window.padding.x=" . padding . " 'colors.primary.background=\"\\"..bg_color.."\"'" 657 exe "!alacritty msg config --window-id $WINDOWID window.padding.x=" . padding . " 'colors.primary.background=\"\\"..bg_color.."\"'"
649 endif 658 endif
650 659
@@ -737,7 +746,6 @@ function! Redir(cmd)
737endfunction 746endfunction
738 747
739command! -nargs=1 -complete=command Redir silent call Redir(<q-args>) 748command! -nargs=1 -complete=command Redir silent call Redir(<q-args>)
740command! -nargs=1 -complete=command R silent call Redir(<q-args>)
741nnoremap <leader>rr :Redir<space> 749nnoremap <leader>rr :Redir<space>
742 750
743" Print Runtimepath 751" Print Runtimepath
diff --git a/vim/mini.lua b/vim/mini.lua
index 799f638..d449bf7 100644
--- a/vim/mini.lua
+++ b/vim/mini.lua
@@ -429,6 +429,7 @@ require("lazy").setup({
429 } 429 }
430 }, 430 },
431 custom_filter = function (buf_number) 431 custom_filter = function (buf_number)
432 if vim.t.bufs == nil then return false end
432 for _, p in ipairs(vim.t.bufs) do 433 for _, p in ipairs(vim.t.bufs) do
433 if p == buf_number then 434 if p == buf_number then
434 return true 435 return true
@@ -562,6 +563,13 @@ require("lazy").setup({
562 -- config {{{ 563 -- config {{{
563 require("telescope").setup({ 564 require("telescope").setup({
564 defaults = { 565 defaults = {
566 preview = {
567 filesize_hook = function(filepath, bufnr, opts)
568 local max_bytes = 100000
569 local cmd = {"head", "-c", max_bytes, filepath}
570 require('telescope.previewers.utils').job_maker(cmd, bufnr, opts)
571 end
572 },
565 mappings = { 573 mappings = {
566 i = { 574 i = {
567 -- ["<c-j>"] = "move_selection_next", 575 -- ["<c-j>"] = "move_selection_next",
@@ -1046,14 +1054,21 @@ require("lazy").setup({
1046 ensure_installed = { "markdown", "markdown_inline", "lua", "luadoc", "printf", "vim", "vimdoc" }, 1054 ensure_installed = { "markdown", "markdown_inline", "lua", "luadoc", "printf", "vim", "vimdoc" },
1047 1055
1048 highlight = { 1056 highlight = {
1049 enable = true, 1057 enable = false,
1050 use_languagetree = true,
1051 additional_vim_regex_highlighting = true, 1058 additional_vim_regex_highlighting = true,
1059 use_languagetree = true,
1060 disable = function(lang, buf)
1061 local max_filesize = 100 * 1024 -- 100 KB
1062 local ok, stats = pcall(vim.loop.fs_stat, vim.api.nvim_buf_get_name(buf))
1063 if ok and stats and stats.size > max_filesize then
1064 return true
1065 end
1066 end,
1052 }, 1067 },
1053 1068
1054 indent = { enable = true }, 1069 indent = { enable = true },
1055 }) 1070 })
1056 vim.cmd([[ 1071 vim.cmd([[
1057 syn match MarkdownHtmlDetails '^<details>' conceal cchar=▶ 1072 syn match MarkdownHtmlDetails '^<details>' conceal cchar=▶
1058 syn match MarkdownHtmlSummary '<summary>' conceal cchar= 1073 syn match MarkdownHtmlSummary '<summary>' conceal cchar=
1059 syn match MarkdownHtmlSummaryEnd '</summary>' conceal 1074 syn match MarkdownHtmlSummaryEnd '</summary>' conceal