sponsor Vim development Vim logo Vim Book Ad

undofile.vim : persistent undo: enable 'undofile' for certain files only

 script karma  Rating 13/4, Downloaded by 1791  Comments, bugs, improvements  Vim wiki

created by
Andy Wokula
 
script type
utility
 
description
If you want 'undofile' only for certain files, you will notice that 'undofile' cannot be set in a modeline, or once the buffer is loaded (because an existing undo file will not be loaded then).  Bram suggests to use a BufReadPre autocmd which sets 'undofile' before the buffer is loaded.  This script does the steps for you.

Usage:

:SetUndoFile[!]

  execute :setlocal undofile, install a BufReadPre autocmd for the current file name and also maintain a plugin file "plugin/undofile_autocmds.vim" that enables all such autocmds at next startup of Vim.

  This means you can execute this command once for the current file and then never ever again -- FIRE AND FORGET ;)

  The plugin file (if not found in the runtimepath) is stored in the first directory of the runtimepath (which must contain a "plugin" folder).  Older Vims will ignore the plugin.

  With [!], ignore if 'undofile' is already set.


:UnsetUndoFile

  opposite of :SetUndoFile.  Does :setlocal noundofile, removes the autcommand and the autcommand entry from "plugin/undofile_autocmds.vim"; finally it executes :DelUndoFile.


:DelUndoFile

  delete the undofile for the current buffer.  Fails silently.

PLEASE REPORT BUGS
 
install details
Note: With Vim 7.3.392 or newer, you can set 'undofile' in the modeline!  No need for this script then ... (2012 Jan 28)

requires the persistent_undo feature (since Vim7.3)
:source this script when needed, or drop it in your plugin folder
 

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
undofile.vim 0.2 2010-08-14 7.0 Andy Wokula forgot the init folklore
undofile.vim 0.1 2010-08-14 7.2 Andy Wokula Initial upload
ip used for rating: 142.132.191.50

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
   
Vim at Github