Vim record history

2020-05-21 07:32发布

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
6条回答
孤傲高冷的网名
2楼-- · 2020-05-21 08:02

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.

查看更多
聊天终结者
3楼-- · 2020-05-21 08:15

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

查看更多
爷的心禁止访问
4楼-- · 2020-05-21 08:19

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.

查看更多
够拽才男人
5楼-- · 2020-05-21 08:20

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.

查看更多
倾城 Initia
6楼-- · 2020-05-21 08:21

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.

查看更多
一夜七次
7楼-- · 2020-05-21 08:23

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

查看更多
登录 后发表回答