undotree.txt 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519
  1. *undotree.txt* The undo history visualizer for VIM
  2. Author: Ming Bai <mbbill AT gmail DOT COM>
  3. Licence: BSD
  4. Homepage: https://github.com/mbbill/undotree/
  5. ==============================================================================
  6. CONTENTS *undotree-contents*
  7. 1. Intro ................................ |undotree-intro|
  8. 2. Usage ................................ |undotree-usage|
  9. 3. Configuration ........................ |undotree-config|
  10. 3.1 undotree_WindowLayout .......... |undotree_WindowLayout|
  11. 3.2 undotree_CustomUndotreeCmd...... |undotree_CustomUndotreeCmd|
  12. undotree_CustomDiffpanelCmd..... |undotree_CustomDiffpanelCmd|
  13. 3.3 undotree_SplitWidth ............ |undotree_SplitWidth|
  14. 3.4 undotree_DiffpanelHeight ....... |undotree_DiffpanelHeight|
  15. 3.5 undotree_DiffAutoOpen .......... |undotree_DiffAutoOpen|
  16. 3.6 undotree_SetFocusWhenToggle .... |undotree_SetFocusWhenToggle|
  17. 3.7 undotree_TreeNodeShape ......... |undotree_TreeNodeShape|
  18. undotree_TreeVertShape ......... |undotree_TreeVertShape|
  19. undotree_TreeSplitShape ........ |undotree_TreeSplitShape|
  20. undotree_TreeReturnShape ....... |undotree_TreeReturnShape|
  21. 3.8 undotree_DiffCommand ........... |undotree_DiffCommand|
  22. 3.9 undotree_RelativeTimestamp ..... |undotree_RelativeTimestamp|
  23. 3.10 undotree_ShortIndicators ....... |undotree_ShortIndicators|
  24. 3.11 undotree_HighlightChangedText .. |undotree_HighlightChangedText|
  25. 3.12 undotree_HighlightSyntaxAdd .... |undotree_HighlightSyntaxAdd|
  26. undotree_HighlightSyntaxChange . |undotree_HighlightSyntaxChange|
  27. 3.13 Undotree_CustomMap ............. |Undotree_CustomMap|
  28. 3.14 undotree_HelpLine .............. |undotree_HelpLine|
  29. 3.15 undotree_CursorLine ............ |undotree_CursorLine|
  30. 3.16 undotree_UndoDir................ |undotree_UndoDir|
  31. 4. Bugs ................................. |undotree-bugs|
  32. 5. Changelog ............................ |undotree-changelog|
  33. 6. License .............................. |undotree-license|
  34. ==============================================================================
  35. 1. Intro *undotree-intro*
  36. The plug-in visualizes undo history and makes it easier to browse and switch
  37. between different undo branches. You might wonder what are undo "branches"?
  38. It's vim feature that allows you to go back to a state when it is overwritten
  39. by a latest edit. For most editors, if you make a change A, then B, then go
  40. back to A and make change C, normally you won't be able to go back to B
  41. because undo history is linear. That's not the case for Vim because it
  42. internally keeps all the edit history like a tree structure, and this plug-in
  43. exposes the tree to you so that you not only can switch back and forth but
  44. also can switch between branches.
  45. Some people have questions about file contents being changed when switching
  46. between undo history states. Don't worry, undotree will NEVER save your data
  47. or write to disk. All it does is to change the current buffer little bit, just
  48. like those auto-completion plug-ins do. It just adds or removes something in
  49. the buffer temporarily, and if you don't like you can always go back to the
  50. last state easily. Let's say, you made some change but didn't save, then you
  51. use undotree and go back to an arbitrary version, your unsaved change doesn't
  52. get lost - it stores in the latest undo history node. Clicking that node on
  53. undotree will bring you back instantly. Play with undo/redo on other editors
  54. is always dangerous because when you step back and accidentally typed
  55. something, boom! You lose your edits. But don't worry, that won't happen in
  56. Vim. Then you might ask what if I make some changes without saving and switch
  57. back to an old version and then exit? Well, imagine what would happen if you
  58. don't have undotree? You lose your latest edits and the file on disk is your
  59. last saved version. This behaviour remains the same with undotree. So, if you
  60. saved, you won't lose anything.
  61. We all know that usually undo/redo is only for the current edit session. It's
  62. stored in memory and once the process exits, the undo history is lost.
  63. Although undotree makes switching between history states easier, it doesn't do
  64. more than that. Sometimes it would be much safer or more convenient to keep
  65. the undo history across edit sessions. In this case you might need to enable a
  66. Vim feature called persistent undo. Let me explain how persistent undo works:
  67. instead of keeping undo history in RAM, persistent undo keeps undo history in
  68. file. Let's say you make a change A, then B, then go back to A and make change
  69. C, then you save the file. Now Vim save the file with content state C, and in
  70. the mean time it saves the entire undo history to a file including state A, B
  71. and C. Next time when you open the file, Vim will also restore undo history.
  72. So you can still go back to B. The history file is incremental, and every
  73. change will be recorded permanently, kind of like Git. You might think that's
  74. too much, well, undotree does provide a way to clean them up. If you need to
  75. enable persistent undo, type :h persistent-undo or follow the instructions
  76. below.
  77. Undotree is written in pure Vim script and doesn't rely on any third party
  78. tools. It's lightweight, simple and fast. It only does what it supposed to do,
  79. and it only runs when you need it.
  80. ==============================================================================
  81. 2. Usage *undotree-usage*
  82. Use :UndotreeToggle to toggle the undo-tree panel. You may want to map this
  83. command to whatever hotkey by adding the following line to your vimrc, take F5
  84. for example.
  85. >
  86. nnoremap <F5> :UndotreeToggle<cr>
  87. <
  88. Markers
  89. * Every change has a sequence number and it is displayed before timestamps.
  90. * The current state is marked as > number <.
  91. * The next state which will be restored by :redo or <ctrl-r> is marked as
  92. { number }.
  93. * The [ number ] marks the most recent change.
  94. * The undo history is sorted by timestamps.
  95. * Saved changes are marked as s and the big S indicates the most recent
  96. saved change.
  97. * Press ? in undotree window for quick help.
  98. Persistent undo
  99. Usually I would like to store the undo files in a separate place like below.
  100. >
  101. if has("persistent_undo")
  102. let target_path = expand('~/.undodir')
  103. " create the directory and any parent directories
  104. " if the location does not exist.
  105. if !isdirectory(target_path)
  106. call mkdir(target_path, "p", 0700)
  107. endif
  108. let &undodir=target_path
  109. set undofile
  110. endif
  111. <
  112. Alternatively, the persistent undofile can be activated by using the
  113. :UndotreePersistUndo command. This will enable the undofile for the current
  114. buffer only, as undotree utilizes the setlocal undofile function. Once this
  115. command is executed and the persistence undofile is created, the "setlocal
  116. undofile" function will automatically be executed the next time the file is
  117. reopened.
  118. See |undotree_UndoDir|
  119. You may want to map the command to whatever hotkey by adding this following
  120. line to your vimrc, for instance:
  121. `nnoremap <F6> :UndotreePersistUndo<cr>`
  122. ==============================================================================
  123. 3. Configuration *undotree-config*
  124. ------------------------------------------------------------------------------
  125. 3.1 g:undotree_WindowLayout *undotree_WindowLayout*
  126. Set the undotree window layout.
  127. Style 1
  128. >
  129. +----------+------------------------+
  130. | | |
  131. | | |
  132. | undotree | |
  133. | | |
  134. | | |
  135. +----------+ |
  136. | | |
  137. | diff | |
  138. | | |
  139. +----------+------------------------+
  140. <
  141. Style 2
  142. >
  143. +----------+------------------------+
  144. | | |
  145. | | |
  146. | undotree | |
  147. | | |
  148. | | |
  149. +----------+------------------------+
  150. | |
  151. | diff |
  152. | |
  153. +-----------------------------------+
  154. <
  155. Style 3
  156. >
  157. +------------------------+----------+
  158. | | |
  159. | | |
  160. | | undotree |
  161. | | |
  162. | | |
  163. | +----------+
  164. | | |
  165. | | diff |
  166. | | |
  167. +------------------------+----------+
  168. <
  169. Style 4
  170. >
  171. +------------------------+----------+
  172. | | |
  173. | | |
  174. | | undotree |
  175. | | |
  176. | | |
  177. +------------------------+----------+
  178. | |
  179. | diff |
  180. | |
  181. +-----------------------------------+
  182. <
  183. Default: 1
  184. ------------------------------------------------------------------------------
  185. 3.2 g:undotree_CustomUndotreeCmd *undotree_CustomUndotreeCmd*
  186. g:undotree_CustomDiffpanelCmd *undotree_CustomDiffpanelCmd*
  187. Set up custom window layout.
  188. Setting |undotree_CustomUndotreeCmd| will ignore |undotree_SplitWidth|, and
  189. setting |undotree_CustomDiffpanelCmd| will ignore |undotree_DiffpanelHeight|.
  190. An |undotree_CustomUndotreeCmd| will always open the undotree window relative
  191. to the tracked window and |undotree_CustomDiffpanelCmd| will always open the
  192. diffpanel relative to the undotree window.
  193. Useful when
  194. * absolute positioning commands (|topleft|, |botright|) don't play well
  195. with other plugins
  196. * you have a preferred split window layout and would like to use
  197. UndoTree relative to one specific window only
  198. Examples:
  199. * To recreate Style 1:
  200. >
  201. let g:undotree_CustomUndotreeCmd = 'topleft vertical 30 new'
  202. let g:undotree_CustomDiffpanelCmd = 'belowright 10 new'
  203. <
  204. * To recreate Style 2:
  205. >
  206. let g:undotree_CustomUndotreeCmd = 'topleft vertical 30 new'
  207. let g:undotree_CustomDiffpanelCmd = 'botright 10 new'
  208. <
  209. * A custom layout example:
  210. >
  211. +------------------------+----------+
  212. | | |
  213. | | w |
  214. | | i |
  215. | | n |
  216. | window_1 | d |
  217. | | o |
  218. | | w |
  219. | | | |
  220. | | 2 |
  221. | | |
  222. +------------------------+----------+
  223. | |
  224. | window_3 |
  225. | |
  226. +-----------------------------------+
  227. <
  228. Using the following setup wouldn't mess up the current layout as it
  229. does not use absolute positioning:
  230. >
  231. let g:undotree_CustomUndotreeCmd = 'vertical 32 new'
  232. let g:undotree_CustomDiffpanelCmd= 'belowright 12 new'
  233. <
  234. Issuing :UndotreeToggle now in window_1 would result in:
  235. >
  236. +--------+---------------+----------+
  237. | | | |
  238. | u | | w |
  239. | n | | i |
  240. | d | | n |
  241. | o | window_1 | d |
  242. | | | o |
  243. +--------+ | w |
  244. | | | | |
  245. | diff | | 2 |
  246. | | | |
  247. +--------+---------------+----------+
  248. | |
  249. | window_3 |
  250. | |
  251. +-----------------------------------+
  252. <
  253. Executing :UndotreeToggle again would turn off UndoTree (independently
  254. of which window was active at the time). Moving between window1, window_2
  255. and window_3 would result in showing the respective window's changelog
  256. in the undotree panel.
  257. CAVEAT: To avoid the Vim's default behaviour of equalizing window sizes
  258. when closing a window, set the 'noequalalways' option.
  259. ------------------------------------------------------------------------------
  260. 3.3 g:undotree_SplitWidth *undotree_SplitWidth*
  261. Set the undotree window width.
  262. Default: 30
  263. ------------------------------------------------------------------------------
  264. 3.4 g:undotree_DiffpanelHeight *undotree_DiffpanelHeight*
  265. Set the diff window height.
  266. Default: 10
  267. ------------------------------------------------------------------------------
  268. 3.5 g:undotree_DiffAutoOpen *undotree_DiffAutoOpen*
  269. Set this to 1 to auto open the diff window.
  270. Default: 1
  271. ------------------------------------------------------------------------------
  272. 3.6 g:undotree_SetFocusWhenToggle *undotree_SetFocusWhenToggle*
  273. If set to 1, the undotree window will get focus after being opened, otherwise
  274. focus will stay in current window.
  275. Default: 0
  276. ------------------------------------------------------------------------------
  277. 3.7 g:undotree_TreeNodeShape *undotree_TreeNodeShape*
  278. g:undotree_TreeVertShape *undotree_TreeVertShape*
  279. g:undotree_TreeSplitShape *undotree_TreeSplitShape*
  280. g:undotree_TreeReturnShape *undotree_TreeReturnShape*
  281. Set the characters used to draw the tree. Although you can put any character
  282. you want in these shape variables, the only Unicode box drawing characters
  283. that work well are these three. Make sure your font will render them; you can
  284. easily see if that's the case in the last column of this table.
  285. Variable | Default | Unicode Box Character
  286. ---------------------------+---------------+-----------------------
  287. g:undotree_TreeNodeShape | * |
  288. g:undotree_TreeReturnShape | \ (backslash) | ╲ (U+2572)
  289. g:undotree_TreeVertShape | | (pipe) | │ (U+2502)
  290. g:undotree_TreeSplitShape | / (slash) | ╱ (U+2571)
  291. ------------------------------------------------------------------------------
  292. 3.8 g:undotree_DiffCommand *undotree_DiffCommand*
  293. Set the command used to get the diff output.
  294. Default: "diff"
  295. ------------------------------------------------------------------------------
  296. 3.9 g:undotree_RelativeTimestamp *undotree_RelativeTimestamp*
  297. Set to 1 to use relative timestamp.
  298. Default: 1
  299. ------------------------------------------------------------------------------
  300. 3.10 g:undotree_ShortIndicators *undotree_ShortIndicators*
  301. Set to 1 to get short timestamps when |undotree_RelativeTimestamp| is also
  302. enabled:
  303. >
  304. Before | After
  305. ===========================
  306. (5 seconds ago) | (5 s)
  307. ----------------|----------
  308. (1 minute ago) | (1 m)
  309. ----------------|----------
  310. (2 minutes ago) | (2 m)
  311. ----------------|----------
  312. (1 hour ago) | (1 h)
  313. ----------------|----------
  314. (Original) | (Orig)
  315. <
  316. Default: 0
  317. ------------------------------------------------------------------------------
  318. 3.11 g:undotree_HighlightChangedText *undotree_HighlightChangedText*
  319. Set to 1 to highlight the changed text.
  320. Default: 1
  321. ------------------------------------------------------------------------------
  322. 3.12 g:undotree_HighlightSyntaxAdd *undotree_HighlightSyntaxAdd*
  323. g:undotree_HighlightSyntaxDel *undotree_HighlightSyntaxDel*
  324. g:undotree_HighlightSyntaxChange *undotree_HighlightSyntaxChange*
  325. Set the highlight linked syntax type.
  326. You may chose your favorite through ":hi" command.
  327. Default: "DiffAdd", "DiffDelete" and "DiffChange"
  328. ------------------------------------------------------------------------------
  329. 3.13 g:Undotree_CustomMap *Undotree_CustomMap*
  330. There are two ways of changing the default key mappings:
  331. The first way is to define global mappings as the following example:
  332. >
  333. nmap <buffer> J <plug>UndotreeNextState
  334. nmap <buffer> K <plug>UndotreePreviousState
  335. <
  336. A better approach is to define the callback function g:Undotree_CustomMap().
  337. The function will be called after the undotree windows is initialized, so the
  338. key mappings only works on the undotree windows.
  339. >
  340. function g:Undotree_CustomMap()
  341. nmap <buffer> J <plug>UndotreeNextState
  342. nmap <buffer> K <plug>UndotreePreviousState
  343. endfunc
  344. <
  345. List of the commands available for redefinition.
  346. >
  347. <plug>UndotreeHelp
  348. <plug>UndotreeClose
  349. <plug>UndotreeFocusTarget
  350. <plug>UndotreeClearHistory
  351. <plug>UndotreeTimestampToggle
  352. <plug>UndotreeDiffToggle
  353. <plug>UndotreeNextState
  354. <plug>UndotreePreviousState
  355. <plug>UndotreeNextSavedState
  356. <plug>UndotreePreviousSavedState
  357. <plug>UndotreeRedo
  358. <plug>UndotreeUndo
  359. <plug>UndotreeEnter
  360. <
  361. ------------------------------------------------------------------------------
  362. 3.14 g:undotree_HelpLine *undotree_HelpLine*
  363. Set to 0 to hide "Press ? for help".
  364. Default: 1
  365. ------------------------------------------------------------------------------
  366. 3.15 g:undotree_CursorLine
  367. Set to 0 to disable cursorline.
  368. Default: 1
  369. ------------------------------------------------------------------------------
  370. 3.16 g:undotree_UndoDir *undotree_UndoDir*
  371. Set the path for the persistence undo directory. Due to the differing formats
  372. of the persistence undo files between nvim and vim, the default undodir for
  373. both has been intentionally given different paths. This ensures that users who
  374. use both nvim and vim do not accidentally lose their persistence undo files
  375. due to the different ways in which vim and nvim handle these files.
  376. If the g:undotree_UndoDir is not set and undodir has been set to "." (vim's
  377. default undodir value), then the g:undotree_UndoDir value will be set to:
  378. - vim: $HOME/.local/state/undo/vim/
  379. - nvim: $HOME/.local/state/undo/nvim/
  380. ==============================================================================
  381. 4. Bugs *undotree-bugs*
  382. Post any issue and feature request here:
  383. https://github.com/mbbill/undotree/issues
  384. ==============================================================================
  385. 5. Changelog *undotree-changelog*
  386. Further changes will not be recorded. Please go to github page for more
  387. information.
  388. 4.4 (2017-10-15)
  389. - Autoload plugin functions
  390. 4.3 (2013-02-18)
  391. - Several fixes and enhancements.
  392. 4.2 (2012-11-24)
  393. - Fixed some small issue.
  394. 4.1 (2012-09-05)
  395. - Enhanced tree style.
  396. - Multi-window switching support.
  397. 4.0 (2012-08-30)
  398. - Live updated highlight for changed text.
  399. - Customizable key mappings.
  400. - Fixed some minor bugs.
  401. 3.1 (2012-08-25)
  402. - Add saved status.
  403. - Add relative timestamp.
  404. - Add ability of clear undo history.
  405. 3.0 (2012-08-24)
  406. - Add diff panel.
  407. - Performance improvement.
  408. 2.2 (2012-08-21)
  409. - Stable version.
  410. 2.1 (2012-08-20)
  411. - Fixed some annoying issues.
  412. 2.0 (2012-08-19)
  413. - Hotkey support.
  414. - Handle undo levels.
  415. - Auto refresh.
  416. - And so on.
  417. 1.0 (2012-08-18)
  418. - Initial upload
  419. ==============================================================================
  420. 6. License *undotree-license*
  421. BSD
  422. vim:tw=78:ts=8:ft=help:norl: