prathmesh.kallurkar
prathmesh.kallurkar

Reputation: 5686

Vim record history

Vim stores the list of commands that we applied using : for the current execution. But when I close vim and start it again, the vim command history is lost. I tried set history = 1000 in the .vimrc file but that did not help.
Where does Vim maintain the local command history?
What is the command to retain command history?

Upvotes: 53

Views: 23439

Answers (8)

Bunnyton
Bunnyton

Reputation: 9

If you are using a vimrc file, check your folders and files for existence and correctness

set history=200 
set undolevels=128 
set undodir=~/.vim/undodir/ 
set undofile 
set undolevels=1000 
set undoreload=10000 

If the specified folder (undodir in my case) does not exist, the history will not be saved.

Upvotes: 0

Christophe Quintard
Christophe Quintard

Reputation: 2698

I had the same problem. The issue was that I had vim-minimal installed (this is a default with Fedora), which does not support history. I had to uninstall it and install the full vim instead. I now have history... and syntaxic coloration !

Upvotes: 1

Christopher Broderick
Christopher Broderick

Reputation: 448

I went round in circles on this one a bit on Ubuntu and set viminfo solutions proposed above resulted in errors.

I eventually did the command "version" in the command mode and it came back with "-" for most stuff including: -cmdline_hist -cmdline_info

I ran the following command and it all worked fine again: sudo apt install vim

Upvotes: 0

Aniket Anand
Aniket Anand

Reputation: 69

Mr. Baint has given the answer.

  • Go to $HOME directory.
  • give ls -l .viminfo to check permissions.
  • change permission so that group and owner also can have write permission. use:

     sudo chown yourUserId $HOME/.viminfo
    

It should fix the issue.

Upvotes: 6

Chanakya.sun
Chanakya.sun

Reputation: 587

You should check the permissions of the .viminfo file. You might need to change owner of the file to your current user using chown or sudo chown.

Upvotes: 7

Balint
Balint

Reputation: 1415

Just an issue that caught me out the other day, which may or may not be your problem:

On some Linux systems (e.g. Ubuntu), if the very first time you run VIM, you run it as a super-user, then the $HOME/.viminfo file gets created with root owner and your local user does not have permissions to write to it. This explained why my VIM was not storing command history when it was all configured up correctly.

Bottom line: on a *nix system, locate your .viminfo file, and make sure you have read/write permissions on it.

Upvotes: 78

Ingo Karkat
Ingo Karkat

Reputation: 172520

To check whether Vim supports the 'viminfo' file (which stores the history), :echo has('viminfo'). The corresponding setting must not be empty: :set viminfo?, and :set history? should be greater than one.

If there's a problem writing the viminfo file (though Vim should complain in that case), you could try passing a different location via vim -i /tmp/viminfo

Upvotes: 28

sehe
sehe

Reputation: 392883

You will have to set the viminfo option. Set it in your $MYVIMRC

Update To find out where the option was last set/changed:

:verbose set viminfo?

See http://vimdoc.sourceforge.net/htmldoc/starting.html#viminfo-file

If you exit Vim and later start it again, you would normally lose a lot of information. The viminfo file can be used to remember that information, which enables you to continue where you left off.

This is introduced in section |21.3| of the user manual.

The viminfo file is used to store:

  • The command line history.
  • The search string history.
  • The input-line history.
  • Contents of non-empty registers.
  • Marks for several files.
  • File marks, pointing to locations in files.
  • Last search/substitute pattern (for 'n' and '&').
  • The buffer list.
  • Global variables.

The viminfo file is not supported when the |+viminfo| feature has been disabled at compile time.

You could also use Session files.

Upvotes: 2

Related Questions