How to let previous opened fold open reentering vim buffer.

22 views
Skip to first unread message

Ni Va

unread,
Sep 27, 2019, 11:58:23 AM9/27/19
to vim_use
Hi,


I try this in _vimrc in order to let a previous opened fold, opened when I re enter buffer.

in _vimrc:
if has("autocmd")
silent autocmd! BufEnter *.vim norm za
endif

example of vim buffer :

function! sequencerutil#echomsg(startreltime,str) abort  " timestamp stolen from codi sorry :){{{
let seconds_and_microseconds = reltimestr(reltime(a:startreltime))
let decimal_i = stridx(seconds_and_microseconds, '.')
let seconds = seconds_and_microseconds[:decimal_i - 1]
let microseconds = seconds_and_microseconds[decimal_i + 1:]
let timestamp = strftime("%T.".microseconds, seconds)
echomsg strftime('%Y/%m/%d %T.').printf("%.3s",microseconds).printf(" %.3s secs %s", seconds, a:str)
endfunc "}}}
" vim: set ft=vim ff=dos fdm=marker ts=4 :expandtab:



It seems to not doing what I attempt but why ?

Thanks in advance.
NiVa

Enno

unread,
Oct 2, 2019, 7:12:17 AM10/2/19
to vim_use
The command `za` toggles the fold. Try instead

silent autocmd! BufEnter *.vim normal! zv

to open sufficiently many folds to show the line where the cursor is at.

Ni Va

unread,
Oct 2, 2019, 7:33:56 AM10/2/19
to vim_use

Seems to not working..
It's disturbing that previsou opened fold is closed just when leaving and re entering the same buffer.
vim.gif

Ni Va

unread,
Oct 10, 2019, 4:50:24 AM10/10/19
to vim_use
This code well do the calling of func AvoidFolding when entering buffer but it returns E490 no fold found.

fun! AvoidFolding() 
  normal! zx
  normal! zv
  normal! za
endfunction
if has("autocmd")

  " augroup vimrc
  au!
" Avoid folding
autocmd BufEnter *.vim       :call AvoidFolding()
autocmd BufEnter $VIM/_vimrc :call AvoidFolding()
  " augroup END

endif " has("autocmd")
Reply all
Reply to author
Forward
0 new messages