Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
mbbill committed Jan 30, 2019
1 parent d7075dd commit a01ffdb
Showing 1 changed file with 29 additions and 38 deletions.
67 changes: 29 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,65 +1,56 @@

### [Project on Vim.org](http://www.vim.org/scripts/script.php?script_id=4177)

[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/mbbill/undotree?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

### Screenshot

![](https://sites.google.com/site/mbbill/undotree_new.png)

### Description
The plug-in visualize undo history and makes it easier to browse and switch between different undo branches. Wait a second, what do you mean by undo "branches"? Well, it's vim feature added a long time ago, and it allows you to go back to a state when it is overwritten by a latest edit. For example, you made a change A, then B, then go back to A and made change C, normally you won't be able to go back to B anymore on other editors. Vim internally maintains all the undo history as a tree structure, and this plug in exposes the tree to you so that you can switch to whatever state you need.

The plug-in visualizes undo history and makes it easier to browse and switch between different undo branches. You might wonder what is undo "branches"? It's vim feature that allows you to go back to a state when it is overwritten by a latest edit. For most editors, if you make a change A, then B, then go back to A and make change C, normally you won't be able to go back to B because undo history is linear. That's not the case for Vim because it internally keeps all the edit history like a tree structure, and this plug-in exposes the tree to you so that you not only can switch back and forth but also can switch between branches.


Some people have questions about file contents being changed when switching between undo history states. Don't worry, *undotree* will **NEVER** save your data or write to disk. All it does is to change the current buffer little bit, just like those auto-completion plug-ins do. It just adds or removes something in the buffer temporarily, and if you don't like you can always go back to the last state easily. Let's say, you made some change but didn't save, then you use *undotree* and go back to an arbitrary version, your unsaved change doesn't get lost - it stores in the latest undo history node. Clicking that node on *undotree* will bring you back instantly. Play with undo/redo on other editors is always dangerous because when you step back and accidentally typed something, boom! You lose your edits. But don't worry, that won't happen in Vim. Then you might ask what if I make some changes without saving and switch back to an old version and then **exit**? Well, imaging what would happen if you don't have *undotree*? You lose your latest edits and the file on disk is your last saved version. This behaviour **remains the same** with *undotree*. So, if you saved, you won't lose anything.


Some people have questions about file contents being changed when switching between undo history states. Don't worry, *undotree* will **NEVER** save your data or write to disk. All it does is to change the current buffer little bit, just like those auto-completion plug-ins does - it adds or removes something in the buffer temporarily, and if you don't like you can always go back to the last state easily. Let's say, you made some change but didn't save, now you use *undotree* and go back to an old version, your last change doesn't get lost - it stores in the latest undo history node. Clicking that node will bring you back instantly. Then you might ask what if I made some change without save and switch back to an old version and then **exit**? Well, imaging what would happen if you don't have *undotree*? You lost your latest edit and the file on disk is your last saved version. This behaviour remains the same with *undotree*, and that's why I highly recommend enabling *persistent undo*. Let me explain how persistent undo works: the biggest difference is that persistent undo keeps your undo history on disk, kind of like git. Let's say you made a change A, then B, then go back to A and made change C, and now you *save* the file. Now Vim save the file with content state C, and in the mean time it saves undo history to a file with A, B and C. Next time you open the file you can still go back to B because when you save, you save **everything** you did in the past. So, be careful don't let somebody else find our your secret - you know I'm kidding.
We all know that usually undo/redo is only for the current edit session. It's stored in memory and once the process exits, the undo history is lost. Although *undotree* makes switching between history states easier, it doesn't do more than that. Sometimes it would be much safer or more convenient to keep the undo history across edit sessions. In this case you might need to enable a Vim feature called *persistent undo*. Let me explain how persistent undo works: instead of keeping undo history in *RAM*, persistent undo keeps undo history in file. Let's say you make a change A, then B, then go back to A and make change C, then you *save* the file. Now Vim save the file with content state C, and in the mean time it saves **the entire** undo history to a file including state A, B and C. Next time when you open the file, Vim will also restore undo history. So you can still go back to B. The history file is incremental, and every change will be recorded permanently, kind of like Git. You might think that's too much, well, *undotree* does provide a way to clean them up. If you need to enable *persistent undo*, type ```:h persistent-undo``` or follow the instructions below.


Undotree is written in **pure Vim script** and doesn't rely on any third party tools. It's lightweight, simple and fast. It only does what it supposed to do, and it only runs when you need it.

### Features
1. Visualize undo-tree
* The undo history is sorted based on the changes' timestamp. The year/month/day field will not be displayed if the changes were made within the same day.
* The change sequence number is displayed before timestamp.
* The current position is marked as **>seq<**.
* The next change that will be restored by `:redo` or `<ctrl-r>` is marked as **{seq}**, it's the same as *curhead* returned by *undotree()*
* The **[seq]** marks the last change and where further changes will be added, it's the same as *newhead* returned by *undotree()*
* Saved changes are marked as **s** and the capitalized **S** indicates the last saved change.
1. Live updated diff panel.
1. Highlight for added and changed text.
1. Revert to a specific change by a single mouse click or key stroke.
1. Customizable hotkeys and highlighting.
1. Display changes in diff panel.

### [Download](https://github.com/mbbill/undotree/tags)

### Install
1. Unpack all scripts into *.vim* directory and that's all. This script is written purely in Vim script with no additional dependency.
1. It's highly recommend using **pathogen** or **Vundle** to manage your plug-ins.

### Download and Install

Use whatever plug-in manager to pull the master branch.


### Usage
1. 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 &lt;F5&gt; :UndotreeToggle&lt;cr&gt;

1. Then you can try to do some modification, and the undo tree will automatically updated afterwards.
1. There are some hotkeys provided by vim to switch between the changes in history, like `u`, `<ctrl-r>`, `g+`, `g-` as well as the `:earlier` and `:later` commands.
1. You may also switch to undotree panel and use the hotkeys to switch between history versions. Press `?` in undotree window for quick help of hotkeys.
1. You can monitor the changed text in diff panel which is automatically updated when undo/redo happens.
1. 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 big `S` indicates the most recent saved change.
1. Press `?` in undotree window for quick help.
1. Persistent undo
* It is highly recommend to enable the persistent undo. If you don't like your working directory be messed up with the undo file everywhere, you may add the following line to your *vimrc* in order to make them stored together.
* Usually I would like to store the undo files in a seperate place like below.

// In your vimrc

if has("persistent_undo")
set undodir=$HOME."/.undodir"
set undofile
endif
```
if has("persistent_undo")
set undodir=$HOME."/.undodir"
set undofile
endif
```

### Configuration
1. Basically, you do not need any configuration to let it work, cool?
1. But if you still want to do some customization, there is also a couple of options provided.
* [Here](https://github.com/mbbill/undotree/blob/master/plugin/undotree.vim#L15) is a list of these options.

### Post any issue and feature request here:
https://github.com/mbbill/undotree/issues
[Here](https://github.com/mbbill/undotree/blob/master/plugin/undotree.vim#L15) is a list of options.

### Debug
1. Create a file under $HOME with the name `undotree_debug.log`
Expand Down

0 comments on commit a01ffdb

Please sign in to comment.