T. Borgmann
unread,Dec 18, 2008, 2:14:28 PM12/18/08Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to vim_use
Thanks for your appreciation, folks!
Well yes you're right, but restoring my foldings manually would
require me to assimilate two more shortcuts into my brain ;)
Here is my temporary solution, temporary, because it shows an
unexpected behaviour which is also unwanted but not as disattracting
to me like all following folds to get opened.
My approach uses the "InsertEnter" and "InsertLeave" events called -
you guess it - when entering or leaving insert mode.
I wrote two functions for theese events to store the current folding
mehtod (foldmethod, e.g. foldmehtod=syntax ;) ) into a temporary
variable, which shall reside in the same scope than "foldmethod"
itself does. Therefore it should be as window dependend as
"foldmethod" is. The temporarily stored original fold method is then
restored when leaving insertion mode. During insertion mode,
"foldmethod" is set to "manual" which should be most applicable.
Now comes the drawback. For some reason, all new top-level functions
writting during this "manual-mode-insertion-session" become folded. I
think the reason for that might be vim reparsing for folding issues
automatically when changing the fold method used.
Nevertheless new text inserted in some existing functions does not
become folded.
Anyway, I'm much more pleased with that - in fact, autofolding my new
function can also be seen as a handy feature - solution, than with the
standard behaviour.
So, here it is. I pasted it into my .gvimrc, if you are more strict
than me concerning file integrety, you might want to put theese lines
into a .vim file and put it into your plugins directory.
Any comments & proposals etc. are most welcome and forgive me, this is
my very first self-made-function-based script (after about 7 years of
using the worlds best editor)
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" for correct syntax-folding while inserting new text/code
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
function PreserveFoldingsEnter()
let w:preservedMethod = &foldmethod
let &foldmethod="manual"
endfunction
function PreserveFoldingsLeave()
let &foldmethod=w:preservedMethod
endfunction
autocmd InsertEnter * call PreserveFoldingsEnter()
autocmd InsertLeave * call PreserveFoldingsLeave()
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""