undotree

repository·master·Indexed 26 days ago

https://github.com/mbbill/undotree

A Vim plugin that visualizes undo history as a tree, enabling users to browse and switch between diverging undo branches created by non-linear edits. Includes features for persistent undo configuration and a visualization panel toggled via :UndotreeToggle.

Tokens
673
Snippets
4
Records
6
Agent score
39%

What's inside undotree

  1. Install undotree using a plugin manager

    master

    Add the following line to your configuration file depending on your plugin manager, then run the corresponding install command:

    • Vundle: Plugin 'mbbill/undotree' (Run :PluginInstall)
    • Vim-Plug: Plug 'mbbill/undotree' (Run :PlugInstall)
    • Packer: use 'mbbill/undotree' (Run :PackerSync)
  2. Install undotree using Vim's built-in package manager

    master

    To install undotree manually using Vim's native package system, run the following commands in your terminal:

    mkdir -p ~/.vim/pack/mbbill/start
    cd ~/.vim/pack/mbbill/start
    git clone https://github.com/mbbill/undotree.git
    vim -u NONE -c "helptags undotree/doc" -c q
  3. Configure persistent undo

    master

    By default, Vim's undo history is lost when the session ends. To persist undo history across sessions, you can configure a dedicated directory in your .vimrc:

    if has("persistent_undo")
       let target_path = expand('~/.undodir')
    
        " create the directory and any parent directories
        if !isdirectory(target_path)
            call mkdir(target_path, "p", 0700)
        endif
    
        let &undodir=target_path
        set undofile
    endif

    Alternatively, you can persist the undo history for only the currently open file by running the command :UndotreePersistUndo.

  4. Debug undotree

    master

    To enable debugging, create a file named undotree_debug.log in your home directory. The plugin will automatically append logs to this file. You can monitor the logs in real-time using tail:

    touch ~/undotree_debug.log
    tail -F ~/undotree_debug.log

    To disable debugging, simply delete the ~/undotree_debug.log file.

  5. Understand undotree markers

    master

    The undotree window uses specific markers to indicate the state of the undo history:

    • > number <: The current state.
    • { number }: The next state that will be restored by :redo or <ctrl-r>.
    • [ number ]: The most recent change.
    • s: Saved changes.
    • S: The most recent saved change.
    • Every change includes a sequence number displayed before the timestamp.
  6. Toggle the undotree panel

    master

    Use the :UndotreeToggle command to open or close the undo-tree visualization panel.

    To map this to a key in your .vimrc (e.g., F5):

    noremap <F5> :UndotreeToggle<CR>

    To map this in Neovim using Lua:

    vim.keymap.set('n', '<leader><F5>', vim.cmd.UndotreeToggle)