Top Related Projects
fzf :heart: vim
A tree explorer plugin for vim.
fugitive.vim: A Git wrapper so awesome, it should be illegal
A Vim plugin which shows git diff markers in the sign column and stages/previews/undoes hunks and partial hunks.
lean & mean status/tabline for vim that's light as air
Check syntax in Vim/Neovim asynchronously and fix files, with Language Server Protocol (LSP) support
Quick Overview
Undotree is a Vim plugin that visualizes the undo history of a file as a tree structure. It allows users to navigate through different versions of their document, making it easier to understand and manage complex editing histories.
Pros
- Provides a clear, visual representation of the undo history
- Allows easy navigation between different versions of a document
- Supports persistent undo, enabling access to previous versions even after closing and reopening Vim
- Integrates seamlessly with Vim's native undo/redo functionality
Cons
- May have a learning curve for users unfamiliar with tree-based undo systems
- Can potentially slow down Vim performance on very large files with extensive editing histories
- Requires manual installation and configuration, which might be challenging for some users
Getting Started
To install Undotree using Vim-Plug, add the following line to your .vimrc
file:
Plug 'mbbill/undotree'
Then run :PlugInstall
in Vim.
To use Undotree, add a key mapping to your .vimrc
:
nnoremap <F5> :UndotreeToggle<CR>
Now you can press F5 to toggle the Undotree panel. Navigate through the tree using Vim's normal movement keys, and press Enter to revert to a specific version.
For persistent undo, add these lines to your .vimrc
:
if has("persistent_undo")
let target_path = expand('~/.undodir')
if !isdirectory(target_path)
call mkdir(target_path, "p", 0700)
endif
let &undodir=target_path
set undofile
endif
This will save your undo history even after closing Vim, allowing you to access previous versions in future editing sessions.
Competitor Comparisons
fzf :heart: vim
Pros of fzf.vim
- Offers powerful fuzzy finding capabilities across various Vim elements (files, buffers, tags, etc.)
- Provides a highly customizable and extensible interface
- Integrates seamlessly with the fzf command-line tool for enhanced performance
Cons of fzf.vim
- Requires external dependencies (fzf command-line tool)
- Has a steeper learning curve due to its extensive feature set
- May have a higher performance overhead for large projects
Code Comparison
fzf.vim:
" Fuzzy find files in the current directory
nnoremap <C-p> :Files<CR>
" Fuzzy find lines in the current buffer
nnoremap <Leader>l :BLines<CR>
undotree:
" Toggle undotree window
nnoremap <F5> :UndotreeToggle<CR>
" Set undotree window width
let g:undotree_SplitWidth = 30
Summary
fzf.vim is a powerful fuzzy finder plugin that enhances Vim's search capabilities across various elements, while undotree focuses specifically on visualizing and navigating the undo history. fzf.vim offers more extensive functionality but requires external dependencies, whereas undotree is more focused and self-contained. The choice between the two depends on whether you prioritize comprehensive fuzzy finding or specialized undo history management.
A tree explorer plugin for vim.
Pros of NERDTree
- Provides a file system explorer sidebar for easy navigation
- Supports bookmarks and custom mappings for quick access
- Offers file operations like create, delete, and rename directly from the tree
Cons of NERDTree
- Can be resource-intensive for large projects
- May clutter the Vim interface, especially on smaller screens
- Requires manual refresh to reflect file system changes
Code Comparison
NERDTree:
let g:NERDTreeShowHidden = 1
let g:NERDTreeMinimalUI = 1
let g:NERDTreeIgnore = []
let g:NERDTreeStatusline = ''
undotree:
if has("persistent_undo")
let target_path = expand('~/.undodir')
set undofile
let &undodir=target_path
endif
NERDTree focuses on file system navigation and management, while undotree specializes in visualizing and navigating Vim's undo history. NERDTree's code typically involves configuration options for appearance and behavior, whereas undotree's setup often relates to persistent undo functionality and undo file management.
fugitive.vim: A Git wrapper so awesome, it should be illegal
Pros of vim-fugitive
- Comprehensive Git integration within Vim
- Powerful commands for staging, committing, and resolving conflicts
- Seamless workflow for managing Git repositories without leaving the editor
Cons of vim-fugitive
- Steeper learning curve due to numerous commands and features
- May be overwhelming for users who only need basic Git functionality
- Requires more setup and configuration for optimal use
Code comparison
vim-fugitive:
:Gstatus
:Gcommit
:Gpush
:Gblame
undotree:
:UndotreeToggle
Key differences
- Purpose: vim-fugitive is a Git wrapper, while undotree focuses on visualizing Vim's undo history
- Scope: vim-fugitive offers extensive Git functionality, undotree specializes in undo management
- Complexity: vim-fugitive has a broader feature set, undotree is more focused and simpler to use
Use cases
vim-fugitive is ideal for developers who frequently work with Git and want deep integration within Vim. undotree is better suited for users who prioritize visualizing and navigating their editing history within a single file.
A Vim plugin which shows git diff markers in the sign column and stages/previews/undoes hunks and partial hunks.
Pros of vim-gitgutter
- Real-time Git diff information in the sign column
- Lightweight and fast, with minimal impact on Vim performance
- Provides hunk staging and undoing functionality
Cons of vim-gitgutter
- Limited to Git-specific functionality
- Doesn't provide a comprehensive undo history visualization
Code comparison
vim-gitgutter:
let g:gitgutter_sign_added = '+'
let g:gitgutter_sign_modified = '~'
let g:gitgutter_sign_removed = '-'
let g:gitgutter_max_signs = 500
undotree:
let g:undotree_WindowLayout = 2
let g:undotree_ShortIndicators = 1
let g:undotree_SplitWidth = 24
let g:undotree_DiffpanelHeight = 8
Key differences
undotree focuses on visualizing and navigating Vim's undo history, providing a tree-like structure for all changes made to a file. It offers a more comprehensive view of file modifications over time, regardless of version control.
vim-gitgutter, on the other hand, specializes in displaying Git-specific information, such as added, modified, or removed lines, directly in the Vim editor. It integrates tightly with Git workflows but doesn't provide the same level of undo history visualization as undotree.
While both plugins enhance Vim's functionality, they serve different purposes: undotree for managing complex undo histories, and vim-gitgutter for real-time Git integration within the editor.
lean & mean status/tabline for vim that's light as air
Pros of vim-airline
- Enhances the Vim status line with useful information and visual appeal
- Supports a wide range of plugins and integrations
- Highly customizable with themes and extensions
Cons of vim-airline
- Can slow down Vim performance, especially on larger files
- Requires more configuration to achieve desired functionality
- May conflict with other status line plugins
Code Comparison
vim-airline:
let g:airline#extensions#tabline#enabled = 1
let g:airline_theme='solarized'
let g:airline_powerline_fonts = 1
undotree:
nnoremap <F5> :UndotreeToggle<CR>
if !exists('g:undotree_WindowLayout')
let g:undotree_WindowLayout = 2
endif
Key Differences
- Purpose: vim-airline focuses on enhancing the status line, while undotree provides undo history visualization
- Complexity: vim-airline is more feature-rich and complex, undotree is simpler and focused
- Performance impact: vim-airline may have a higher performance overhead compared to undotree
- Integration: vim-airline integrates with many plugins, undotree is a standalone tool
Use Cases
- vim-airline: For users who want a comprehensive status line with extensive information and customization options
- undotree: For developers who frequently need to navigate and manage complex undo histories in their workflows
Check syntax in Vim/Neovim asynchronously and fix files, with Language Server Protocol (LSP) support
Pros of ALE
- Provides real-time linting and fixing for multiple languages
- Integrates with various external tools for code analysis
- Offers asynchronous execution for better performance
Cons of ALE
- Can be more complex to set up and configure
- May have higher resource usage due to its extensive features
- Potential for false positives in linting results
Code Comparison
ALE (example configuration):
let g:ale_linters = {
\ 'javascript': ['eslint'],
\ 'python': ['flake8'],
\}
let g:ale_fixers = {
\ '*': ['remove_trailing_lines', 'trim_whitespace'],
\}
Undotree (example usage):
nnoremap <F5> :UndotreeToggle<CR>
if !exists('g:undotree_WindowLayout')
let g:undotree_WindowLayout = 2
endif
While ALE focuses on linting and fixing code across multiple languages, Undotree specializes in visualizing and navigating Vim's undo history. ALE is more feature-rich but potentially more resource-intensive, while Undotree is simpler and more focused on a specific task. The choice between them depends on whether you need comprehensive code analysis or enhanced undo functionality in your Vim setup.
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Project on Vim.org
Screenshot
Table of Contents
Description
Undotree visualizes the undo history and makes it easy to browse and switch between different undo branches. You may be wondering, what are undo "branches" anyway? They're a feature of Vim that allow you to go back to a prior state even after it has been overwritten by later edits. For example: In most editors, if you make some change A, followed by change B, then go back to A and make another change C, normally you wouldn't be able to go back to change B because the undo history is linear. That's not the case with Vim, however. Vim internally stores the entire edit history for each file as a single, monolithic tree structure; this plug-in exposes that tree to you so that you can not only switch back and forth between older and more recent edits linearly but can also switch between diverging branches.
Note: use
:help 'undolevels'
in Vim for information on configuring the size of the undo history
How it works
Some users may have questions about whether file contents change when switching between undo history states. With undotree, you don't need to worry about data loss or disk writes. The plugin will never save your data or write to disk. Instead, it modifies the current buffer temporarily, just like auto-completion plugins do. This means that any changes made by undotree are reversible with a single click, allowing you to easily revert to any prior state.
Vim's undo/redo feature is a great way to protect your work from accidental changes or data loss. Unlike other editors, where undoing and then accidentally typing something can cause you to lose your edits, Vim allows you to revert to previous states without losing any data, as long as you keep the Vim session alive. If you want to keep your undo history permanently, Vim offers a persistent undo feature. This feature saves your undo history to a file on disk, allowing you to preserve your undo history across editing sessions. To enable persistent undo, refer to the instructions below. This can be a useful option for those who want to maintain a long-term undo history for a file or project.
Persisting the undo history
Undo/redo functionality is a useful feature for most editors, including Vim. However, by default, Vim's undo history is only available during the current editing session, as it is stored in memory and lost once the process exits. While tools such as undotree can aid in accessing historical states, it does not offer a permanent solution. For some users, it may be safer or more convenient to persist the undo history across editing sessions, and that's where Vim's persistent undo feature comes in.
Persistent undo saves the undo history in a file on disk, rather than in RAM. Whenever a change is made, Vim saves the edited file with its current state, while also saving the entire undo history to a separate file on disk that includes all states. This means that even after exiting Vim, the undo history is still available when you reopen the file, allowing you to continue to undo/redo changes. The undo history file is incremental and saves every change permanently, similar to Git.
If you're worried about the potential storage space used by persistent undo files, undotree provides an option to clean them up. Additionally, undotree is written in pure Vim script, making it lightweight, simple, and fast, and only runs when needed. To enable persistent undo, simply type :h persistent-undo
in Vim, or follow the instructions provided in the Usage section below.
Download and Install
Using Vim's built-in package manager:
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
Use whatever plug-in manager to pull the master branch. I've included 2 examples of the most used:
- Vundle:
Plugin 'mbbill/undotree'
- Vim-Plug:
Plug 'mbbill/undotree'
- Packer:
use 'mbbill/undotree'
And install them with the following:
- Vundle:
:PluginInstall
- Vim-Plug:
:PlugInstall
- Packer:
:PackerSync
Usage
- Use
:UndotreeToggle
to toggle the undo-tree panel.
You may want to map this command to whatever hotkey by adding the following line to your vimrc, take F5
for example.
nnoremap <F5> :UndotreeToggle<CR>
Or the equivalent mapping if using Neovim and Lua script.
vim.keymap.set('n', '<leader><F5>', vim.cmd.UndotreeToggle)
- Markers
- Every change has a sequence number and it is displayed before timestamps.
- The current state is marked as
> number <
. - The next state which will be restored by
:redo
or<ctrl-r>
is marked as{ number }
. - The
[ number ]
marks the most recent change. - The undo history is sorted by timestamps.
- Saved changes are marked as
s
and the bigS
indicates the most recent saved change.
- Press
?
in undotree window for quick help. - Persistent undo
- Usually, I would like to store the undo files in a separate place like below.
if has("persistent_undo")
let target_path = expand('~/.undodir')
" create the directory and any parent directories
" if the location does not exist.
if !isdirectory(target_path)
call mkdir(target_path, "p", 0700)
endif
let &undodir=target_path
set undofile
endif
* Alternatively, if you wish to persist the undo history for a currently
open file only, you can use the `:UndotreePersistUndo` command.
Configuration
Here is a list of options.
Debug
- Create a file under $HOME with the name
undotree_debug.log
$touch ~/undotree_debug.log
- Run vim, and the log will automatically be appended to the file, and you may watch it using
tail
:$tail -F ~/undotree_debug.log
- If you want to disable debug, just delete that file.
License
BSD
Author
Ming Bai <mbbill AT gmail DOT COM>
Top Related Projects
fzf :heart: vim
A tree explorer plugin for vim.
fugitive.vim: A Git wrapper so awesome, it should be illegal
A Vim plugin which shows git diff markers in the sign column and stages/previews/undoes hunks and partial hunks.
lean & mean status/tabline for vim that's light as air
Check syntax in Vim/Neovim asynchronously and fix files, with Language Server Protocol (LSP) support
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot