Vim record history

Vim

Vim Problem Overview


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?

Vim Solutions


Solution 1 - Vim

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.

Solution 2 - Vim

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

Solution 3 - Vim

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.

Solution 4 - Vim

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.

Solution 5 - Vim

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.

Solution 6 - Vim

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionprathmesh.kallurkarView Question on Stackoverflow
Solution 1 - VimBalintView Answer on Stackoverflow
Solution 2 - VimIngo KarkatView Answer on Stackoverflow
Solution 3 - VimChanakya.sunView Answer on Stackoverflow
Solution 4 - VimAniket AnandView Answer on Stackoverflow
Solution 5 - VimseheView Answer on Stackoverflow
Solution 6 - VimChristopher BroderickView Answer on Stackoverflow