1

I had a swp file with old content, to which I restored and wasted much cleaning it. So I would like much such feature.

Jetbrains's IDEs have feature local history:

enter image description here

Which preserve history for specified settings, it looks this: enter image description here

I would like similar feature in vim, maybe with plugin.

2
  • Welcome to Vim :-) I'm not sure I understand your question. Could you give some context (the situation you are in) and what you want to achieve. You could also explain what you have tried and how it fails. May 22, 2022 at 21:08
  • You may want to check persistent undo files. Also you can of course restore from older swap files. May 23, 2022 at 7:11

1 Answer 1

2

The mbbill/undotree plugin provides you similar feature provided that you have enabled the support for undofiles

see screenshot:

undotree screenshot

Here is what I have in my .vimrc files to control the support

" Save undo trees in files (such that they are available after vim is closed)
set undofile

" folder to store the undo files (the folder has to be created first)
" Save undo files in the .undo sub-folder (if it exists)
" Otherwise in the ~/vimfiles/undo folder (if it exists)
" It avoid to pollute your local folder
if has('win32')
  if !isdirectory(s:vim_data_folder .. 'undo')
    call mkdir(s:vim_data_folder .. 'undo')
  endif
  exe 'set undodir=' .. '.undo/,' .. s:vim_data_folder_alt .. 'undo/'
endif

if has('unix')
  if !isdirectory($HOME .. '/.vim/undo')
    call mkdir($HOME .. "/.vim/undo", "p", 0700)j
  endif
  set undodir=.undo/,~/.vim/undo/
endif

" Set the number of undo saved:
set undolevels=10000

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.