about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRabbit Whispers <us@starfall.systems>2025-08-16 10:16:16 -0500
committerRabbit Whispers <us@starfall.systems>2025-08-16 10:16:16 -0500
commit5c4fb38600e418bd8cb7f18f61c1fe9a6e93ad21 (patch)
tree0a2e640e61c494d3de22be9c39a7308195b12ff3
parent599ded283243a03be5252552cbc7b3bea697c62e (diff)
vim: add subset of vim-yaml-folds plugin HEAD main
-rw-r--r--.vim/ftplugin/yaml.vim40
1 files changed, 40 insertions, 0 deletions
diff --git a/.vim/ftplugin/yaml.vim b/.vim/ftplugin/yaml.vim
index 6b4c519..85d811e 100644
--- a/.vim/ftplugin/yaml.vim
+++ b/.vim/ftplugin/yaml.vim
@@ -1,2 +1,42 @@
 setlocal expandtab shiftwidth=2 softtabstop=2  shiftround
 let b:undo_ftplugin = "setlocal expandtab< shiftwidth< softtabstop< shiftround<"
+
+" vim-yaml-folds by pedrohz <www.vim.org/scripts/script.php?script_id=5559>
+function! YamlFolds()
+	let previous_level = indent(prevnonblank(v:lnum - 1)) / &shiftwidth
+	let current_level = indent(v:lnum) / &shiftwidth
+	let next_level = indent(nextnonblank(v:lnum + 1)) / &shiftwidth
+
+	if getline(v:lnum + 1) =~ '^\s*$'
+		return "="
+
+	elseif current_level < next_level
+		return next_level
+
+	elseif current_level > next_level
+		return ('s' . (current_level - next_level))
+
+	elseif current_level == previous_level
+		return "="
+
+	endif
+
+	return next_level
+endfunction
+
+function! YamlFoldText()
+	let lines = v:foldend - v:foldstart
+	return getline(v:foldstart) . '   (level ' . v:foldlevel . ', lines ' . lines . ')'
+endfunction
+
+
+setlocal foldmethod=expr
+setlocal foldexpr=YamlFolds()
+setlocal foldtext=YamlFoldText()
+
+let b:undo_ftplugin =
+			\ exists('b:undo_ftplugin')
+				\  ? b:undo_ftplugin . ' | '
+				\ : ''
+			\ . 'setlocal foldexpr< foldmethod< foldtext<'
+