diff options
-rw-r--r-- | README.md | 13 | ||||
-rw-r--r-- | VERSION | 1 | ||||
-rw-r--r-- | doc/foldlevelstart_stdin.txt | 21 | ||||
-rw-r--r-- | plugin/foldlevelstart_stdin.vim | 28 |
4 files changed, 63 insertions, 0 deletions
diff --git a/README.md b/README.md new file mode 100644 index 0000000..3087e91 --- /dev/null +++ b/README.md @@ -0,0 +1,13 @@ +foldlevelstart\_stdin.vim +========================= + +This tiny plugin sets `'foldlevel'` to `'foldlevelstart'` after reading from +standard input, which Vim doesn't do by default. + +License +------- + +Copyright (c) [Tom Ryder][1]. Distributed under the same terms as Vim itself. +See `:help license`. + +[1]: https://sanctum.geek.nz/ @@ -0,0 +1 @@ +0.1.0 diff --git a/doc/foldlevelstart_stdin.txt b/doc/foldlevelstart_stdin.txt new file mode 100644 index 0000000..97945c3 --- /dev/null +++ b/doc/foldlevelstart_stdin.txt @@ -0,0 +1,21 @@ +*foldlevelstart_stdin.txt* For Vim version 7.0 Last change: 2018 Aug 16 + +DESCRIPTION *foldlevelstart_stdin* + +This tiny plugin sets 'foldlevel' to 'foldlevelstart' after reading from +standard input, which Vim doesn't do by default. + +REQUIREMENTS *foldlevelstart_stdin-requirements* + +This plugin only loads if 'compatible' is not set. It requires the |+autocmd|, +and |+folding| features, with the |StdinReadPre| event introduced in Vim. + +AUTHOR *foldlevelstart_stdin-author* + +Written and maintained by Tom Ryder <tom@sanctum.geek.nz>. + +LICENSE *foldlevelstart_stdin-license* + +Licensed for distribution under the same terms as Vim itself (see |license|). + + vim:tw=78:ts=8:ft=help:norl: 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 <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() 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 |