aboutsummaryrefslogtreecommitdiff
path: root/vim
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2018-07-30 10:17:14 +1200
committerTom Ryder <tom@sanctum.geek.nz>2018-07-30 10:17:14 +1200
commitc1057031b7cc9841e1c2ac18798d4e308326b27f (patch)
treed0a255eda31a528da9d01383c1ab31e40bf58ef7 /vim
parentCorrect syntax of new map (diff)
downloaddotfiles-c1057031b7cc9841e1c2ac18798d4e308326b27f.tar.gz
dotfiles-c1057031b7cc9841e1c2ac18798d4e308326b27f.zip
Add foldlevelstart_stdin.vim plugin
This makes 'foldlevelstart' work for stdin reads.
Diffstat (limited to 'vim')
-rw-r--r--vim/plugin/foldlevelstart_stdin.vim28
1 files changed, 28 insertions, 0 deletions
diff --git a/vim/plugin/foldlevelstart_stdin.vim b/vim/plugin/foldlevelstart_stdin.vim
new file mode 100644
index 00000000..4edffb16
--- /dev/null
+++ b/vim/plugin/foldlevelstart_stdin.vim
@@ -0,0 +1,28 @@
+"
+" foldlevelstart_stdin.vim: Set 'foldlevel' to 'foldlevelstart' after reading
+" from standard input, which Vim doesn't do by default.
+"
+" Author: Tom Ryder <tom@sanctum.geek.nz>
+" License: Same as Vim itself
+"
+if exists('g:loaded_foldlevelstart_stdin') || &compatible
+ finish
+endif
+if !has('autocmd') || !has('folding') || !exists('##StdinReadPre')
+ finish
+endif
+let g:loaded_foldlevelstart_stdin = 1
+
+" Check if 'foldlevelstart' is non-negative, and set 'foldlevel' to its value
+" if it is
+function! s:SetFoldlevel()
+ if &foldlevelstart >= 0
+ let &l:foldlevel = &foldlevelstart
+ endif
+endfunction
+
+" Watch for stdin reads and set fold level accordingly
+augroup foldlevelstart_stdin
+ autocmd!
+ autocmd StdinReadPre * call s:SetFoldlevel()
+augroup END