{"id":31,"date":"2014-08-10T00:00:54","date_gmt":"2014-08-09T22:00:54","guid":{"rendered":"http:\/\/kurt.www.pinboard.jp\/blog\/?p=31"},"modified":"2017-01-31T21:15:17","modified_gmt":"2017-01-31T20:15:17","slug":"persistent-undo","status":"publish","type":"post","link":"http:\/\/kurt.www.pinboard.jp\/blog\/kurt\/31\/","title":{"rendered":"persistent undo stack"},"content":{"rendered":"<p>In <a title=\"undo \u2013 redo\" href=\"http:\/\/kurt.www.pinboard.jp\/blog\/kurt\/25\/\">undo \u2013 redo<\/a> I&#8217;ve described how to undo and redo changes in a file. By default, the undo stack is deleted when you close a file. However, this can be changed and also the size of the undo stack can be controlled.<!--more--><\/p>\n<p>There are three interesting options which you can use:<\/p>\n<ul>\n<li><span style=\"color: #008000;\">:set undolevels=1000<\/span><br \/>\nThe undolevels setting has a default of 1000 on my system. It controls how many changes are remembered and thus can be undone.<br \/>\nUse <span style=\"color: #008000;\">:set undolevels<\/span> without a value in command mode to check the current value on your system.<\/li>\n<li><span style=\"color: #008000;\">:set undodir=~\/.vim\/undo\/<\/span><br \/>\nBy default, the undo information is saved in the same directory as the file which is edited. The undo file is a hidden and has an extension of <code>.un~<\/code>. I prefer to have all these files in a separate place somewhere in my home directory. Therefor I create the <code>~\/.vim\/undo\/<\/code> directory and configure vim to save the undo information of all my edits there.<\/li>\n<li><span style=\"color: #008000;\">:set undofile<\/span><br \/>\nThis is the switch which actually enables saving change information to a file and thus make it persistent across multiple edit sessions.<br \/>\nIf the undo file can not be written, you will not get any warning unless you explicitly <span style=\"color: #008000;\">:set verbose=1<\/span>.<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p>So the section in your <code>.vimrc<\/code> file to persistently record the last 1000 changes for each file you edit could look like this:<\/p>\n<pre style=\"background-color: lightyellow; color: green;\">:set undolevels=1000    \" default is 1000\r\n:set undodir=~\/.vim\/undo\/  \" set the directory to store undo files\r\n:set undofile           \" activate undo info saving\r\n                        \" ATTENTION: vim does not delete these fiels, you\r\n                        \"            need to delete them manually\r\n<\/pre>\n<p>That all said, this is a configuration which I actually do not use. Why not? I often open a file, make some changes to it, leave the editor open and test the changes. If I&#8217;m not happy with the result, I want to be able to go back to the version of the file before I opened it for editing. Without the configuration presented here, I can simply use the undo command until there is no more undo possible and then I know I&#8217;m back at the original version (unless I made more than 1000 individual changes). But with persistent undo, I might undo a change I did during my last edit session, which could be weeks or months back. That is not what I want.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In undo \u2013 redo I&#8217;ve described how to undo and redo changes in a file. By default, the undo stack is deleted when you close a file. However, this can be changed and also the size of the undo stack can be controlled.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[2],"tags":[4],"_links":{"self":[{"href":"http:\/\/kurt.www.pinboard.jp\/blog\/wp-json\/wp\/v2\/posts\/31"}],"collection":[{"href":"http:\/\/kurt.www.pinboard.jp\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/kurt.www.pinboard.jp\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/kurt.www.pinboard.jp\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/kurt.www.pinboard.jp\/blog\/wp-json\/wp\/v2\/comments?post=31"}],"version-history":[{"count":4,"href":"http:\/\/kurt.www.pinboard.jp\/blog\/wp-json\/wp\/v2\/posts\/31\/revisions"}],"predecessor-version":[{"id":182,"href":"http:\/\/kurt.www.pinboard.jp\/blog\/wp-json\/wp\/v2\/posts\/31\/revisions\/182"}],"wp:attachment":[{"href":"http:\/\/kurt.www.pinboard.jp\/blog\/wp-json\/wp\/v2\/media?parent=31"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/kurt.www.pinboard.jp\/blog\/wp-json\/wp\/v2\/categories?post=31"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/kurt.www.pinboard.jp\/blog\/wp-json\/wp\/v2\/tags?post=31"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}