From 77d9d2c3ee865f6334ffda5d665ecb6cdf0541cd Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Thu, 16 Aug 2018 22:21:34 +1200 Subject: First version --- plugin/foldlevelstart_stdin.vim | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 plugin/foldlevelstart_stdin.vim (limited to 'plugin') diff --git a/plugin/foldlevelstart_stdin.vim b/plugin/foldlevelstart_stdin.vim new file mode 100644 index 0000000..f8e4d50 --- /dev/null +++ b/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 +" 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() abort + 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 -- cgit v1.2.3