Saturday, January 21, 2023

Re: Why does (my) Vim leave the cursor to the last mark even if I don't save the file?

* Marvin Renich <mrvn@renich.org> [230121 10:53]:
> * Bram Moolenaar <Bram@moolenaar.net> [230120 11:01]:
> >
> > > I think what he is asking is for the " mark to only be written to the
> > > viminfo file for buffers that have been modified. I'm not sure how to
> > > do this or if it is even possible, but it seems like a perfectly
> > > reasonable behavior to want.
> > >
> > > Perhaps a VimLeavePre autocommand that wipes unmodified buffers? What
> > > other settings for those buffers would not be saved to .viminfo?
> >
> > How about:
> > - When writing the buffer set some flag, e.g. b:did_write_this_buf
> > - When exiting, go through all buffers and those that don't have the
> > b:did_write_this_buf flag move the cursor to the " mark.
> >
> > Something like that.
>
> I don't think we need another flag; just use the 'modified' option. I
> think this is what the OP wants, and is simpler.
>
> I also think Salman Halim's suggestion of using the . mark instead of the
> " mark is more useful.

Note that what the OP wants (don't update " mark for non-modified
buffers) requires changing the code that writes .viminfo, which I think
is in the source, not the runtime.

If you change defaults.vim to use the . mark instead, the OP is going to
get very close to the behavior he wants (he may even like it better than
what he asked for), and no change to the Vim source is needed.

I suspect that most Vim users will prefer the . mark behavior over the
current behavior, but if not, they can easily get the old behavior back;
just leave the old BufReadPost as a comment in defaults.vim, and they
can copy it to their own vimrc.

I think this is the best solution all around.

...Marvin

--
--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/Y8wOqZXZuVPFSJg1%40basil.wdw.

No comments:

Post a Comment