2

I've looked up and tried several of the following post up here regarding setting up persistent undo history in vim, but still I'm not able to do so. (macOSX Mojave)

here are some info:

:version

   system vimrc file: "$VIM/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
       defaults file: "$VIMRUNTIME/defaults.vim"
  fall-back for $VIM: "/usr/share/vim"

vimrc file = ~/.vim/.vimrc

":highlight Normal ctermfg=grey ctermbg=darkblue                                          
:let $MYVIMRC="~/.vim/.vimrc"

set undofile                                                                              
set undodir=/Users/dave/.vim/undodir

let mapleader = "\<Space>"

:nnoremap <leader>sv :source $MYVIMRC<cr>                                                 
:nnoremap <leader>ev :vsplit $MYVIMRC<cr>

~/.bash_profile

alias vim="vim -S ~/.vim/.vimrc"

Inside of /undodir:

%Users%dave%.vim%.vimrc %Users%dave%test.js

However when I load "test.js" and press u, vim responds with "already oldest change".

  • 3
    No answer to you actual question, but unless you have a really good reason for it, I’d recommend allowing Vim to find your .vimrc in the usual way rather than your slightly convoluted method. Specifically, remove your bash alias, remove the line overwriting the $MYVIMRC variable, and rename your file from ~/.vim/.vimrc to ~/.vim/vimrc. – Rich Apr 30 at 23:34
  • 1
    Are you sure youve edited test.js such that it has an undo history? – D. Ben Knoble Apr 30 at 23:39
  • 1
    @Rich, I forgot the reason why I did it that way, but your suggestion help fixed my issue. Thanks! – David Trinh May 1 at 19:00
1

The problem is with your alias:

alias vim="vim -S ~/.vim/.vimrc"

Note that sourcing a script with -S is not the same as using that file as your vimrc.

From :help -S (emphasis mine):

The {file} will be sourced after the first file has been read.

So, in effect, you're only setting 'undofile' and 'undodir' after you've already opened your test.js. If you simply opened vim with no files and then opened the file with :e test.js, restoring undo might have worked.

If you want to load your vimrc from a non-standard location, then -u is what you want instead... But there's really no reason to do that, just store your vimrc at one of the standard locations and get rid of that alias instead.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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