From cc96870ff94afba7b0f2dc18f0209611ff7201f7 Mon Sep 17 00:00:00 2001 From: Hsieh Chin Fan Date: Thu, 1 Aug 2024 00:32:50 +0800 Subject: Update --- vim/init/config.vim | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) (limited to 'vim/init/config.vim') diff --git a/vim/init/config.vim b/vim/init/config.vim index e4403fb..318bc58 100644 --- a/vim/init/config.vim +++ b/vim/init/config.vim @@ -18,9 +18,9 @@ augroup TerminalSize au! function! LayoutForSmallTerminal(bound) if &lines < a:bound || g:alacritty_extra_padding - silent! set cmdheight=0 laststatus=0 showtabline=0 nowrap scrolloff=1 + silent! set laststatus=0 showtabline=0 signcolumn=0 nowrap scrolloff=1 else - silent! set cmdheight& laststatus& showtabline=2 scrolloff=3 + silent! set laststatus& showtabline& signcolumn& scrolloff& endif endfunc autocmd VimEnter,VimResized * silent call LayoutForSmallTerminal(20) @@ -148,6 +148,7 @@ augroup InitFileTypes augroup Config_Markdown au! au FileType markdown call InitMarkdown() + au FileType markdown let b:in_frontmatter = 0 function! InitMarkdown() setlocal wrap sw=2 ts=2 @@ -159,12 +160,25 @@ augroup InitFileTypes syn match DetailsEnd '^' conceal cchar=E endfunc - " Fold by heading level function! MarkdownLevel() + " For frontmatter + if v:lnum == 1 && getline(1) =~ '^---' + let b:in_frontmatter = 1 + return '>1' + endif + if b:in_frontmatter + if getline(v:lnum) =~ '^---' + let b:in_frontmatter = 0 + return '<1' + else + return '=' + endif + endif + + " Fold for heading and the following contents let hash_num = matchstr(getline(v:lnum), '^#\+') if !empty(hash_num) " HEADING - " return ">"..(len(hash_num) - 1) return len(hash_num) == 1 ? 0 : '>1' else " Contents @@ -173,8 +187,14 @@ augroup InitFileTypes endfunc function! MarkdownFoldTextHeading() + " For frontmatter + if v:foldstart == 1 && getline(v:foldstart) =~ '^---' + return '===FrontMatter===' + endif + + " For heading, foltext() let origin = split(MarkdownFoldText()[2:], ' ') - let heading = substitute(join(origin[:-3], ' '), '\#', ' ', 'g') + let heading = substitute(join(origin[:-3], ' '), '\#', ' ', 'g') let lines = join(origin[-2:], ' ')[1:-2] let fills = repeat('.', 48 - len(heading) - len(lines)) return heading.." "..fills.." "..lines -- cgit v1.2.3-70-g09d2