Disabling persistent undo for a file mask

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Disabling persistent undo for a file mask

RingoRangoRongo
Hi!


In order to disable persistent undo for a file mask I have the following command in my .vimdc:

    autocmd! BufRead,BufWrite *.sec setlocal ul=-1

However, I noticed the following strange behaviour:

1. I save an empty buffer with :saveas file.sec command: no undo file present
2. I add text and save this now named buffer with :write command: undo file appears
3. I add more text and save this buffer again with :write command: undo file disappears.

How do I escape the appearance of the undo file at the second step? What should I add to my autocmd?

Vim ver:
VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Jan 24 2017 00:42:53)
MacOS X (unix) version
Included patches: 1-222
Compiled by Homebrew


Thanks!

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Disabling persistent undo for a file mask

Ben Fritz
On Wednesday, February 22, 2017 at 12:23:16 AM UTC-6, RingoRangoRongo wrote:

> Hi!
>
>
> In order to disable persistent undo for a file mask I have the following command in my .vimdc:
>
>     autocmd! BufRead,BufWrite *.sec setlocal ul=-1
>
> However, I noticed the following strange behaviour:
>
> 1. I save an empty buffer with :saveas file.sec command: no undo file present
> 2. I add text and save this now named buffer with :write command: undo file appears
> 3. I add more text and save this buffer again with :write command: undo file disappears.
>
> How do I escape the appearance of the undo file at the second step? What should I add to my autocmd?
>
What other commands do you have in your .vimrc to enable the undo file for other file types? I'd guess you have an interference going on.

It's probably not related to your current problem, but you probably also want a BufNewFile autocmd event in there.

Also, why are you using "setlocal undolevels=-1" instead of "setlocal noundofile", if you goal is only to disable persistent undo? Setting undolevels to -1 disables undo *entirely*, not just persistent undo, so that pressing 'u' in normal mode while you edit will do nothing.

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Disabling persistent undo for a file mask

RingoRangoRongo
On Wednesday, February 22, 2017 at 5:21:20 PM UTC+2, Ben Fritz wrote:

> What other commands do you have in your .vimrc to enable the undo file for other file types? I'd guess you have an interference going on.

Nothing except this:

set undofile
set undodir=~/.vim/tmp//

No filetype is specified for that (*.sec) particular extension, too.

> It's probably not related to your current problem, but you probably also want a BufNewFile autocmd event in there.

I've tried that, too. No changes: the undofile appears at the second step and disappears at the third.

> Also, why are you using "setlocal undolevels=-1" instead of "setlocal noundofile", if you goal is only to disable persistent undo. Setting undolevels to -1 disables undo *entirely*.

Well, that's my purpose :). Sorry for somewhat misleading subject.

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Disabling persistent undo for a file mask

Ben Fritz
On Wednesday, February 22, 2017 at 9:45:02 AM UTC-6, RingoRangoRongo wrote:
> On Wednesday, February 22, 2017 at 5:21:20 PM UTC+2, Ben Fritz wrote:
> > Also, why are you using "setlocal undolevels=-1" instead of "setlocal noundofile", if you goal is only to disable persistent undo. Setting undolevels to -1 disables undo *entirely*.
>
> Well, that's my purpose :). Sorry for somewhat misleading subject.

Assuming this is reliably repeatable, before performing the :w command that would create the undo file, do this to see what undolevels is and which script last changed it:

:verbose set undolevels?

Do it again after the :w to see if it has changed.

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Disabling persistent undo for a file mask

RingoRangoRongo
On Thursday, February 23, 2017 at 6:10:27 PM UTC+2, Ben Fritz wrote:
> Assuming this is reliably repeatable, before performing the :w command that would create the undo file, do this to see what undolevels is and which script last changed it:
>
> :verbose set undolevels?


0. empty buffer:
  undolevels=1000
1. I save an empty buffer with :saveas file.sec command: no undo file present
  undolevels=-1
        Last set from ~/.vimrc
2. I add text and save this now named buffer with :write command: undo file appears
  undolevels=-1
        Last set from ~/.vimrc
3. I add more text and save this buffer again with :write command: undo file disappears.
  undolevels=-1
        Last set from ~/.vimrc

That flashing undo file looks like this: http://i.imgur.com/84Dt8g8.png

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Disabling persistent undo for a file mask

RingoRangoRongo
Just confirmed same behaviour with VIM - Vi IMproved 7.3 (vim -u NONE):

:set undolevels=1000
:set undofile
:set undodir
:autocmd BufNewFile,BufRead,BufWrite *.sec setlocal ul=-1

:sav test.sec " no undo file exists

insert random text

:w " undo file appears

insert more random test

:w " undo file disappears

Looks like a bug? :)

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Disabling persistent undo for a file mask

Charles Campbell
RingoRangoRongo wrote:

> Just confirmed same behaviour with VIM - Vi IMproved 7.3 (vim -u NONE):
>
> :set undolevels=1000
> :set undofile
> :set undodir
> :autocmd BufNewFile,BufRead,BufWrite *.sec setlocal ul=-1
>
> :sav test.sec " no undo file exists
>
> insert random text
>
> :w " undo file appears
>
> insert more random test
>
> :w " undo file disappears
>
> Looks like a bug? :)
>
Just tried the attached minimal file along with the commands:

vim -u rrr
:saveas! file.sec
i one two<esc>
:w
i three four<esc>
:w

Comments: nothing in $HOME/VITMP ever appeared, and I checked before
starting and after every saveas and write, using vim 8.0.189 .

Regards,
Chip Campbell

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.

rrr (168 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Disabling persistent undo for a file mask

RingoRangoRongo
On Thursday, February 23, 2017 at 9:09:58 PM UTC+2, Charles Campbell wrote:

> Just tried the attached minimal file along with the commands:

[…]

Well, you are also setting noundofile. And while this is a solution to my question (and I dothank you for it, and also blame myself for not thinking about this obvious step :), I'd still say that if undolevels is set to -1, undofile should not appear at all.

Nonetheless, thanks again :).

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Disabling persistent undo for a file mask

Christian Brabandt
In reply to this post by RingoRangoRongo
Hi RingoRangoRongo!

On Do, 23 Feb 2017, RingoRangoRongo wrote:

> Just confirmed same behaviour with VIM - Vi IMproved 7.3 (vim -u NONE):
>
> :set undolevels=1000
> :set undofile
> :set undodir
> :autocmd BufNewFile,BufRead,BufWrite *.sec setlocal ul=-1
>
> :sav test.sec " no undo file exists
>
> insert random text
>
> :w " undo file appears
>
> insert more random test
>
> :w " undo file disappears
>
> Looks like a bug? :)

Vim will write an undofile (call the internal C function u_write_undo()
for writing the undo file), if the undofile option is set, which it is
in your case. Now you have just set undolevels to -1, but the undo
information is only discarded, if another step has to be saved for undo,
until then the undo information is still kept in memory (and written out
to a file, if you write the file). Once the undo history has been
purged, Vim the internal C function u_write_undo() will skip writing the
file after it has deleted the old file.

Setting 'verbose' to a higher value might also give some clues. The
writeundofile function gives some status then.

Back then when undo persistence was implemented, there were quite some
discussions if one should have another function for discarding the undo
information (there is also a Debian wishlist bug open for that I think).
I think I have even made a patch for that. But in the end it was never
done, because a simple change is enough to purge the undo state (e.g.
https://github.com/chrisbra/histwin.vim/blob/master/autoload/histwin.vim#L1049-L1072)

Best,
Christian
--
Die Wissenschaft ist der Verstand der Welt, die Kunst ihre Seele.
                -- Maxim Gorkij

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Disabling persistent undo for a file mask

RingoRangoRongo
On Thursday, February 23, 2017 at 10:43:01 PM UTC+2, Christian Brabandt wrote:

Thanks for the explanation, Christian!

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Loading...