Session-Viminfo-Management


Ⅰ. 插件描述

My Vim plugin. It provide great convinience to save and load your Vim session and viminfo files automatically.

Ⅱ. 基本信息

创建日期:  2014-08-15
使用用户:  1
Github星:  5
插件作者:  Brant Chen

Ⅲ. 安装方法

使用Vundle管理器安装

在你的.vimrc下添加:
Plugin 'xkdcc/session-viminfo-management'
… 然后在Vim中运行以下命令:
:source %
:PluginInstall

对于Vundle版本 < 0.10.2,请用上面的Bundle替换Plugin。

使用NeoBundle管理器安装

在你的.vimrc下添加:
NeoBundle 'xkdcc/session-viminfo-management'
… 然后在Vim中运行以下命令:
:source %
:NeoBundleInstall

使用VimPlug管理器安装

在你的.vimrc下添加:
Plug 'xkdcc/session-viminfo-management'
… 然后在Vim中运行以下命令:
:source %
:PlugInstall

使用Pathogen管理器安装

在终端中运行以下命令:
cd ~/.vim/bundle
git clone https://github.com/xkdcc/session-viminfo-management

Ⅳ. 文档说明

Session-Viminfo-Management

The plug-in improves upon Vim's built-in :mksession and :wviminfo commands.
It provide great convinience to save and load your Vim session and viminfo files automatically.
Typically, you can save your Vim session and viminfo files in one command and load them efficiently.
Even better, it can automatically load/save vim session and viminfo files when entering vim and leaving vim environment.
That are very useful if you want Vim to quickly swith between different projects, automatically loading the files you were last working on in that project, and enable you to continue where you left off.

Terminology and Default Values

Workspace files: I will shortly call vim session and viminfo files as "Workspace files" in this manual.
workspace: All prompt messages in Vim prefixed with "workspace:" are from this Session-Viminfo-Management plugin.
Default Values:

  • Default name for workspace files is:
    workspace.session
    workspace.viminfo
  • Default saving path:
    vim current path (Type Vim Ex command getcwd() to get it)

Installation

Download zip ball and copy files to ~/.vim/plugin/session-viminfo-manage.vim and ~/.vim/doc/session-viminfo-manage.txt. Or copy and paste:

cd ~/.vim
git clone https://github.com/xkdcc/Session-Viminfo-Management.git 
mv Session-Viminfo-Management/plugin/* ~/.vim/plugin/ && mv Session-Viminfo-Management/doc/* ~/.vim/doc/
rm -fr Session-Viminfo-Management/

Normally to generate documentation, Vim expects you to run :helptags on each directory with documentation (e.g., :helptags ~/.vim/doc).

Automation

This plugin provides automation ability when launching Vim and leaving Vim.

Launching Vim

When launching Vim, this plugin will detect current path and load default workspace files(workspace.session and workspace.viminfo) if exist.
If no default workspace files found, it will check whether there are files having suffix ".session" and ".viminfo" in pair.
If yes, it will prompt a list for user selection if there are more than one pair.

Example 1:

If you're at /home/test, there are:

  • workspace.session
  • workspace.viminfo
  • test.session
  • test.viminfo

When you launch vim, it will load workspace.session and workspace.viminfo with prompt message by default. As following illustration:
vim01-automation-launching.png

Example 2:

If you're at /home/test, there are:

  • test01.session
  • test01.viminfo
  • test02.session
  • test02.viminfo

When you launch vim, it will list all workspace files for your choice.
As following:

  workspace: Please input the expected workspace index you want to load:
    [0] /home/test/test01
    [1] /home/test/test02
  Your input(q to exit this function of workspace plugin):

Then you type a legal number in range(0,1), it will load the specific workspace files. Also you can type 'Q' or 'q' to do nothing with workspace files. If you give an exception, you will be required to input again. As following illustration:
vim02-automation-launching.png

There is a little compatible problem in some tty console. Please read "Limitation and Known issues" section in this Readme.md for more details.

Leaving Vim

Example 1:

  : Savews my.ws
  : Loadws wow.ws
  : Savews new.ws
  : qa

Result:

This plugin will automatically save session and viminfo files to the last workspace files

  • new.session
  • new.viminfo

As following illustration:
vim03-automation_leaving_new.ws.png

Ex Commands

This plugin provide two Ex commands: Savews, Loadws.

Savews

Save vim session and viminfo files when you type Ex command :Savews with proper arguments.
Particularly, if option wsOverwrite is 1(This is default value), when you exit from Vim, this plugin will save session and viminfo files to your last saved/loaded workspace files automatically.

Example 1:

  :Savews    

Result:

Will create workspace.session and workspace.viminfo in current folder, if they didnot existed beforehand.

Please see |'wsOverwrite'| for more details about overwrite behavior.

Example 2:

  :Savews /home/myproject 

Result:

Will create:

  • /home/myproject/workspace.session
  • /home/myproject/workspace.viminfo
    Please make sure folder /home/myproject existed beforehand.

Please see |'wsOverwrite'| for more details about overwrite behavior.

Example 3:

  :Savews my.ws

Result:

Save to my.session and my.viminfo in current folder.

Please see |'wsOverwrite'| for more details about overwrite behavior.

Example 4:

  :Savews /home/myproject/my.ws

Result:

You will get my.session and my.viminfo in /home/myproject folder if /home/myproject existed.

Please see |'wsOverwrite'| for more details about overwrite behavior.

Two point please keep in mind when using Savews:

  • You must have suffix .ws , if you want to specify name for session and viminfo files, like example 3 and example 4.
    Otherwise, they will have default name, workspace.session and workspace.viminfo.
  • Please remember to use :qwa to quit Vim if you want to reopen all windows/tabs you're editing.

    The reason is that Savews command will save workspace files automatically when you exit Vim. So if you have opened many windows/tabs, but closed them one by one, there would be only one window is openning just before you exit Vim, workspace plugin will only can remember the last window and just reopen it for you when you enter Vim next time by loading your workspace files.

Loadws

Load vim session and viminfo files.

Example 1:

  :Lavews    

Result:

Will load workspace.session and workspace.viminfo in current folder, if they existed beforehand.

Example 2:

  :Lavews /home/myproject 

Result:

Will load:

  • /home/myproject/workspace.session
  • /home/myproject/workspace.viminfo
    Please make sure workspace files existed beforehand.

Example 3:

  :Lavews my.ws

Result:

Will load my.session and my.viminfo in current folder.

Example 4:

  :Lavews /home/myproject/my.ws

Result:

Will load my.session and my.viminfo in /home/myproject folder if existed.

You'd better not to run :Loadws in same Vim twice. Please read "Limitation and Known issues" section in this Readme.md for more details.

Options

There is one global option you can use: wsOverwrite.

wsOverwrite

Value: 0 or 1.

Default: 1.

If there are vim session and viminfo files with same name when you issue :Savews, you can overwrite them by setting this option to 1:

  let g:wsOverwrite=1

If g:wsOverwrite is 0, and there are workspace.session and workspace.viminfo, when you type:

  :Savews

It will said:

Workspace files existed, and wsOverwrite is 0, will not overwrite existed files.

IT RECOMMENDED STRONGLY YOU KEEP IT DEFAULT AS 1.
BECAUSE IF IT'S 0, WHEN YOU EXIT VIM, IT WON'T SAVE YOUR WORKSPACE FILES AUTOMATICALLY.

Limitation and Known issues

  • Windows is not a target of this plugin.
    You might experience some problmes if you want to use this plugin on Windows Vim.
  • There is compatible problem when work with autochdir option. Recommend to remove autochdir option from your ~/.vimrc.
    For my experiences, if enable autochdir option in Vim, users will mess up themselves when trying to provide relative pathes of Vim session and viminfo files. It seems it can't have impact if you provide absolute path for Vim session and viminfo files.
  • There is a little compatible problem in some tty console.
    In some tty console, when launching Vim and this plugin prompt a workspace list for your choice, after you input your choice, it will echo all message one time. Anyway, the function still works.As following illustration:

vim04-automatino-luanching-dup-echo

  • You'd better not to run :Loadws in same Vim twice.
    If you once run Loadws to load your workspace files, then run Loadws to reload them again in the same Vim, it will not close all openning windows and tabs. In other words, you may see double windows have been opened for the same file.

License

This software is licensed under the MIT License.
Copyright 2014 Brant Chen (brantchen2008@yahoo.com).

Welcome to Brant Blog

Brant's Blog

Follow Me on Social Networking

Brant's Google+
Brant's LinkedIn
Brant's Facebook
Brant's Twitter

添加新评论