Wednesday, January 21, 2015

Re: Open folds in autocmd makes vim start at strange lines


On Jan 21, 2015 5:45 PM, "Óscar Pereira" <burn.till.skid@gmail.com> wrote:
>
> Dear all,
>
> I wanted a way to make vim, when opening a file, open all folds it
> contained. But *only* when opening the file: if I closed some folds on
> the original file and then switched to another window or buffer, when
> returning to the original one the folds I had closed should remain
> closed. The only way I could solve this was by putting this in my
> .vimrc:
> autocmd BufWinEnter * :call ExpandFoldsOnOpenFile()

This won't solve everything, but you could hook into BufReadPost, I think, to cause it to only happen once:

au BufReadPost * normal zR

>
> function! ExpandFoldsOnOpenFile()
>         if exists("b:did_initial_fold_expansion") | return
>         endif
>         let b:did_initial_fold_expansion = 1
>         normal(zR)
> endfunction
>
> Of course I did *not* want to do this for every file, but before I could
> move that piece of code out of .vimrc, I noticed something strange: when
> opening a lot of files, even ones with no folds, vim would *not* start
> in the file's first line. The most notorious case was mutt: vim would
> start in the first non-blank line (either the signature line or the
> "Reply Original in..." line if replying to a previous mail).
>
> Now my question is... *why* does this happen? I mean, if I open a file
> with no folds, and do "zR", the cursor stays in the same line. I've read
> the docs on folds, but I could not an answer. Ideas anyone?
>
> Thanks,
> --Óscar

Not sure. I have an autocommand to take me where I last left off, but I desire this behavior and cannot speak to what you are seeing.

Salman

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments: