From 0d3f526a884d4f24915f2b78fb655a3237898620 Mon Sep 17 00:00:00 2001 From: Ivan Tishchenko Date: Fri, 27 Nov 2015 03:13:25 +0300 Subject: [PATCH] Preserve fold open/close status of the TOC on save. Since TOC is completely recreated, Vim loses its fold open/close status. If your TOC was open, after you save it gets closed. Fix will save fold status, and restore it after TOC is updated. --- autoload/vimwiki/base.vim | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/autoload/vimwiki/base.vim b/autoload/vimwiki/base.vim index da68849..2b8cabd 100644 --- a/autoload/vimwiki/base.vim +++ b/autoload/vimwiki/base.vim @@ -1147,9 +1147,12 @@ function! vimwiki#base#update_listing_in_buffer(strings, start_header, let cursor_line = old_cursor_pos[1] let is_cursor_after_listing = 0 + let is_fold_closed = 1 + let lines_diff = 0 if already_there + let is_fold_closed = ( foldclosed(start_lnum) > 1 ) " delete the old listing let whitespaces_in_first_line = matchstr(getline(start_lnum), '\m^\s*') let end_lnum = start_lnum + 1 @@ -1189,6 +1192,12 @@ function! vimwiki#base#update_listing_in_buffer(strings, start_header, let lines_diff += 1 endif + " Open fold, if needed + if !is_fold_closed + exe start_lnum + norm zo + endif + if is_cursor_after_listing let old_cursor_pos[1] += lines_diff endif