Using a version control system is definitely a good idea for any projects you work on, even if they are quite small. Despite this, the HaskellElephant makes a good point - sometimes you can experiment with a small outlier script that you want to customize. Actually, it would be pretty cool to create savepoints in such cases, so I played with the vim undotree() function and came up with this script:
command! -nargs=1 StoreUndo call s:StoreUndo(<f-args>) function! s:StoreUndo(label) if !exists('b:stored_undo_state') let b:stored_undo_state = {} endif let b:stored_undo_state[a:label] = undotree()['seq_cur'] endfunction command! -nargs=1 -complete=custom,s:CompleteUndoStates RestoreUndo call s:RestoreUndo(<f-args>) function! s:RestoreUndo(label) if !exists('b:stored_undo_state') let b:stored_undo_state = {} endif if !has_key(b:stored_undo_state, a:label) echoerr a:label.' not found in stored undo states.' endif exe 'undo '.b:stored_undo_state[a:label] endfunction function! s:CompleteUndoStates(A, L, P) if !exists('b:stored_undo_state') let b:stored_undo_state = {} endif return join(keys(b:stored_undo_state), "\n") endfunction
Here it is in gist form: https://gist.github.com/1473170
You can put it under ~/.vim/plugin , for example. Command Execution :StoreUndo foo will create a savepoint named "foo". You can make any changes. When you execute :RestoreUndo foo , the buffer restores the saved state. The RestoreUndo command is RestoreUndo with tabs with all existing savepoints.
It is not saved in the file. If you close the buffer, you will lose the history, so it can be useful only temporarily, for quick experimentation.
source share