aboutsummaryrefslogtreecommitdiffhomepage
path: root/vim
diff options
context:
space:
mode:
authorHsieh Chin Fan <pham@topo.tw>2024-11-06 23:18:40 +0800
committerHsieh Chin Fan <pham@topo.tw>2024-11-06 23:18:40 +0800
commit5bc85b9ce603bfc52808164da7264b5b0ad29bc9 (patch)
treede29454dd24cebf5b2265b9a3bf7207f407eea9e /vim
parent6571b18686e1bb5c77948a21d4ad74d29c646d1d (diff)
Update
Diffstat (limited to 'vim')
-rw-r--r--vim/init/config.vim17
1 files changed, 14 insertions, 3 deletions
diff --git a/vim/init/config.vim b/vim/init/config.vim
index ce81f8a..8be42b4 100644
--- a/vim/init/config.vim
+++ b/vim/init/config.vim
@@ -159,6 +159,7 @@ augroup InitFileTypes
159 nnoremap \fl :let markdown_apply_heading_level = !markdown_apply_heading_level<CR>zX 159 nnoremap \fl :let markdown_apply_heading_level = !markdown_apply_heading_level<CR>zX
160 160
161 let b:in_frontmatter = 0 161 let b:in_frontmatter = 0
162 let b:insideCodeBlock = 0
162 setlocal foldexpr=MarkdownLevel() foldmethod=expr 163 setlocal foldexpr=MarkdownLevel() foldmethod=expr
163 setlocal foldtext=MarkdownFoldTextHeading() 164 setlocal foldtext=MarkdownFoldTextHeading()
164 165
@@ -173,13 +174,15 @@ augroup InitFileTypes
173 endfunc 174 endfunc
174 175
175 function! MarkdownLevel() 176 function! MarkdownLevel()
177 let line = getline(v:lnum)
178
176 " For frontmatter 179 " For frontmatter
177 if v:lnum == 1 && getline(1) =~ '^---' 180 if v:lnum == 1 && getline(1) =~ '^---'
178 let b:in_frontmatter = 1 181 let b:in_frontmatter = 1
179 return '>1' 182 return '>1'
180 endif 183 endif
181 if b:in_frontmatter 184 if b:in_frontmatter
182 if getline(v:lnum) =~ '^---' 185 if line =~ '^---'
183 let b:in_frontmatter = 0 186 let b:in_frontmatter = 0
184 return '<1' 187 return '<1'
185 else 188 else
@@ -187,13 +190,21 @@ augroup InitFileTypes
187 endif 190 endif
188 endif 191 endif
189 192
193 " Codeblock Switching
194 if line =~ '^```'
195 let b:insideCodeBlock = b:insideCodeBlock == 1 ? 0 : 1
196 endif
197 if b:insideCodeBlock == 1
198 return '='
199 endif
200
190 " Fold for heading and the following contents 201 " Fold for heading and the following contents
191 let hash_num = matchstr(getline(v:lnum), '^\zs#\+\ze\s') 202 let hash_num = matchstr(line, '^\zs#\+\ze\s')
192 if !empty(hash_num) 203 if !empty(hash_num)
193 let foldlevel = g:markdown_apply_heading_level ? len(hash_num) - 1 : 1 204 let foldlevel = g:markdown_apply_heading_level ? len(hash_num) - 1 : 1
194 " HEADING 205 " HEADING
195 return len(hash_num) == 1 ? 0 : '>'.foldlevel 206 return len(hash_num) == 1 ? 0 : '>'.foldlevel
196 elseif match(getline(v:lnum), '^----') != -1 207 elseif match(line, '^----') != -1
197 return "<" 208 return "<"
198 else 209 else
199 " Contents 210 " Contents