Session saving function of VIM

Source: Internet
Author: User
Use Vim to develop software projects-(2) sessions and viminfo


The help entry for the commands used in this section:

: Help mksession
: Help 'sessionoptions'
: Help Source
: Help wviminfo
: Help rviminfo
: Help 'viminfo

Many software have this function: when you start the software next time, it will automatically restore you to the environment you exited last time, restore the window layout, open files, or even the last setting.

So does Vim have this function?

Of course the answer is yes! This requires the SAVE and restore functions of VIM sessions and viminfo.

This
The session and viminfo mentioned in, including the editing environment in your use of VIM this time, VIM can save the editing environment, and then you can restore
This environment. When developing software projects, the cycle is not one or two days. If you quit Vim halfway and cannot restore the original editing environment, you need to re-open the file you opened and redefine you.
The ing and abbreviation of the tag, locate the position of the tag you set, and reset the settings of the project ...... It's not a problem!

To restore the last editing environment, we need to save two different types of information: session information and viminfo information.

-Views of all windows are saved in the session information, and global settings are added.
-The viminfo information contains the command line history, search string history, input line history, non-empty register content, file location tag, recent search/replacement mode, buffer list, and global variable and other information.

We will introduce them separately below.

[Session]

We can use ": mksession"
Command to create a session file. If the file name is omitted, a session file named session. Vim is automatically created. A session file is essentially a Vim script. You can use the preceding command to generate a session file, and then view the content to gain an in-depth understanding of the session file.

Which information is stored in the session file'
Optional. Default 'sessionoptions'
Select
Items include "Blank, buffers, curdir, folds, help, options, tabpages, winsize", meaning that the session file will be restored when
Edit the blank window of the environment, all the buffers, the current directory, folding information, help window, all options and mappings, all tabs, and window size.

If you use Vim on Windows and want your session files to be used by VIM in windows and VIM in UNIX, run 'sessionoptions'
Add 'slash'
And 'unix'
The former replaces '/' with '/' in the file name, and the latter saves the line break of the session file in UNIX format.

If you do not want to save the current path in the session, but want the directory where the session file is located to automatically become the current working directory, you need'
Remove 'curdir'
, Add 'sesdir'
,
In this way, the directory where the file is located is set to the current working directory of VIM each time the session file is loaded. When you access other projects through the network, or your project has multiple different versions (in different projects
This option is useful when you want to always use a session file: you only need to copy the session file to a different directory and then use it. The session file stores the relative path of the file, while
It is not an absolute path.

We use ": mksession" above"
Command to create a session file. How can I use the session file to restore the editing environment? Very simple. You only need to use "Source {file }"
To import session files. Because the session file is a script that stores the ex command, "Source"
The command only executes the ex command in the session file once.

[Viminfo]

Use ": wviminfo
You can manually create a viminfo file.

When Vim exits, A. viminfo file is saved in the user's home directory every time. We use ": wviminfo
"Command is to manually create a viminfo file, because the default. the viminfo file will be automatically updated every time you exit Vim. Who knows what Vim has to do after you close the current software project? In this case, the information in. viminfo may be irrelevant to your software project. Or manually save an insurance policy.

": Wviminfo
"Command to save the content, and the number of saved content, by 'viminfo'
The option determines that the value of this option is different from the default value on Windows and Linux. For more information, see the manual.

To read the saved viminfo file, use ": rviminfo
"Command.

Now, back to our example, we still capture images in the previous article. Let's take a look at our current directory and execute ": pwd
","/Home/easwy/src/vim70 "is displayed
", And then run the following command:

: Cd src 'Switch to the/home/easwy/src/vim70/src directory

: Set sessionoptions-= curdir' remove curdir from session Option

: Set sessionoptions + = sesdir 'add sesdir to the session option.

: Mksession vim70.vim 'create a session file

: Wviminfo vim70.viminfo 'create a viminfo File

: QA 'exit Vim

After exiting vim, Run "gvim &
", Enter Vim again, and a blank window is displayed. Then run the following command:

: Source ~ /Src/vim70/src/vim70.vim 'load the session file

: Rviminfo vim70.viminfo 'reads the viminfo File

It's great, and it's restored to the status when I exited yesterday! Continue to work ~~~~

[Reference document
]
1. Vim Help File
2. http://vimcdoc.sourceforge.net/

 

 Original article address

Http://blog.csdn.net/easwy/archive/2007/02/16/1511021.aspx

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.