Skip to content

Commit 8e6be34

Browse files
committed
patch 8.2.2039: viminfo is not written when creating a new file
Problem: Viminfo is not written when creating a new file. Solution: Set "b_marks_read" in the new buffer. (Christian Brabandt, closes #7350)
1 parent 142f235 commit 8e6be34

3 files changed

Lines changed: 38 additions & 0 deletions

File tree

src/bufwrite.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2579,6 +2579,12 @@ buf_write(
25792579
#endif
25802580
}
25812581

2582+
#ifdef FEAT_VIMINFO
2583+
// Make sure marks will be written out to the viminfo file later, even when
2584+
// the file is new.
2585+
curbuf->b_marks_read = TRUE;
2586+
#endif
2587+
25822588
got_int |= prev_got_int;
25832589

25842590
return retval;

src/testdir/test_viminfo.vim

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
" Test for reading and writing .viminfo
22

33
source check.vim
4+
source term_util.vim
5+
source shared.vim
46

57
function Test_viminfo_read_and_write()
68
" First clear 'history', so that "hislen" is zero. Then set it again,
@@ -879,4 +881,32 @@ func Test_viminfo_option_error()
879881
call assert_fails('set viminfo=%10', 'E528:')
880882
endfunc
881883

884+
func Test_viminfo_oldfiles_newfile()
885+
CheckRunVimInTerminal
886+
887+
let save_viminfo = &viminfo
888+
let save_viminfofile = &viminfofile
889+
set viminfo&vim
890+
let v:oldfiles = []
891+
let commands =<< trim [CODE]
892+
set viminfofile=Xviminfofile
893+
set viminfo&vim
894+
w! Xnew-file.txt
895+
qall
896+
[CODE]
897+
call writefile(commands, 'Xviminfotest')
898+
let buf = RunVimInTerminal('-S Xviminfotest', #{wait_for_ruler: 0})
899+
call WaitForAssert({-> assert_equal("finished", term_getstatus(buf))})
900+
901+
let &viminfofile = 'Xviminfofile'
902+
rviminfo! Xviminfofile
903+
call assert_match('Xnew-file.txt$', v:oldfiles[0])
904+
call assert_equal(1, len(v:oldfiles))
905+
call delete('Xviminfofile')
906+
call delete('Xviminfotest')
907+
call delete('Xnew-file.txt')
908+
let &viminfo = save_viminfo
909+
let &viminfofile = save_viminfofile
910+
endfunc
911+
882912
" vim: shiftwidth=2 sts=2 expandtab

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,8 @@ static char *(features[]) =
750750

751751
static int included_patches[] =
752752
{ /* Add new patch number below this line */
753+
/**/
754+
2039,
753755
/**/
754756
2038,
755757
/**/

0 commit comments

Comments
 (0)