chrisbra / Recover.vim

A Plugin to show a diff, whenever recovering a buffer
http://www.vim.org/scripts/script.php?script_id=3068
247 stars 25 forks source link

Some viminfo history reset #41

Closed ghost closed 7 years ago

ghost commented 7 years ago

With 'history' greater than 50, and more than fifty entries for the command line history in .viminfo, opening the same file in two instances of Vim will reset the saved history to 50. The real world use case that I keep getting this is when I do a vimdiff with two files, one of which I have open already in some other Vim instance. I lose my older (but useful!) history.

With only "set history=5000" in vimrc, only Recover.vim installed, and more than fifty ":" entries in viminfo (grep -c '^:' .viminfo), steps to replicate:

  1. vim wibble
  2. Open another window, or put the current vim into the background
  3. vim wibble - the same file. The "Please choose:" prompt appears
  4. Note that the number of ":" entries in viminfo have reduced to 50
chrisbra commented 7 years ago

Hm, can you check, if this patch fixes it:

diff --git a/autoload/recover.vim b/autoload/recover.vim
index b1653af..bb130db 100755
--- a/autoload/recover.vim
+++ b/autoload/recover.vim
@@ -110,7 +110,7 @@ fu! recover#ConfirmSwapDiff() "{{{1
        "   let wincmd = printf('-c "redir > %s|1d|:q!" ', tfile)
        "   let wincmd = printf('-c "call feedkeys(\"o\n\e:q!\n\")"')
        " endif
-       let cmd = printf("%s %s -u NONE -es -V %s %s",
+       let cmd = printf("%s %s -i NONE -u NONE -es -V %s %s",
            \ (s:isWin() ? '' : 'TERM=vt100 LC_ALL=C'),
            \ s:progpath,
            \ (s:isWin() ? wincmd : ''),
ghost commented 7 years ago

No difference, unfortunately.

ghost commented 7 years ago

Now that I knew where to look, I found what appears to be the cause:

diff -ur .vim.old/autoload/recover.vim .vim/autoload/recover.vim
--- .vim.old/autoload/recover.vim   2016-10-01 14:20:29.221611463 +0100
+++ .vim/autoload/recover.vim   2016-10-01 14:20:55.082618673 +0100
@@ -147,7 +147,7 @@
    if s:isWin()
        let tfile = substitute(tfile, '/', '\\', 'g')
    endif
-   let cmd = printf("%s -u NONE -N %s -r %s -c \":w %s|:q!\" %s diff %s %s",
+   let cmd = printf("%s -i NONE -u NONE -N %s -r %s -c \":w %s|:q!\" %s diff %s %s",
            \ s:progpath,
            \ (s:isWin() ? '' : '-es'),
            \ (s:isWin() ? fnamemodify(v:swapname, ':p:8') : shellescape(v:swapname)),

Which is odd, because I can see with some debugging that the cmd in your patch above is indeed being executed, but viminfo doesn't change at that point. The cmd in my patch is also being executed, and that's when viminfo changes. (I can tell when it changes because I put some sleeps just after the calls to system(cmd)).

ghost commented 7 years ago

Ah, this appears to mess up when recovering…

ghost commented 7 years ago

I've made both changes together and it seems OK. I'll create a pull request.