Wednesday, February 23, 2011

Vim Usage: viminfo

Yesterday, I talked about the session in vim which is used to store the layout, tabs, files opened records. How about mapping, abbreviate, mark and options, history, register, recent search records?

All of these values are stored in viminfo. To create a viminfo file manually, use ":wviminfo [filename]". In fact, before exiting vim, vim will automatically create a .viminfo file under home directory. To use ":wviminfo" is to create a viminfo explicitly. It is because .viminfo will be updated every vim exits. Who know what you do after using vim. Thus, it is better to create a viminfo by yourself such that the viminfo file you created will not be changed no matter how you use vim later (unless you save the viminfo file with same file name). Which ":wviminfo" will save what values and numbers of records depends on "viminfo" option setting. You can check it by ":set viminfo". If you want to edit it, you can read the manual by using ":help viminfo".

Now, to restore viminfo, just use ":rviminfo [filename]" command. Then, you can restore all values and registers. Thus, you may need to use following command if you need to work on a project to restore the environment with viminfo.

:wviminfo project1.viminfo       " create a viminfo file
:qa                                        " quit vim

Enter vim again, you will see a blank windows. Then, restore the environment from viminfo

:rviminfo project1.viminfo        " read viminfo file

Now, you can get back the vim environment you exit before. If you want to restore the layout and tabs, please read my previous post about using session.

    No comments:

    Post a Comment