aboutsummaryrefslogtreecommitdiffhomepage
path: root/vim/init/config.vim
diff options
context:
space:
mode:
authorHsieh Chin Fan <pham@topo.tw>2024-07-30 17:56:29 +0800
committerHsieh Chin Fan <pham@topo.tw>2024-07-30 17:56:29 +0800
commitc680ac2a4b06ebdc2da9a05311f01495c73f9c01 (patch)
treeb4c8f50db4330bf8de0d2af26a9637706cd97f0c /vim/init/config.vim
parent9b564fcfeec95ed965252ef4acc6ee42702ded88 (diff)
Update
Diffstat (limited to 'vim/init/config.vim')
-rw-r--r--vim/init/config.vim63
1 files changed, 38 insertions, 25 deletions
diff --git a/vim/init/config.vim b/vim/init/config.vim
index 4181ad3..9700c61 100644
--- a/vim/init/config.vim
+++ b/vim/init/config.vim
@@ -16,14 +16,15 @@ augroup END
16 16
17augroup TerminalSize 17augroup TerminalSize
18 au! 18 au!
19 function! LayoutForSmallTerminal() 19 function! LayoutForSmallTerminal(bound)
20 if &lines < 19 20 let l:bound = a:bound ? a:bound : 19
21 if &lines < l:bound || g:alacritty_extra_padding
21 silent! set cmdheight=0 laststatus=0 showtabline=0 signcolumn=no nowrap scrolloff=1 22 silent! set cmdheight=0 laststatus=0 showtabline=0 signcolumn=no nowrap scrolloff=1
22 else 23 else
23 silent! set cmdheight& laststatus& showtabline=2 signcolumn=yes scrolloff=3 24 silent! set cmdheight& laststatus& showtabline=2 signcolumn=yes scrolloff=3
24 endif 25 endif
25 endfunction 26 endfunc
26 autocmd VimEnter,VimResized * call LayoutForSmallTerminal() 27 autocmd VimEnter,VimResized * silent call LayoutForSmallTerminal(0)
27augroup END 28augroup END
28 29
29" }}} 30" }}}
@@ -140,30 +141,45 @@ augroup InitFileTypes
140 echo "filetype from shebang: ".l:filetype 141 echo "filetype from shebang: ".l:filetype
141 execute "set filetype=".l:filetype 142 execute "set filetype=".l:filetype
142 endif 143 endif
143 endfunction 144 endfunc
144 autocmd BufReadPost * call <SID>ApplyShebang() 145 autocmd BufReadPost * call <SID>ApplyShebang()
145 " }}} 146 " }}}
146 " Markdown {{{ 147 " Markdown {{{
147 148
148 augroup Config_Markdown 149 augroup Config_Markdown
149 au! 150 au!
150 au FileType markdown setlocal wrap sw=2 ts=2 151 au FileType markdown call InitMarkdown()
151 au FileType markdown setlocal foldexpr=MarkdownLevel() foldmethod=expr 152
153 function! InitMarkdown()
154 setlocal wrap sw=2 ts=2
155 setlocal foldexpr=MarkdownLevel() foldmethod=expr
156 setlocal foldtext=MarkdownFoldTextHeading()
157 syn match Details '^<details>' conceal cchar=▶
158 syn match Summary '<summary>' conceal cchar=
159 syn match SummaryEnd '</summary>' conceal
160 syn match DetailsEnd '^</details>' conceal cchar=E
161 endfunc
152 162
153 " Fold by heading level 163 " Fold by heading level
154 function! MarkdownLevel() 164 function! MarkdownLevel()
155 let hash_num = matchstr(getline(v:lnum), '^#\+') 165 let hash_num = matchstr(getline(v:lnum), '^#\+')
156 let hash_num_at_top = matchstr(getline(v:lnum-1), '^#\+') 166 if !empty(hash_num)
157 if empty(hash_num) 167 " HEADING
158 if empty(hash_num_at_top) 168 " return ">"..(len(hash_num) - 1)
159 return "=" 169 return len(hash_num) == 1 ? 0 : '>1'
160 else
161 return ">"..(len(hash_num_at_top))
162 endif
163 else 170 else
164 return len(hash_num) - 1 171 " Contents
172 return "="
165 endif 173 endif
166 endfunction 174 endfunc
175
176 function! MarkdownFoldTextHeading()
177 let origin = split(MarkdownFoldText()[2:], ' ')
178 let heading = substitute(join(origin[:-3], ' '), '\#', ' ', 'g')
179 let lines = join(origin[-2:], ' ')[1:-2]
180 let spaces = repeat('.', 50 - len(heading) - len(lines))
181 return heading..spaces.." "..lines
182 endfunc
167 183
168 augroup END 184 augroup END
169 185
@@ -186,7 +202,7 @@ augroup InitFileTypes
186 noh 202 noh
187 startinsert 203 startinsert
188 endif 204 endif
189 endfunction 205 endfunc
190 autocmd FileType html,markdown nnoremap <buffer> <leader>cl :call <SID>ChangeAttr("class")<CR> 206 autocmd FileType html,markdown nnoremap <buffer> <leader>cl :call <SID>ChangeAttr("class")<CR>
191 autocmd FileType html,markdown nnoremap <buffer> <leader>id :call <SID>ChangeAttr("id")<CR> 207 autocmd FileType html,markdown nnoremap <buffer> <leader>id :call <SID>ChangeAttr("id")<CR>
192 208
@@ -194,12 +210,12 @@ augroup InitFileTypes
194 autocmd BufWrite *.html,*.js,*.css call ReloadServer() 210 autocmd BufWrite *.html,*.js,*.css call ReloadServer()
195 function! ReloadServer() 211 function! ReloadServer()
196 silent !browser-sync reload &>/dev/null 212 silent !browser-sync reload &>/dev/null
197 endfunction 213 endfunc
198 214
199 " }}} 215 " }}}
200 " Mail {{{ 216 " Mail {{{
201 217
202 autocmd BufRead /tmp/mutt-* set tw=72 218 autocmd BufRead /tmp/mutt-* setlocal tw=72
203 219
204 " }}} 220 " }}}
205 " Password {{{ 221 " Password {{{
@@ -211,12 +227,9 @@ augroup InitFileTypes
211 function SetPasswordFile() 227 function SetPasswordFile()
212 setlocal foldminlines=0 228 setlocal foldminlines=0
213 setlocal foldmethod=manual 229 setlocal foldmethod=manual
214 function s:custom() 230 setlocal foldtext="Password"
215 return "Password"
216 endfunction
217 setlocal foldtext=s:custom()
218 norm! ggzfl 231 norm! ggzfl
219 endfunction 232 endfunc
220 " }}} 233 " }}}
221 " Beancount {{{ 234 " Beancount {{{
222 235
@@ -225,7 +238,7 @@ augroup InitFileTypes
225 set filetype=beancount 238 set filetype=beancount
226 silent !setsid fava ~/bean/main.bean &>/dev/null 239 silent !setsid fava ~/bean/main.bean &>/dev/null
227 autocmd VimLeave * silent !killall fava 240 autocmd VimLeave * silent !killall fava
228 endfunction 241 endfunc
229 242
230 " }}} 243 " }}}
231 244