Commit b56c4236 authored by Dustin L. Howett's avatar Dustin L. Howett

Merge commit '31608644' as 'pack/3rdparty/start/undotree'

parents 75d5f211 31608644
### [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
Vim 7.0 added a new feature named **Undo branches**. Basically it's a kind of ability to go back to the text after any change, even if they were undone. Vim stores undo history in a tree which you can browse and manipulate through a bunch of commands. But that was not enough straightforward and a bit hard to use. You may use `:help new-undo-branches` or `:help undo-tree` to get more detailed help.
Now this plug-in will free you from those commands and bring back the power of undo tree.
### 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.
### 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. 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.
// In your vimrc
if has("persistent_undo")
set undodir=~/.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
### Debug
1. Create a file under $HOME with the name `undotree_debug.log`
* `$touch ~/undotree_debug.log`
1. Run vim, and the log will automatically be appended to the file, and you may watch it using `tail`:
* `$tail -F ~/undotree_debug.log`
1. If you want to disable debug, just delete that file.
### Alternatives
Someone asked me about the difference with [Gundo](https://bitbucket.org/sjl/gundo.vim/), here is a list of differences, or advantages.
1. Pure vimscript implementation and no 3rd-party libraries(like python) is needed, don't worry about performance, it's not such a big deal for vim to handle this. The only dependency is the 'diff' tool which always shipped with vim and even without 'diff' you still can use most of the features of this script.
1. Realtime updated undo tree. Once you make changes, the undo tree will be updated simultaneously.
1. Several useful marks, like current changeset, next redo changeset, saved changeset, etc.
1. Toggle between relative timestamp and absolute timestamp.
1. Realtime updated undo window.
1. Ability to clear undo history.
1. More customizable.
### License
**BSD**
### Author
Ming Bai &lt;mbbill AT gmail DOT COM&gt;
This diff is collapsed.
This diff is collapsed.
"=================================================
" File: plugin/undotree.vim
" Description: Manage your undo history in a graph.
" Author: Ming Bai <mbbill@gmail.com>
" License: BSD
" Avoid installing twice.
if exists('g:loaded_undotree')
finish
endif
let g:loaded_undotree = 0
" At least version 7.3 with 005 patch is needed for undo branches.
" Refer to https://github.com/mbbill/undotree/issues/4 for details.
" Thanks kien
if v:version < 703
command! -n=0 -bar UndotreeToggle :echoerr "undotree.vim needs Vim version >= 7.3"
finish
endif
if (v:version == 703 && !has("patch005"))
command! -n=0 -bar UndotreeToggle :echoerr "undotree.vim needs vim7.3 with patch005 applied."
finish
endif
let g:loaded_undotree = 1 " Signal plugin availability with a value of 1.
"=================================================
"Options:
" Window layout
" style 1
" +----------+------------------------+
" | | |
" | | |
" | undotree | |
" | | |
" | | |
" +----------+ |
" | | |
" | diff | |
" | | |
" +----------+------------------------+
" Style 2
" +----------+------------------------+
" | | |
" | | |
" | undotree | |
" | | |
" | | |
" +----------+------------------------+
" | |
" | diff |
" | |
" +-----------------------------------+
" Style 3
" +------------------------+----------+
" | | |
" | | |
" | | undotree |
" | | |
" | | |
" | +----------+
" | | |
" | | diff |
" | | |
" +------------------------+----------+
" Style 4
" +-----------------------++----------+
" | | |
" | | |
" | | undotree |
" | | |
" | | |
" +------------------------+----------+
" | |
" | diff |
" | |
" +-----------------------------------+
if !exists('g:undotree_WindowLayout')
let g:undotree_WindowLayout = 1
endif
" e.g. using 'd' instead of 'days' to save some space.
if !exists('g:undotree_ShortIndicators')
let g:undotree_ShortIndicators = 0
endif
" undotree window width
if !exists('g:undotree_SplitWidth')
if g:undotree_ShortIndicators == 1
let g:undotree_SplitWidth = 24
else
let g:undotree_SplitWidth = 30
endif
endif
" diff window height
if !exists('g:undotree_DiffpanelHeight')
let g:undotree_DiffpanelHeight = 10
endif
" auto open diff window
if !exists('g:undotree_DiffAutoOpen')
let g:undotree_DiffAutoOpen = 1
endif
" if set, let undotree window get focus after being opened, otherwise
" focus will stay in current window.
if !exists('g:undotree_SetFocusWhenToggle')
let g:undotree_SetFocusWhenToggle = 0
endif
" tree node shape.
if !exists('g:undotree_TreeNodeShape')
let g:undotree_TreeNodeShape = '*'
endif
if !exists('g:undotree_DiffCommand')
let g:undotree_DiffCommand = "diff"
endif
" relative timestamp
if !exists('g:undotree_RelativeTimestamp')
let g:undotree_RelativeTimestamp = 1
endif
" Highlight changed text
if !exists('g:undotree_HighlightChangedText')
let g:undotree_HighlightChangedText = 1
endif
" Highlight linked syntax type.
" You may chose your favorite through ":hi" command
if !exists('g:undotree_HighlightSyntaxAdd')
let g:undotree_HighlightSyntaxAdd = "DiffAdd"
endif
if !exists('g:undotree_HighlightSyntaxChange')
let g:undotree_HighlightSyntaxChange = "DiffChange"
endif
" Deprecates the old style configuration.
if exists('g:undotree_SplitLocation')
echo "g:undotree_SplitLocation is deprecated,
\ please use g:undotree_WindowLayout instead."
endif
" Show help line
if !exists('g:undotree_HelpLine')
let g:undotree_HelpLine = 1
endif
"let s:auEvents = "InsertEnter,InsertLeave,WinEnter,WinLeave,CursorMoved"
let s:auEvents = "BufEnter,InsertLeave,CursorMoved,BufWritePost"
augroup Undotree
exec "au! ".s:auEvents." * call undotree#UndotreeUpdate()"
augroup END
"=================================================
" User commands.
command! -n=0 -bar UndotreeToggle :call undotree#UndotreeToggle()
command! -n=0 -bar UndotreeHide :call undotree#UndotreeHide()
command! -n=0 -bar UndotreeShow :call undotree#UndotreeShow()
command! -n=0 -bar UndotreeFocus :call undotree#UndotreeFocus()
" vim: set et fdm=marker sts=4 sw=4:
"=================================================
" File: undotree.vim
" Description: undotree syntax
" Author: Ming Bai <mbbill@gmail.com>
" License: BSD
syn match UndotreeNode ' \zs\*\ze '
syn match UndotreeNodeCurrent '\zs\*\ze.*>\d\+<'
syn match UndotreeTimeStamp '(.*)$'
syn match UndotreeFirstNode 'Original'
syn match UndotreeBranch '[|/\\]'
syn match UndotreeSeq ' \zs\d\+\ze '
syn match UndotreeCurrent '>\d\+<'
syn match UndotreeNext '{\d\+}'
syn match UndotreeHead '\[\d\+]'
syn match UndotreeHelp '^".*$' contains=UndotreeHelpKey,UndotreeHelpTitle
syn match UndotreeHelpKey '^" \zs.\{-}\ze:' contained
syn match UndotreeHelpTitle '===.*===' contained
syn match UndotreeSavedSmall ' \zss\ze '
syn match UndotreeSavedBig ' \zsS\ze '
hi def link UndotreeNode Question
hi def link UndotreeNodeCurrent Statement
hi def link UndotreeTimeStamp Function
hi def link UndotreeFirstNode Function
hi def link UndotreeBranch Constant
hi def link UndotreeSeq Comment
hi def link UndotreeCurrent Statement
hi def link UndotreeNext Type
hi def link UndotreeHead Identifier
hi def link UndotreeHelp Comment
hi def link UndotreeHelpKey Function
hi def link UndotreeHelpTitle Type
hi def link UndotreeSavedSmall WarningMsg
hi def link UndotreeSavedBig MatchParen
" vim: set et fdm=marker sts=4 sw=4:
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment