How can I “control version” in vim?

For example, I have working code, but not fast enough, so I want to write this version of the code, and ten continue to optimize it and possibly get a better version, then write this version again and so on.

If I eventually failed to get the fast code, I want to return to the original working code.

I suppose this can be achieved using the undo branch, but I have not found how to do this.

+6
source share
5 answers

Yes, you can add functionality to undo branches, which makes it more like a version control system.

In vim 7.3, you can have persistent undo, as described here , you need to add the following lines to .vimrc .

 set undodir=~/.vim/undodir set undofile 

To get the most out of the branches, I highly recommend gundo , as you can use it to render the tree and see the differences it makes.

+6
source

Use a version control system. I recommend Git + Runaway .

Seriously!

You will not look back.

+7
source

There are plugins for vim.

Also check: http://www.vim.org/scripts/script.php?script_id=90

+2
source

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.

+2
source

I'm not an expert in vim (in fact, I can barely use it), but the solutions that come to my mind are:

  • Use actual version control for what it is needed. Perhaps even one of them has “distributed” tastes, because they do not need a separate repository;
  • Just backup your file / folder whenever you want.
  • You can even write a short program (shell script?) That copies the file / folder for you with the suffix automatically added, which marks the time when you made the copy.
  • ... and then bind this program to a short vim course (I don’t know how to do this, but, according to rumors, vim is so strong that I would assume that it has such a function).
0
source

Source: https://habr.com/ru/post/903438/


All Articles