aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--vim/init/basic.vim133
-rw-r--r--vim/init/config.vim30
-rw-r--r--vim/init/keymaps.vim115
-rw-r--r--vim/mini.lua659
4 files changed, 585 insertions, 352 deletions
diff --git a/vim/init/basic.vim b/vim/init/basic.vim
index 2394045..e18d51f 100644
--- a/vim/init/basic.vim
+++ b/vim/init/basic.vim
@@ -4,7 +4,7 @@
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" Vimscript file settings ---------------------- {{{ 7" For Vimscript {{{
8 8
9" Usage: type --- for foldmark 9" Usage: type --- for foldmark
10augroup filetype_vim 10augroup filetype_vim
@@ -14,13 +14,63 @@ augroup filetype_vim
14augroup END 14augroup END
15 15
16" }}} 16" }}}
17" GERERNAL ----------------{{{ 17" For Buffer and Tab {{{
18augroup tabinfo
19 au!
20 let g:tab_group = {}
21 " BufEnter {{{
22 function! AddBufToTabGroup(tab_group)
23 let l:tabId = tabpagenr()
24 let l:bufnr = bufnr()
25
26 if has_key(a:tab_group, l:tabId)
27 for v in a:tab_group[l:tabId]
28 if v == l:bufnr
29 return
30 endif
31 endfor
32 call add(a:tab_group[l:tabId], l:bufnr)
33 else
34 let a:tab_group[l:tabId] = [l:bufnr]
35 endif
36
37 endfunc
38 autocmd BufWinEnter * if &buflisted | call AddBufToTabGroup(g:tab_group) | endif
39 " }}}
40 " BufDelete {{{
41 function! RemoveBufFromTabGroup(tab_group)
42 let l:tabId = tabpagenr()
43
44 if has_key(a:tab_group, l:tabId)
45 let l:new_tab_group = {}
46
47 for [k, tab_list] in items(a:tab_group)
48 let l:list = []
49 for buf in tab_list
50 if buflisted(buf) > 0 && buf != expand('<abuf>')
51 call add(l:list, buf)
52 end
53 endfor
54 if !empty(l:list)
55 let l:new_tab_group[k] = l:list
56 endif
57 endfor
58 let g:tab_group = l:new_tab_group
59
60 endif
61
62 endfunc
63 autocmd BufDelete * call RemoveBufFromTabGroup(g:tab_group)
64 "}}}
65augroup END
66"}}}
67" GERERNAL {{{
18 68
19let mapleader = "," " Always use comma as leader key 69let mapleader = "," " Always use comma as leader key
20set nocompatible " Disable vi compatible, today is 20XX 70set nocompatible " Disable vi compatible, today is 20XX
21set path=.,** " Allow :find with completion 71set path=.,** " Allow :find with completion
22set mouse= " Disable mouse selection 72set mouse= " Disable mouse selection
23set winaltkeys=no " Allow alt key for mapping 73set winaltkeys=no " Allow alt key for mapping
24 74
25" Turn persistent undo on 75" Turn persistent undo on
26" means that you can undo even when you close a buffer/VIM 76" means that you can undo even when you close a buffer/VIM
@@ -43,22 +93,20 @@ set spellfile="/tmp/spell"
43sign define piet text=>> texthl=Search 93sign define piet text=>> texthl=Search
44 94
45" }}} 95" }}}
46" VISUAL ----------------{{{ 96" VISUAL {{{
47 97
48" colorscheme desert 98" colorscheme desert
49 99
50" Editing Area 100" Editing Area
51set wrap " enable wrap by default 101set wrap " enable wrap by default
52set scrolloff=3 " Leave some buffer when scrolling down 102set scrolloff=3 " Leave some buffer when scrolling down
53set showmatch " Show pairing brackets 103set showmatch " Show pairing brackets
54set display=lastline 104set display=lastline
55set lazyredraw 105set lazyredraw
56set formatoptions+=m " 遇到Unicode值大於255的文本,不必等到空格再折行
57set formatoptions+=B " 合併兩行中文時,不在中間加空格
58set whichwrap=b,s 106set whichwrap=b,s
59 107
60" Side column 108" Side column
61set signcolumn=yes number relativenumber 109set number relativenumber
62 110
63" Cursor 111" Cursor
64set cursorline 112set cursorline
@@ -67,30 +115,40 @@ set matchtime=2
67 115
68" In most of the cases, it is overrides by lightline.vim 116" In most of the cases, it is overrides by lightline.vim
69set statusline=\ %F%m%r%h\ %w\ \ CWD:\ %r%{getcwd()}%h\ \ \ Line:\ %l\ \ Column:\ %c 117set statusline=\ %F%m%r%h\ %w\ \ CWD:\ %r%{getcwd()}%h\ \ \ Line:\ %l\ \ Column:\ %c
70set laststatus=2 " Always show the status line 118set laststatus=2 " Always show the status line
71set ruler " Show cursor position 119set ruler " Show cursor position
72set wildmenu wildoptions=pum,fuzzy 120set wildmenu wildoptions=pum,fuzzy
73 121
74" Format of error message 122" Format of error message
75set errorformat+=[%f:%l]\ ->\ %m,[%f:%l]:%m 123set errorformat+=[%f:%l]\ ->\ %m,[%f:%l]:%m
76 124
125" Direction for new window
126set splitright
127
77" }}} 128" }}}
78" EDIT ----------------{{{ 129" EDIT {{{
130
131" overrides ftplugin in runtimepath
132" Don't wrap line when typing CJK characters
133" Don't add spaces for CJK
134" Don't add comment at next line
135autocmd Filetype * set fo+=mB fo-=cro
79 136
80set backspace=eol,start,indent " Set Backspace behaviors
81set autoindent smartindent
82set shiftwidth=2 137set shiftwidth=2
138set autoindent smartindent
83set cindent 139set cindent
84set ttimeout 140set ttimeout
85set timeoutlen=500 141set timeoutlen=500
142
143set backspace=eol,start,indent " Set Backspace behaviors
144
86" set updatetime=4000 145" set updatetime=4000
87" autocmd CursorHold * normal! m' 146" autocmd CursorHold * normal! m'
88 147
89" TAB and special Chars ----------------{{{ 148" TAB and special Chars {{{
90 149
91set tabstop=8 150set tabstop=8 softtabstop=8
92set expandtab 151set expandtab
93set softtabstop=-1
94 152
95" Invisible chars 153" Invisible chars
96set nolist 154set nolist
@@ -99,23 +157,23 @@ set listchars=tab:»·,extends:>,precedes:<
99" }}} 157" }}}
100 158
101" }}} 159" }}}
102" JUMP to anoterh file ----------------{{{ 160" JUMP to anoterh file {{{
103 161
104set isfname=@,48-57,/,.,-,_,+,,,#,$,%,~ " This affects filename recognition for gf (go to file) 162set isfname=@,48-57,/,.,-,_,+,,,#,$,%,~ " This affects filename recognition for gf (go to file)
105set suffixesadd=.md " Enable reference markdown file without extension 163set suffixesadd=.md " Enable reference markdown file without extension
106 164
107" }}} 165" }}}
108" SEARCH ----------------{{{ 166" SEARCH {{{
109 167
110set ignorecase " Search case without case sensation 168set ignorecase " Search case without case sensation
111set smartcase 169set smartcase
112set hlsearch " Hilight all matched texts 170set hlsearch " Highlight all matched texts
113set incsearch " Show matched strings when typing 171set incsearch " Show matched strings when typing
114 172
115" }}} 173" }}}
116" BUFFERS ----------------{{{ 174" BUFFERS {{{
117 175
118" Go to last cursor position ----------------{{{ 176" Go to last cursor position {{{
119augroup vimStartup 177augroup vimStartup
120 au! 178 au!
121 " When editing a file, always jump to the last known cursor position. 179 " When editing a file, always jump to the last known cursor position.
@@ -131,21 +189,22 @@ augroup END
131" }}} 189" }}}
132 190
133" }}} 191" }}}
134" FOLD ----------------{{{ 192" FOLD {{{
193
135set foldenable " Allow fold 194set foldenable " Allow fold
136set foldmethod=indent " Fold contents by indent 195set foldmethod=indent " Fold contents by indent
137set foldlevel=2 196set foldlevel=2
138set fillchars+=foldopen:▽,foldsep:│,foldclose:▶ 197set fillchars+=foldopen:▽,foldsep:│,foldclose:▶
139let g:defaut_foldcolumn = "" 198let g:defaut_foldcolumn = ""
140if has('nvim') 199if has('nvim')
141 let g:defaut_foldcolumn = "auto:5" 200 let g:defaut_foldcolumn = "auto:3"
142else 201else
143 let g:defaut_foldcolumn = 5 202 let g:defaut_foldcolumn = 3
144endif 203endif
145let &foldcolumn = g:defaut_foldcolumn 204let &foldcolumn = g:defaut_foldcolumn
146 205
147" }}} 206" }}}
148" ENCODING_PREFERENCE ----------------{{{ 207" ENCODING_PREFERENCE {{{
149 208
150if has('multi_byte') 209if has('multi_byte')
151 set encoding=utf-8 210 set encoding=utf-8
@@ -155,7 +214,7 @@ if has('multi_byte')
155endif 214endif
156 215
157" }}} 216" }}}
158" BACKUP ----------------{{{ 217" BACKUP {{{
159 218
160" Allow backup 219" Allow backup
161set backup 220set backup
@@ -170,7 +229,7 @@ set backupdir=~/.vim/tmp
170set writebackup 229set writebackup
171 230
172" }}} 231" }}}
173" HIGHLIGHT ----------------{{{ 232" HIGHLIGHT {{{
174 233
175syntax enable 234syntax enable
176set conceallevel=1 235set conceallevel=1
@@ -185,7 +244,7 @@ highlight ExtraWhitespace ctermbg=red guibg=red
185match ExtraWhitespace /\s\+$/ 244match ExtraWhitespace /\s\+$/
186 245
187" }}} 246" }}}
188" MISC ----------------{{{ 247" MISC {{{
189 248
190" Use Unix way to add newline 249" Use Unix way to add newline
191set ffs=unix,dos,mac 250set ffs=unix,dos,mac
diff --git a/vim/init/config.vim b/vim/init/config.vim
index 4e1c06c..4181ad3 100644
--- a/vim/init/config.vim
+++ b/vim/init/config.vim
@@ -3,7 +3,7 @@
3" Do some autocommand for by contexts 3" Do some autocommand for by contexts
4"====================================================================== 4"======================================================================
5 5
6" Unnamed Buffer ----------------{{{ 6" Unnamed Buffer {{{
7 7
8" Automatically delete unnamed empty buffer when leaving 8" Automatically delete unnamed empty buffer when leaving
9augroup DeleteUnnamedEmptBuffer! 9augroup DeleteUnnamedEmptBuffer!
@@ -12,7 +12,7 @@ augroup DeleteUnnamedEmptBuffer!
12augroup END 12augroup END
13 13
14" }}} 14" }}}
15" Small Terminal ----------------{{{ 15" Small Terminal {{{
16 16
17augroup TerminalSize 17augroup TerminalSize
18 au! 18 au!
@@ -27,13 +27,13 @@ augroup TerminalSize
27augroup END 27augroup END
28 28
29" }}} 29" }}}
30" X11 ----------------{{{ 30" X11 {{{
31 31
32" Change IM to US when exit to Normal mode 32" Change IM to US when exit to Normal mode
33autocmd InsertLeave * :silent !fcitx-remote -c &>/dev/null || true 33autocmd InsertLeave * :silent !fcitx-remote -c &>/dev/null || true
34 34
35" }}} 35" }}}
36" TMUX ----------------{{{ 36" TMUX {{{
37 37
38" 有 tmux 何没有的功能键超时(毫秒) 38" 有 tmux 何没有的功能键超时(毫秒)
39if $TMUX != '' 39if $TMUX != ''
@@ -60,7 +60,7 @@ if !has('gui_running') && &term =~ '^\%(screen\|tmux\)'
60endif 60endif
61 61
62" }}} 62" }}}
63" KeyCode ----------------{{{ 63" KeyCode {{{
64 64
65"---------------------------------------------------------------------- 65"----------------------------------------------------------------------
66" 终端下允许 ALT,详见:http://www.skywind.me/blog/archives/2021 66" 终端下允许 ALT,详见:http://www.skywind.me/blog/archives/2021
@@ -114,22 +114,22 @@ call s:key_escape('<S-F11>', '[23;2~')
114call s:key_escape('<S-F12>', '[24;2~') 114call s:key_escape('<S-F12>', '[24;2~')
115 115
116" }}} 116" }}}
117" Filetype ----------------{{{ 117" Filetype {{{
118 118
119augroup InitFileTypes 119augroup InitFileTypes
120 120
121 au! 121 au!
122 122
123 " Filetype for Vim ----------------{{{ 123 " Filetype for Vim {{{
124 124
125 " Help page 125 " Help page
126 autocmd BufEnter *.txt if &filetype == 'help' | wincmd T | endif 126 autocmd BufEnter * if &filetype == 'help' | wincmd T | set buflisted | endif
127 127
128 " quickfix: hide line number 128 " quickfix: hide line number
129 autocmd FileType quickfix setlocal nonumber 129 autocmd FileType quickfix setlocal nonumber
130 130
131 " }}} 131 " }}}
132 " Shebeng: Set filetype from shebeng ----------------{{{ 132 " Shebeng: Set filetype from shebeng {{{
133 function! s:ApplyShebang() 133 function! s:ApplyShebang()
134 let l:filetype = matchstr(getline(1), '^#!.*[ /]\zs[[:alnum:]]\+$') 134 let l:filetype = matchstr(getline(1), '^#!.*[ /]\zs[[:alnum:]]\+$')
135 let l:shebangMatch = #{ node: "javascript" } 135 let l:shebangMatch = #{ node: "javascript" }
@@ -143,7 +143,7 @@ augroup InitFileTypes
143 endfunction 143 endfunction
144 autocmd BufReadPost * call <SID>ApplyShebang() 144 autocmd BufReadPost * call <SID>ApplyShebang()
145 " }}} 145 " }}}
146 " Markdown ----------------{{{ 146 " Markdown {{{
147 147
148 augroup Config_Markdown 148 augroup Config_Markdown
149 au! 149 au!
@@ -168,7 +168,7 @@ augroup InitFileTypes
168 augroup END 168 augroup END
169 169
170 " }}} 170 " }}}
171 " HTML ----------------{{{ 171 " HTML {{{
172 172
173 " Usage: <leader>cl(ass) or <leader>id to edit html tag attribute 173 " Usage: <leader>cl(ass) or <leader>id to edit html tag attribute
174 function! s:ChangeAttr(pattern) 174 function! s:ChangeAttr(pattern)
@@ -192,17 +192,17 @@ augroup InitFileTypes
192 192
193 " Reload preview server 193 " Reload preview server
194 autocmd BufWrite *.html,*.js,*.css call ReloadServer() 194 autocmd BufWrite *.html,*.js,*.css call ReloadServer()
195 function ReloadServer() 195 function! ReloadServer()
196 silent !browser-sync reload &>/dev/null 196 silent !browser-sync reload &>/dev/null
197 endfunction 197 endfunction
198 198
199 " }}} 199 " }}}
200 " Mail ----------------{{{ 200 " Mail {{{
201 201
202 autocmd BufRead /tmp/mutt-* set tw=72 202 autocmd BufRead /tmp/mutt-* set tw=72
203 203
204 " }}} 204 " }}}
205 " Password ----------------{{{ 205 " Password {{{
206 206
207 " Hide the first line of a file if editing password file 207 " Hide the first line of a file if editing password file
208 " TODO a better way to determine a file is related to password-store, now use 208 " TODO a better way to determine a file is related to password-store, now use
@@ -218,7 +218,7 @@ augroup InitFileTypes
218 norm! ggzfl 218 norm! ggzfl
219 endfunction 219 endfunction
220 " }}} 220 " }}}
221 " Beancount ----------------{{{ 221 " Beancount {{{
222 222
223 autocmd BufRead,BufNewFile *.bean call PrepareBean() 223 autocmd BufRead,BufNewFile *.bean call PrepareBean()
224 function PrepareBean() 224 function PrepareBean()
diff --git a/vim/init/keymaps.vim b/vim/init/keymaps.vim
index f13756b..1eb2b20 100644
--- a/vim/init/keymaps.vim
+++ b/vim/init/keymaps.vim
@@ -21,15 +21,15 @@ nnoremap <leader>W :set wrap!<CR>
21function! s:WriteOrEnterFileName() 21function! s:WriteOrEnterFileName()
22 if !empty(expand('%')) | write! | else | call feedkeys(":w ") | endif 22 if !empty(expand('%')) | write! | else | call feedkeys(":w ") | endif
23endfunction 23endfunction
24nmap <leader>w :call <SID>WriteOrEnterFileName()<CR> 24nnoremap <leader>w :call <SID>WriteOrEnterFileName()<CR>
25 25
26" :W sudo saves the file 26" :W sudo saves the file
27" (useful for handling the permission-denied error) 27" (useful for handling the permission-denied error)
28command! W execute 'w !sudo -S tee %' <bar> edit! 28command! W execute 'w !sudo -S tee %' <bar> edit!
29 29
30" Quit 30" Quit
31nmap <leader>q :q<CR> 31nnoremap <leader>q :q<CR>
32nmap cq :cq<CR> 32nnoremap cq :cq<CR>
33 33
34" Remap <CR> in Quickfix, Cmdwin Location list 34" Remap <CR> in Quickfix, Cmdwin Location list
35augroup vimrc_CRfix 35augroup vimrc_CRfix
@@ -57,7 +57,7 @@ augroup END
57" execute "set <M-h>=\eh" 57" execute "set <M-h>=\eh"
58 58
59" Spell 59" Spell
60nnoremap <leader><leader>sp :set spell!<CR>:set spell?<CR> 60nnoremap \s :set spell!<CR>:set spell?<CR>
61nnoremap <leader>ss ]s 61nnoremap <leader>ss ]s
62nnoremap <leader>S [s 62nnoremap <leader>S [s
63 63
@@ -68,6 +68,7 @@ nnoremap <C-g> 1<C-g>
68vnoremap Tz :!trans -t zh-TW -b<CR> 68vnoremap Tz :!trans -t zh-TW -b<CR>
69vnoremap Te :!trans -t en-US -b<CR> 69vnoremap Te :!trans -t en-US -b<CR>
70 70
71
71" }}} 72" }}}
72" WORKING_DIR ----------------{{{ 73" WORKING_DIR ----------------{{{
73 74
@@ -82,8 +83,8 @@ nnoremap cd :cd %:p:h<CR>:pwd<CR>
82 83
83nnoremap cd<space> :cd<space> 84nnoremap cd<space> :cd<space>
84nnoremap cdg :call CdToGitRepo()<CR>:pwd<CR> 85nnoremap cdg :call CdToGitRepo()<CR>:pwd<CR>
85noremap <C-[> :cd ..<CR>:pwd<CR> 86nnoremap <C-[> :cd ..<CR>:pwd<CR>
86noremap <C-]> :call InCaseCdToLatestDir()<CR> 87nnoremap <C-]> :call InCaseCdToLatestDir()<CR>
87 88
88" Switch CWD to root git directory 89" Switch CWD to root git directory
89function! CdToGitRepo() 90function! CdToGitRepo()
@@ -105,17 +106,21 @@ endfunction
105" MOTION ----------------{{{ 106" MOTION ----------------{{{
106 107
107" j/k will move virtual lines (lines that wrap) 108" j/k will move virtual lines (lines that wrap)
108noremap <silent> <expr> j (v:count == 0 ? 'gj' : 'j') 109nnoremap <silent> <expr> j (v:count == 0 ? 'gj' : 'j')
109noremap <silent> <expr> k (v:count == 0 ? 'gk' : 'k') 110nnoremap <silent> <expr> k (v:count == 0 ? 'gk' : 'k')
110 111
111" Quick move in a line 112" Quick move in a line
112noremap <C-h> 30h 113nnoremap <C-h> 30h
113noremap <C-l> 30l 114nnoremap <C-l> 30l
114 115
115" File under the cursor 116" File under the cursor
116nnoremap <CR> gf 117nnoremap <CR> gf
117nnoremap gF :e <cfile><CR> 118nnoremap gF :e <cfile><CR>
118 119
120xnoremap iq i"
121xnoremap aq a"
122
123
119" READLINE_FEATURES ----------------{{{ 124" READLINE_FEATURES ----------------{{{
120 125
121inoremap <C-f> <Right> 126inoremap <C-f> <Right>
@@ -145,22 +150,22 @@ cnoremap <C-k> <C-x>d$<C-c>
145cnoremap <M-d> <C-x>de<C-c> 150cnoremap <M-d> <C-x>de<C-c>
146 151
147" Moving with wrap 152" Moving with wrap
148noremap <m-j> gj 153nnoremap <m-j> gj
149noremap <m-k> gk 154nnoremap <m-k> gk
150inoremap <m-j> <c-\><c-o>gj 155inoremap <m-j> <c-\><c-o>gj
151inoremap <m-k> <c-\><c-o>gk 156inoremap <m-k> <c-\><c-o>gk
152" }}} 157" }}}
153" JUMP_TO_TABS_WITH_ALT ----------------{{{ 158" JUMP_TO_TABS_WITH_ALT ----------------{{{
154 159
155noremap <silent><A-1> :tabn 1<CR> 160nnoremap <silent><A-1> :tabn 1<CR>
156noremap <silent><A-2> :tabn 2<CR> 161nnoremap <silent><A-2> :tabn 2<CR>
157noremap <silent><M-3> :tabn 3<CR> 162nnoremap <silent><M-3> :tabn 3<CR>
158noremap <silent><M-4> :tabn 4<CR> 163nnoremap <silent><M-4> :tabn 4<CR>
159noremap <silent><M-5> :tabn 5<CR> 164nnoremap <silent><M-5> :tabn 5<CR>
160noremap <silent><M-6> :tabn 6<CR> 165nnoremap <silent><M-6> :tabn 6<CR>
161noremap <silent><M-7> :tabn 7<CR> 166nnoremap <silent><M-7> :tabn 7<CR>
162noremap <silent><M-8> :tabn 8<CR> 167nnoremap <silent><M-8> :tabn 8<CR>
163noremap <silent><M-9> :tablast<CR> 168nnoremap <silent><M-9> :tablast<CR>
164inoremap <silent><A-1> <Esc>:tabn 1<CR> 169inoremap <silent><A-1> <Esc>:tabn 1<CR>
165inoremap <silent><A-2> <Esc>:tabn 2<CR> 170inoremap <silent><A-2> <Esc>:tabn 2<CR>
166inoremap <silent><M-3> <Esc>:tabn 3<CR> 171inoremap <silent><M-3> <Esc>:tabn 3<CR>
@@ -211,23 +216,25 @@ nnoremap <leader>ee :edit $MYVIMRC<CR>
211" MANAGE_BUFFERS ----------------{{{ 216" MANAGE_BUFFERS ----------------{{{
212 217
213" Set options 218" Set options
214noremap st :set<space> 219nnoremap so :set<space>
215noremap <leader><leader>ft :<C-\>e'set filetype='..&filetype<CR> 220nnoremap <leader><leader>ft :<C-\>e'set filetype='..&filetype<CR>
216noremap <leader><leader>li :set list!<CR> 221nnoremap <leader><leader>sw :<C-\>e'set shiftwidth='..&shiftwidth<CR>
217noremap <leader><leader>sw :<C-\>e'set shiftwidth='..&shiftwidth<CR> 222nnoremap <leader><leader>ts :<C-\>e'set tabstop='..&tabstop<CR>
218noremap <leader><leader>nu :set number!<CR> 223nnoremap \e :set expandtab!<CR>:set expandtab?<CR>
219noremap <leader><leader>ru :set relativenumber!<CR> 224nnoremap \l :set list!<CR>:set list?<CR>
225nnoremap \n :set nu!<CR>:set nu?<CR>
226nnoremap \r :set relativenumber!<CR>:set rnu?<CR>
220 227
221" Open a new buffer 228" Open a new buffer
222nmap <leader>B :enew<CR> 229nnoremap <leader>B :enew<CR>
223nmap <leader>O :e /tmp/buffer<CR> 230nnoremap <leader>O :e /tmp/buffer<CR>
224 231
225" Let <leader>l toggle between this and the last accessed buffer 232" Let <leader>l toggle between this and the last accessed buffer
226augroup SaveLastBuffer 233augroup SaveLastBuffer
227 let g:lastbuffer = 1 234 let g:lastbuffer = 1
228 au BufLeave * let g:lastbuffer = bufnr() 235 au BufLeave * if &buflisted | let g:lastbuffer = expand('<abuf>') | endif
229augroup END 236augroup END
230noremap <leader>l :exe "buffer ".g:lastbuffer<CR> 237nnoremap <leader>l :exe "buffer ".g:lastbuffer<CR>
231 238
232" Use Ctrl-C for buffer delete or quit vim ----------------{{{ 239" Use Ctrl-C for buffer delete or quit vim ----------------{{{
233 240
@@ -238,9 +245,11 @@ function! ToggleQuit()
238 let message = g:quitVimWhenPressingCtrlC ? "Unlock" : "Lock" 245 let message = g:quitVimWhenPressingCtrlC ? "Unlock" : "Lock"
239 echo message 246 echo message
240endfunction 247endfunction
241nnoremap <leader><leader>gl :call ToggleQuit()<CR> 248nnoremap \q :call ToggleQuit()<CR>
242 249
243function! CloseBufferSafely() 250function! CloseBufferSafely()
251 let l:bufnr = bufnr()
252 " Ask Saving
244 if &modified 253 if &modified
245 let answer = confirm("Save changes?", "&Yes\n&No\n&Cancel") 254 let answer = confirm("Save changes?", "&Yes\n&No\n&Cancel")
246 if answer == 1 | write | endif 255 if answer == 1 | write | endif
@@ -248,27 +257,22 @@ function! CloseBufferSafely()
248 if answer == "" | return | endif 257 if answer == "" | return | endif
249 endif 258 endif
250 259
251 let bufs = getbufinfo({'buflisted': 1}) 260 if g:tab_group[tabpagenr()] == [l:bufnr]
252 if len(bufs) == 1 261 bdelete
253 bdelete!
254 else 262 else
255 b# | bd! # 263 bprevious | bd #
256 endif 264 endif
257endfunction 265endfunction
258func! QuitWithCheck() 266func! QuitWithCheck()
259 if g:quitVimWhenPressingCtrlC 267 if g:quitVimWhenPressingCtrlC
260 silent! quit 268 silent! quit
261 else 269 else
262 echo "Press <leader><leader>gl to allow quit with <C-c>" 270 echo "Press \\q to allow quit with <C-c>"
263 endif 271 endif
264endfunc 272endfunc
265function! Bye() 273function! Bye()
266 let windows = gettabinfo(tabpagenr())[0]['windows'] 274 let windows = gettabinfo(tabpagenr())[0]['windows']
267 try 275 let bufs = getbufinfo({'buflisted': 1})
268 let bufs = gettabinfo(tabpagenr())[0]['variables']['bufs']
269 catch
270 let bufs = getbufinfo({'buflisted': 1})
271 endtry
272 276
273 if len(windows) == 1 && len(bufs) == 1 277 if len(windows) == 1 && len(bufs) == 1
274 call QuitWithCheck() 278 call QuitWithCheck()
@@ -282,8 +286,8 @@ function! Bye()
282endfunction 286endfunction
283nnoremap <silent> <C-c> :call Bye()<CR> 287nnoremap <silent> <C-c> :call Bye()<CR>
284 288
285 289" }}}
286" Diff Mode ---------------- 290" Diff Mode {{{
287 291
288function! CloseBuffersForDiff() 292function! CloseBuffersForDiff()
289 windo | if &diff && &buftype == "nofile" | bdelete | endif 293 windo | if &diff && &buftype == "nofile" | bdelete | endif
@@ -329,10 +333,10 @@ nnoremap <leader><leader>sb :windo set scrollbind!<CR>
329" 传统的 CTRL+hjkl 移动窗口不适用于 vim 8.1 的终端模式,CTRL+hjkl 在 333" 传统的 CTRL+hjkl 移动窗口不适用于 vim 8.1 的终端模式,CTRL+hjkl 在
330" bash/zsh 及带文本界面的程序中都是重要键位需要保留,不能 tnoremap 的 334" bash/zsh 及带文本界面的程序中都是重要键位需要保留,不能 tnoremap 的
331"---------------------------------------------------------------------- 335"----------------------------------------------------------------------
332noremap <m-H> <c-w>h 336nnoremap <m-H> <c-w>h
333noremap <m-L> <c-w>l 337nnoremap <m-L> <c-w>l
334noremap <m-J> <c-w>j 338nnoremap <m-J> <c-w>j
335noremap <m-K> <c-w>k 339nnoremap <m-K> <c-w>k
336inoremap <m-H> <esc><c-w>h 340inoremap <m-H> <esc><c-w>h
337inoremap <m-L> <esc><c-w>l 341inoremap <m-L> <esc><c-w>l
338inoremap <m-J> <esc><c-w>j 342inoremap <m-J> <esc><c-w>j
@@ -365,12 +369,12 @@ map <leader>tc :tabclose<CR>
365map <leader>tm :tabmove<SPACE> 369map <leader>tm :tabmove<SPACE>
366map <leader>to :tabonly<CR> 370map <leader>to :tabonly<CR>
367 371
368noremap <silent><m-h> :call Tab_MoveLeft()<CR> 372nnoremap <silent><m-h> :call Tab_MoveLeft()<CR>
369noremap <silent><m-l> :call Tab_MoveRight()<CR> 373nnoremap <silent><m-l> :call Tab_MoveRight()<CR>
370 374
371" Let <leader>tl toggle between this and the last accessed tab 375" Let <leader>tl toggle between this and the last accessed tab
372let g:lasttab = 1 376let g:lasttab = 1
373nmap <Leader>tl :exe "tabn ".g:lasttab<CR> 377nnoremap <Leader>tl :exe "tabn ".g:lasttab<CR>
374autocmd TabLeave * let g:lasttab = tabpagenr() 378autocmd TabLeave * let g:lasttab = tabpagenr()
375 379
376" Opens a new tab with the current buffer's path 380" Opens a new tab with the current buffer's path
@@ -394,8 +398,8 @@ endfunc
394" FOLD ----------------{{{ 398" FOLD ----------------{{{
395 399
396" Set fold options 400" Set fold options
397noremap <leader><leader>fm :<C-\>e'set foldmethod='..&foldmethod<CR> 401nnoremap <leader><leader>fm :<C-\>e'set foldmethod='..&foldmethod<CR>
398noremap <leader><leader>fc :<C-\>e'set foldcolumn='..&foldcolumn<CR> 402nnoremap <leader><leader>fc :<C-\>e'set foldcolumn='..&foldcolumn<CR>
399 403
400nnoremap zi zizz 404nnoremap zi zizz
401 405
@@ -463,7 +467,7 @@ endfunction
463" HIGHLIGHT ----------------{{{ 467" HIGHLIGHT ----------------{{{
464 468
465" Disable highlight when <leader><CR> is pressed 469" Disable highlight when <leader><CR> is pressed
466noremap <silent> <leader><CR> :noh<CR> 470nnoremap <silent> <leader><CR> :noh<CR>
467 471
468function! HiFile() 472function! HiFile()
469 let i = 1 473 let i = 1
@@ -501,7 +505,6 @@ inoremap ( ()<Left>
501inoremap [ []<Left> 505inoremap [ []<Left>
502inoremap { {}<Left> 506inoremap { {}<Left>
503 507
504vnoremap S sa
505vnoremap ' <ESC>`<i'<ESC>`>la'<ESC> 508vnoremap ' <ESC>`<i'<ESC>`>la'<ESC>
506vnoremap q <ESC>`<i"<ESC>`>la"<ESC> 509vnoremap q <ESC>`<i"<ESC>`>la"<ESC>
507vnoremap ( <ESC>`<i(<ESC>`>la)<ESC> 510vnoremap ( <ESC>`<i(<ESC>`>la)<ESC>
@@ -591,6 +594,8 @@ vnoremap <CR> <Cmd>call SubstituteBySearch()<CR>
591" }}} 594" }}}
592" SIGN ----------------{{{ 595" SIGN ----------------{{{
593 596
597nnoremap <leader><leader>sc :<C-\>e'set signcolumn='..&signcolumn<CR>
598
594nnoremap <leader>si :exe ":sign place " .. line('.') .. " line=" .. line('.') .. " name=piet file=" .. expand("%:p")<CR> 599nnoremap <leader>si :exe ":sign place " .. line('.') .. " line=" .. line('.') .. " name=piet file=" .. expand("%:p")<CR>
595nnoremap <leader>sI :exe ":sign unplace * file=" .. expand("%:p")<CR> 600nnoremap <leader>sI :exe ":sign unplace * file=" .. expand("%:p")<CR>
596 601
diff --git a/vim/mini.lua b/vim/mini.lua
index e693db2..15f4c42 100644
--- a/vim/mini.lua
+++ b/vim/mini.lua
@@ -13,8 +13,7 @@ end
13vim.opt.rtp:prepend(lazypath) 13vim.opt.rtp:prepend(lazypath)
14-- }}} 14-- }}}
15require("lazy").setup({ 15require("lazy").setup({
16 16 -- "tpope/vim-sleuth",
17 "tpope/vim-sleuth",
18 -- Telescope {{{ 17 -- Telescope {{{
19 { 18 {
20 "nvim-telescope/telescope.nvim", 19 "nvim-telescope/telescope.nvim",
@@ -236,7 +235,6 @@ require("lazy").setup({
236 indent_markers = { 235 indent_markers = {
237 enable = true, 236 enable = true,
238 }, 237 },
239 --
240 icons = { 238 icons = {
241 show = { 239 show = {
242 file = true, 240 file = true,
@@ -244,7 +242,6 @@ require("lazy").setup({
244 folder_arrow = true, 242 folder_arrow = true,
245 git = true, 243 git = true,
246 }, 244 },
247 --
248 glyphs = { 245 glyphs = {
249 default = "󰈚", 246 default = "󰈚",
250 symlink = "", 247 symlink = "",
@@ -336,192 +333,278 @@ require("lazy").setup({
336 end, 333 end,
337 }, 334 },
338 --}}} 335 --}}}
336 -- lualine {{{
337 {
338 "nvim-lualine/lualine.nvim",
339 event = "VeryLazy",
340 init = function()
341 vim.g.lualine_laststatus = vim.o.laststatus
342 if vim.fn.argc(-1) > 0 then
343 -- set an empty statusline till lualine loads
344 vim.o.statusline = " "
345 else
346 -- hide the statusline on the starter page
347 vim.o.laststatus = 0
348 end
349 end,
350 opts = function()
351 -- PERF: we don't need this lualine require madness 🤷
352 local lualine_require = require("lualine_require")
353 lualine_require.require = require
339 354
340 -- -- lspconfig {{{ 355 vim.o.laststatus = vim.g.lualine_laststatus
341 -- -- Use :help lspconfig-all to check servers 356
342 -- { 357 local opts = {
343 -- "neovim/nvim-lspconfig", 358 options = {
344 -- lazy = false, 359 theme = "auto",
345 -- config = function() 360 globalstatus = vim.o.laststatus == 3,
346 -- local lspconfig = require "lspconfig" 361 disabled_filetypes = { statusline = { "dashboard", "alpha", "ministarter" } },
347 -- -- 362 },
348 -- -- typescript 363 sections = {
349 -- lspconfig.lua_ls.setup {} 364 lualine_a = { "mode" },
350 -- lspconfig.tsserver.setup {} 365 lualine_b = { "branch" },
351 -- lspconfig.vimls.setup {} 366
352 -- lspconfig.html.setup {} 367 lualine_x = {
353 -- -- 368 -- stylua: ignore
354 -- vim.keymap.set("n", "<leader>F", function() 369 {
355 -- vim.lsp.buf.format() 370 function() return require("noice").api.status.command.get() end,
356 -- end, { desc = "format files" }) 371 cond = function() return package.loaded["noice"] and require("noice").api.status.command.has() end,
357 -- end, 372 },
358 -- }, 373 -- stylua: ignore
359 -- -- }}} 374 {
360 -- -- Mason {{{ 375 function() return require("noice").api.status.mode.get() end,
361 -- { 376 cond = function() return package.loaded["noice"] and require("noice").api.status.mode.has() end,
362 -- "williamboman/mason.nvim", 377 },
363 -- config = function() 378 -- stylua: ignore
364 -- require('mason').setup { 379 {
365 -- automatically_installation = true, 380 function() return " " .. require("dap").status() end,
366 -- ensure_installed = { 381 cond = function() return package.loaded["dap"] and require("dap").status() ~= "" end,
367 -- "vim-language-server", 382 },
368 -- "lua-language-server", 383 -- stylua: ignore
369 -- "css-lsp", 384 {
370 -- "html-lsp", 385 require("lazy.status").updates,
371 -- "prettier", 386 cond = require("lazy.status").has_updates,
372 -- "stylua", 387 },
373 -- }, 388 {
374 -- } 389 "diff",
375 -- end 390 source = function()
376 -- }, 391 local gitsigns = vim.b.gitsigns_status_dict
377 -- -- }}} 392 if gitsigns then
378 -- -- treesitter {{{ 393 return {
379 -- { 394 added = gitsigns.added,
380 -- "nvim-treesitter/nvim-treesitter", 395 modified = gitsigns.changed,
381 -- event = { "BufReadPost", "BufNewFile" }, 396 removed = gitsigns.removed,
382 -- cmd = { "TSInstall", "TSBufEnable", "TSBufDisable", "TSModuleInfo" }, 397 }
383 -- build = ":TSUpdate", 398 end
384 -- config = function() 399 end,
385 -- require("nvim-treesitter.configs").setup({ 400 },
386 -- ensure_installed = { "lua", "luadoc", "printf", "vim", "vimdoc" }, 401 },
387 -- -- 402 lualine_y = {
388 -- highlight = { 403 { "progress", separator = " ", padding = { left = 1, right = 0 } },
389 -- enable = true, 404 { "location", padding = { left = 0, right = 1 } },
390 -- use_languagetree = true, 405 },
391 -- }, 406 lualine_z = {
392 -- -- 407 function()
393 -- indent = { enable = true }, 408 return " " .. os.date("%R")
394 -- }) 409 end,
395 -- end, 410 },
396 -- }, 411 },
397 -- -- }}} 412 extensions = { "neo-tree", "lazy" },
398 -- -- nvim-cmp {{{ 413 }
399 -- { 414
400 -- "hrsh7th/nvim-cmp", 415 return opts
401 -- event = { 416 end,
402 -- "InsertEnter", 417 },
403 -- "CmdlineEnter" 418 -- }}}
404 -- }, 419
405 -- dependencies = { -- {{{ 420 -- lspconfig {{{
406 -- { 421 -- Use :help lspconfig-all to check servers
407 -- -- snippet plugin 422 {
408 -- "L3MON4D3/LuaSnip", 423 "neovim/nvim-lspconfig",
409 -- build = "make install_jsregexp", 424 lazy = false,
410 -- dependencies = { 425 config = function()
411 -- "rafamadriz/friendly-snippets", 426 local lspconfig = require "lspconfig"
412 -- "saadparwaiz1/cmp_luasnip", 427 --
413 -- "onsails/lspkind-nvim", 428 -- typescript
414 -- }, 429 lspconfig.lua_ls.setup {}
415 -- opts = { 430 lspconfig.tsserver.setup {}
416 -- history = true, 431 lspconfig.vimls.setup {}
417 -- updateevents = "TextChanged,TextChangedI" 432 lspconfig.html.setup {}
418 -- }, 433 --
419 -- config = function(_, opts) 434 vim.keymap.set("n", "<leader>F", function()
420 -- require("luasnip").config.set_config(opts) 435 vim.lsp.buf.format()
421 -- require("luasnip.loaders.from_vscode").lazy_load() 436 end, { desc = "format files" })
422 -- require("luasnip.loaders.from_lua").load() 437 end,
423 -- require("luasnip.loaders.from_lua").lazy_load { paths = vim.g.lua_snippets_path or "" } 438 },
424 -- -- 439 -- }}}
425 -- vim.api.nvim_create_autocmd("InsertLeave", { 440 -- Mason {{{
426 -- callback = function() 441 {
427 -- if 442 "williamboman/mason.nvim",
428 -- require("luasnip").session.current_nodes[vim.api.nvim_get_current_buf()] 443 dependencies = {
429 -- and not require("luasnip").session.jump_active 444 "williamboman/mason-lspconfig.nvim",
430 -- then 445 },
431 -- require("luasnip").unlink_current() 446 config = function()
432 -- end 447 require('mason').setup {
433 -- end, 448 automatically_installation = true,
434 -- }) 449 ensure_installed = {
435 -- end, 450 "vim-language-server",
436 -- }, 451 "lua-language-server",
437 -- -- 452 "css-lsp",
438 -- -- cmp sources plugins 453 "html-lsp",
439 -- { 454 "prettier",
440 -- "hrsh7th/cmp-nvim-lua", 455 "stylua",
441 -- "hrsh7th/cmp-nvim-lsp", 456 },
442 -- "hrsh7th/cmp-buffer", 457 }
443 -- "hrsh7th/cmp-path", 458 end
444 -- "hrsh7th/cmp-cmdline", 459 },
445 -- }, 460 -- }}}
446 -- }, -- }}} 461 -- treesitter {{{
447 -- config = function() 462 {
448 -- local cmp = require "cmp" 463 "nvim-treesitter/nvim-treesitter",
449 -- local default_mapping = { 464 event = { "BufReadPost", "BufNewFile" },
450 -- ["<S-TAB>"] = cmp.mapping.select_prev_item(), 465 cmd = { "TSInstall", "TSBufEnable", "TSBufDisable", "TSModuleInfo" },
451 -- ["<TAB>"] = cmp.mapping.select_next_item(), 466 build = ":TSUpdate",
452 -- ["<C-p>"] = cmp.mapping.select_prev_item(), 467 config = function()
453 -- ["<C-n>"] = cmp.mapping.select_next_item(), 468 require("nvim-treesitter.configs").setup({
454 -- ["<C-d>"] = cmp.mapping.scroll_docs(-4), 469 ensure_installed = { "lua", "luadoc", "printf", "vim", "vimdoc" },
455 -- ["<C-f>"] = cmp.mapping.scroll_docs(4), 470 --
456 -- ["<C-Space>"] = cmp.mapping.complete(), 471 highlight = {
457 -- ["<C-e>"] = cmp.mapping.close(), 472 enable = true,
458 -- ['<CR>'] = cmp.mapping.confirm(), 473 use_languagetree = true,
459 -- ['<C-c>'] = cmp.mapping.abort(), 474 },
460 -- } 475 --
461 -- 476 indent = { enable = true },
462 -- require("cmp").setup({ 477 })
463 -- completion = { 478 end,
464 -- completeopt = "menu,menuone,noselect", 479 },
465 -- }, 480 -- }}}
466 -- window = { 481 -- nvim-cmp {{{
467 -- documentation = cmp.config.window.bordered(), 482 {
468 -- completion = cmp.config.window.bordered({ 483 "hrsh7th/nvim-cmp",
469 -- winhighlight = 'Normal:CmpPmenu,CursorLine:PmenuSel,Search:None' 484 event = {
470 -- }), 485 "InsertEnter",
471 -- }, 486 "CmdlineEnter"
472 -- snippet = { 487 },
473 -- expand = function(args) 488 dependencies = { -- {{{
474 -- require("luasnip").lsp_expand(args.body) 489 {
475 -- end, 490 -- snippet plugin
476 -- }, 491 "L3MON4D3/LuaSnip",
477 -- formatting = { 492 build = "make install_jsregexp",
478 -- format = require('lspkind').cmp_format({ 493 dependencies = {
479 -- with_text = true, -- do not show text alongside icons 494 "rafamadriz/friendly-snippets",
480 -- maxwidth = 50, -- prevent the popup from showing more than provided characters (e.g 50 will not show more than 50 characters) 495 "saadparwaiz1/cmp_luasnip",
481 -- before = function(entry, vim_item) 496 "onsails/lspkind-nvim",
482 -- -- Source 显示提示来源 497 },
483 -- vim_item.menu = '<' .. entry.source.name .. '>' 498 opts = {
484 -- return vim_item 499 history = true,
485 -- end 500 updateevents = "TextChanged,TextChangedI"
486 -- }) 501 },
487 -- }, 502 config = function(_, opts)
488 -- mapping = default_mapping, 503 require("luasnip").config.set_config(opts)
489 -- sources = cmp.config.sources { 504 require("luasnip.loaders.from_vscode").lazy_load()
490 -- { name = "nvim_lsp" }, 505 require("luasnip.loaders.from_lua").load()
491 -- { name = "luasnip" }, 506 require("luasnip.loaders.from_lua").lazy_load { paths = vim.g.lua_snippets_path or "" }
492 -- { name = "buffer" }, 507 --
493 -- { name = "nvim_lua" }, 508 vim.api.nvim_create_autocmd("InsertLeave", {
494 -- { name = "path" }, 509 callback = function()
495 -- }, 510 if
496 -- experimental = { 511 require("luasnip").session.current_nodes[vim.api.nvim_get_current_buf()]
497 -- ghost_text = true, 512 and not require("luasnip").session.jump_active
498 -- } 513 then
499 -- }) 514 require("luasnip").unlink_current()
500 -- cmp.setup.cmdline(':', { 515 end
501 -- mapping = cmp.mapping.preset.cmdline { 516 end,
502 -- ['<C-n>'] = cmp.config.disable, 517 })
503 -- ['<C-p>'] = cmp.config.disable, 518 end,
504 -- ['<C-c>'] = cmp.mapping.abort(), 519 },
505 -- }, 520 --
506 -- sources = cmp.config.sources( 521 -- cmp sources plugins
507 -- { { name = 'path' } }, 522 {
508 -- { { name = 'cmdline' } } 523 "hrsh7th/cmp-nvim-lua",
509 -- ) 524 "hrsh7th/cmp-nvim-lsp",
510 -- }) 525 "hrsh7th/cmp-buffer",
511 -- cmp.setup.cmdline({ '/', '?' }, { 526 "hrsh7th/cmp-path",
512 -- mapping = cmp.mapping.preset.cmdline { 527 "hrsh7th/cmp-cmdline",
513 -- ['<C-n>'] = cmp.config.disable, 528 },
514 -- ['<C-p>'] = cmp.config.disable, 529 }, -- }}}
515 -- ['<C-c>'] = cmp.mapping.abort(), 530 config = function()
516 -- }, 531 local cmp = require "cmp"
517 -- sources = { { name = 'buffer' } } 532 local default_mapping = {
518 -- }) 533 ["<S-TAB>"] = cmp.mapping.select_prev_item(),
519 -- 534 ["<TAB>"] = cmp.mapping.select_next_item(),
520 -- vim.opt.complete = "" 535 ["<C-p>"] = cmp.mapping.select_prev_item(),
521 -- end, 536 ["<C-n>"] = cmp.mapping.select_next_item(),
522 -- }, 537 ["<C-d>"] = cmp.mapping.scroll_docs(-4),
523 -- 538 ["<C-f>"] = cmp.mapping.scroll_docs(4),
524 -- -- }}} 539 ["<C-Space>"] = cmp.mapping.complete(),
540 ["<C-e>"] = cmp.mapping.close(),
541 ['<CR>'] = cmp.mapping.confirm(),
542 ['<C-c>'] = cmp.mapping.abort(),
543 }
544
545 require("cmp").setup({
546 completion = {
547 completeopt = "menu,menuone,noselect",
548 },
549 window = {
550 documentation = cmp.config.window.bordered(),
551 completion = cmp.config.window.bordered({
552 winhighlight = 'Normal:CmpPmenu,CursorLine:PmenuSel,Search:None'
553 }),
554 },
555 snippet = {
556 expand = function(args)
557 require("luasnip").lsp_expand(args.body)
558 end,
559 },
560 formatting = {
561 format = require('lspkind').cmp_format({
562 with_text = true, -- do not show text alongside icons
563 maxwidth = 50, -- prevent the popup from showing more than provided characters (e.g 50 will not show more than 50 characters)
564 before = function(entry, vim_item)
565 -- Source 显示提示来源
566 vim_item.menu = '<' .. entry.source.name .. '>'
567 return vim_item
568 end
569 })
570 },
571 mapping = default_mapping,
572 sources = cmp.config.sources {
573 { name = "nvim_lsp" },
574 { name = "luasnip" },
575 { name = "buffer" },
576 { name = "nvim_lua" },
577 { name = "path" },
578 },
579 experimental = {
580 ghost_text = true,
581 }
582 })
583 cmp.setup.cmdline(':', {
584 mapping = cmp.mapping.preset.cmdline {
585 ['<C-n>'] = cmp.config.disable,
586 ['<C-p>'] = cmp.config.disable,
587 ['<C-c>'] = cmp.mapping.abort(),
588 },
589 sources = cmp.config.sources(
590 { { name = 'path' } },
591 { { name = 'cmdline' } }
592 )
593 })
594 cmp.setup.cmdline({ '/', '?' }, {
595 mapping = cmp.mapping.preset.cmdline {
596 ['<C-n>'] = cmp.config.disable,
597 ['<C-p>'] = cmp.config.disable,
598 ['<C-c>'] = cmp.mapping.abort(),
599 },
600 sources = { { name = 'buffer' } }
601 })
602
603 vim.opt.complete = ""
604 end,
605 },
606
607 -- }}}
525 -- -- lspsaga {{{ 608 -- -- lspsaga {{{
526 -- { 609 -- {
527 -- 'nvimdev/lspsaga.nvim', 610 -- 'nvimdev/lspsaga.nvim',
@@ -555,7 +638,6 @@ require("lazy").setup({
555 -- end, 638 -- end,
556 -- }, 639 -- },
557 -- -- }}} 640 -- -- }}}
558
559}) 641})
560 642
561-- Install mini.nvim {{{ 643-- Install mini.nvim {{{
@@ -658,52 +740,6 @@ vim.cmd("hi BufferLineTab guibg=Gray")
658-- mini.icons {{{ 740-- mini.icons {{{
659require("mini.icons").setup({}) 741require("mini.icons").setup({})
660--}}} 742--}}}
661-- mini.statusline {{{
662--
663require("mini.statusline").setup({
664 content = {
665 active = status_config,
666 },
667})
668local function diagnostics_table(args)
669 local info = vim.b.coc_diagnostic_info
670 if MiniStatusline.is_truncated(args.trunc_width) or info == nil then
671 return {}
672 end
673 local table = {}
674 table.e = (info["error"] or 0) > 0 and "E" .. info["error"] or ""
675 table.w = (info["warning"] or 0) > 0 and "W" .. info["warning"] or ""
676 table.h = (info["hint"] or 0) > 0 and "H" .. info["hint"] or ""
677 table.i = (info["information"] or 0) > 0 and "I" .. info["information"] or ""
678 table.s = vim.g.coc_status
679 return table
680end
681--
682function status_config()
683 local mode, mode_hl = MiniStatusline.section_mode({ trunc_width = 120 })
684 local git = MiniStatusline.section_git({ trunc_width = 75 })
685 local diagnostics = diagnostics_table({ trunc_width = 75 })
686 local filename = MiniStatusline.section_filename({ trunc_width = 140 })
687 local fileinfo = MiniStatusline.section_fileinfo({ trunc_width = 120 })
688 local location = MiniStatusline.section_location({ trunc_width = 75 })
689 --
690 return MiniStatusline.combine_groups({
691 { hl = mode_hl, strings = { mode } },
692 { hl = "MiniStatuslineDevinfo", strings = { git, diagnostics["s"] } },
693 { hl = "MiniStatuslineError", strings = { diagnostics["e"] } },
694 { hl = "MiniStatuslineWarning", strings = { diagnostics["w"] } },
695 { hl = "MiniStatuslineInfo", strings = { diagnostics["i"] } },
696 { hl = "MiniStatuslineHint", strings = { diagnostics["h"] } },
697 "%<", -- Mark general truncate point
698 { hl = "MiniStatuslineFilename", strings = { filename } },
699 "%=", -- End left alignment
700 { hl = "MiniStatuslineFileinfo", strings = { fileinfo } },
701 { hl = mode_hl, strings = { location } },
702 })
703end
704
705--
706-- }}}
707-- mini.comment {{{ 743-- mini.comment {{{
708require("mini.comment").setup({ 744require("mini.comment").setup({
709 -- Module mappings. Use `''` (empty string) to disable one. 745 -- Module mappings. Use `''` (empty string) to disable one.
@@ -754,17 +790,20 @@ vim.keymap.set("n", "\\m", function()
754end, { desc = "Minimap", buffer = bufnr }) 790end, { desc = "Minimap", buffer = bufnr })
755-- }}} 791-- }}}
756-- mini.visits {{{ 792-- mini.visits {{{
793
757require("mini.visits").setup() 794require("mini.visits").setup()
758-- vim.keymap.set("n", "<leader><leader>li", function() 795-- vim.keymap.set("n", "<leader><leader>li", function()
759-- MiniVisits.list_paths() 796-- MiniVisits.list_paths()
760-- end, { buffer = bufnr, desc = "" }) 797-- end, { buffer = bufnr, desc = "" })
798--
761-- }}} 799-- }}}
762-- mini.surround {{{ 800-- mini.surround {{{
763require("mini.surround").setup({ 801require("mini.surround").setup {
764 mappings = { 802 mappings = {
765 add = "s", 803 add = 'S'
766 }, 804 }
767}) 805}
806vim.keymap.set('v', 's', 'S', { remap = true })
768-- }}} 807-- }}}
769-- mini.indentscope {{{ 808-- mini.indentscope {{{
770require("mini.indentscope").setup() 809require("mini.indentscope").setup()
@@ -798,6 +837,51 @@ end, { buffer = bufnr, desc = "Toggle hex color highlight" })
798-- mini.pairs {{{ 837-- mini.pairs {{{
799require("mini.pairs").setup() 838require("mini.pairs").setup()
800-- }}} 839-- }}}
840-- -- mini.statusline {{{
841-- --
842-- require("mini.statusline").setup({
843-- content = {
844-- active = status_config,
845-- },
846-- })
847-- local function diagnostics_table(args)
848-- local info = vim.b.coc_diagnostic_info
849-- if MiniStatusline.is_truncated(args.trunc_width) or info == nil then
850-- return {}
851-- end
852-- local table = {}
853-- table.e = (info["error"] or 0) > 0 and "E" .. info["error"] or ""
854-- table.w = (info["warning"] or 0) > 0 and "W" .. info["warning"] or ""
855-- table.h = (info["hint"] or 0) > 0 and "H" .. info["hint"] or ""
856-- table.i = (info["information"] or 0) > 0 and "I" .. info["information"] or ""
857-- table.s = vim.g.coc_status
858-- return table
859-- end
860--
861-- function status_config()
862-- local mode, mode_hl = MiniStatusline.section_mode({ trunc_width = 120 })
863-- local git = MiniStatusline.section_git({ trunc_width = 75 })
864-- local diagnostics = diagnostics_table({ trunc_width = 75 })
865-- local filename = MiniStatusline.section_filename({ trunc_width = 140 })
866-- local fileinfo = MiniStatusline.section_fileinfo({ trunc_width = 120 })
867-- local location = MiniStatusline.section_location({ trunc_width = 75 })
868--
869-- return MiniStatusline.combine_groups({
870-- { hl = mode_hl, strings = { mode } },
871-- { hl = "MiniStatuslineDevinfo", strings = { git, diagnostics["s"] } },
872-- { hl = "MiniStatuslineError", strings = { diagnostics["e"] } },
873-- { hl = "MiniStatuslineWarning", strings = { diagnostics["w"] } },
874-- { hl = "MiniStatuslineInfo", strings = { diagnostics["i"] } },
875-- { hl = "MiniStatuslineHint", strings = { diagnostics["h"] } },
876-- "%<", -- Mark general truncate point
877-- { hl = "MiniStatuslineFilename", strings = { filename } },
878-- "%=", -- End left alignment
879-- { hl = "MiniStatuslineFileinfo", strings = { fileinfo } },
880-- { hl = mode_hl, strings = { location } },
881-- })
882-- end
883--
884-- -- }}}
801-- -- mini.completion {{{ 885-- -- mini.completion {{{
802-- require('mini.completion').setup() 886-- require('mini.completion').setup()
803-- -- }}} 887-- -- }}}
@@ -878,7 +962,7 @@ require("mini.pairs").setup()
878-- }) 962-- })
879-- vim.keymap.set("n", "<leader>z", ":TZAtaraxis<CR>") 963-- vim.keymap.set("n", "<leader>z", ":TZAtaraxis<CR>")
880-- -- }}} 964-- -- }}}
881-- bufferline {{{ 965-- -- bufferline {{{
882Add({ 966Add({
883 source = "akinsho/bufferline.nvim", 967 source = "akinsho/bufferline.nvim",
884 depends = { 968 depends = {
@@ -886,8 +970,9 @@ Add({
886 "tiagovla/scope.nvim", 970 "tiagovla/scope.nvim",
887 }, 971 },
888}) 972})
889require("bufferline").setup({ 973require('bufferline').setup{
890 options = { 974 options = {
975 numbers = 'ordinal',
891 tab_size = 14, 976 tab_size = 14,
892 separator_style = { "", "" }, 977 separator_style = { "", "" },
893 themable = true, 978 themable = true,
@@ -898,9 +983,66 @@ require("bufferline").setup({
898 require("bufferline.groups").builtin.pinned:with({ icon = "󰐃" }), 983 require("bufferline.groups").builtin.pinned:with({ icon = "󰐃" }),
899 }, 984 },
900 }, 985 },
901 }, 986 enforce_regular_tabs = false,
902}) 987 diagnostics = "coc",
903require("scope").setup({}) 988 diagnostics_update_in_insert = true,
989 diagnostics_indicator = function(count, level)
990 local icon = level:match("error") and " " or " "
991 return " " .. icon .. count
992 end,
993 offsets = {
994 {
995 filetype = "NvimTree",
996 text = "File Explorer",
997 highlight = "Directory",
998 text_align = "left"
999 },
1000 {
1001 filetype = "coc-explorer",
1002 text = function()
1003 return vim.fn.getcwd()
1004 end,
1005 highlight = "Directory",
1006 text_align = "left"
1007 },
1008 {
1009 filetype = 'vista',
1010 text = function()
1011 return vim.fn.getcwd()
1012 end,
1013 highlight = "Tags",
1014 text_align = "right"
1015 }
1016 },
1017 custom_filter = function (buf_number)
1018 local tabId = tostring(vim.fn.tabpagenr())
1019 if vim.g.tab_group[tabId] then
1020 for _, p in ipairs(vim.g.tab_group[tabId]) do
1021 if p == buf_number then
1022 return true
1023 end
1024 end
1025 end
1026 return false
1027 end
1028 }
1029};
1030
1031-- require("bufferline").setup({
1032-- options = {
1033-- custom_filter = function(buf_number)
1034-- local tabId = vim.fn.tabpagenr()
1035-- if vim.g.tab_group[tabId] then
1036-- for _, p in ipairs(vim.g.tab_group[tabId]) do
1037-- if p == buf_number then
1038-- return true
1039-- end
1040-- end
1041-- end
1042-- return false
1043-- end
1044-- },
1045-- })
904-- keymaps {{{ 1046-- keymaps {{{
905for i = 1, 9, 1 do 1047for i = 1, 9, 1 do
906 vim.keymap.set("n", string.format("<A-%s>", i), function() 1048 vim.keymap.set("n", string.format("<A-%s>", i), function()
@@ -914,4 +1056,31 @@ vim.keymap.set("n", "<M-h>", "<Cmd>BufferLineMovePrev<CR>", opts)
914vim.keymap.set("n", "<M-l>", "<Cmd>BufferLineMoveNext<CR>", opts) 1056vim.keymap.set("n", "<M-l>", "<Cmd>BufferLineMoveNext<CR>", opts)
915vim.keymap.set("n", "<M-p>", "<Cmd>BufferLineTogglePin<CR>", opts) 1057vim.keymap.set("n", "<M-p>", "<Cmd>BufferLineTogglePin<CR>", opts)
916-- }}} 1058-- }}}
1059-- -- TODO: tabpages
1060-- -- }}}
1061
1062-- KEYMAPS {{{
1063
1064-- Use floating window for translation
1065vim.keymap.set("v", "Tz", function()
1066 vim.cmd('norm o^zt"ty')
1067 local translated_text = vim.fn.system("trans -t zh-TW -b", vim.fn.getreg("t"))
1068 local lines = vim.split(translated_text, "\n")
1069 table.remove(lines)
1070
1071 local new_buf = vim.api.nvim_create_buf(false, true)
1072 vim.api.nvim_buf_set_lines(new_buf, 0, -1, true, lines)
1073
1074 vim.api.nvim_open_win(new_buf, true, {
1075 relative = "cursor",
1076 width = 80,
1077 height = #lines,
1078 row = #lines,
1079 col = 0,
1080 })
1081
1082 vim.cmd("setl nocul nonu nornu")
1083 vim.cmd("hi ActiveWindow guibg=#2a5a6a guifg=White | setl winhighlight=Normal:ActiveWindow")
1084 vim.cmd(":silent! %s/\\%x1b\\[[0-9;]*m//g")
1085end, { desc = "Description" })
917-- }}} 1086-- }}}