Using Vim's persistent undo?

前端 未结 5 877
独厮守ぢ
独厮守ぢ 2020-12-23 08:39

One of the new features in Vim 7.3 is \'persistent undo\', which allows for the undotree to be saved to a file when exiting a buffer.

Unfortunately, I haven\'t quite

相关标签:
5条回答
  • 2020-12-23 09:21

    Put this in your .vimrc to create an undodir if it doesn't exist and enable persistent undo. Tested on both Windows and Linux.

    " Put plugins and dictionaries in this dir (also on Windows)
    let vimDir = '$HOME/.vim'
    let &runtimepath.=','.vimDir
    
    " Keep undo history across sessions by storing it in a file
    if has('persistent_undo')
        let myUndoDir = expand(vimDir . '/undodir')
        " Create dirs
        call system('mkdir ' . vimDir)
        call system('mkdir ' . myUndoDir)
        let &undodir = myUndoDir
        set undofile
    endif
    
    0 讨论(0)
  • 2020-12-23 09:29

    I suppose $HOME doesn't work as advertised.

    On my system, :echo $HOME shows H:\, but : e $HOME/ says: ~/ invalid filename.

    You could try with an absolute path to see whether it cures it

    0 讨论(0)
  • 2020-12-23 09:36

    If you are looking for %TEMP%.(filename).un~ you won't find it

    The filename will be something line C%%Users%%(username)%_vimrc

    I have no idea why

    0 讨论(0)
  • I tried this in my _gvimrc:

    " Persistent undo
    try 
        set undodir=C:\vim\undodir
        set undofile
    catch
    endtry
    

    It started working as advertised when I deleted the try-catch bracket, thus:

    " Persistent undo
    set undodir=C:\vim\undodir
    set undofile
    

    I had to create the directory.

    0 讨论(0)
  • This now works as expected: file.txt open in a Vim 7.4 buffer on Windows 7, :setlocal undofile, then save a change to the buffer, and the undofile .file.txt.un~ is created alongside because :set undodir? reports that "undodir=." by default - ie no need to specify this manually. You can also :set undofile in a modeline.

    0 讨论(0)
提交回复
热议问题