Just another tech blog.

A blog abt GNU/Linux, programming, hacking, and my life.

Vim Sessions

Posted by ajay on October 15, 2009

Vim editor also supports sessions just like a browser like firefox.

If you have 8-10 tabs having > 30 files open in vim [ this should be the case if you’re working on a project of reasonably big size] , and you have to reboot your PC or restart x server for that matter, it can get really irritating to close vim, and then open files one by one again :(.

Vim session solve exactly this problem. When you have to close your vim for any such thing, you can just do

:mksession /path/to/session/file.vim

This will store everything in current vim session including all open files, all visible buffers, window sizes and keyboard mappings etc.

Now when you want to restore vim from this particular session, you can just do

command_prompt$  vim -S /path/to/session/file.vim

This will restore everything just the way it was :).

You should have vim compiled with session support in order to be able to do this. I think from version 7 onwards, even the standard vim supports this by default. Also, for the setting to work, you need to add the following line to your .vimrc

set sessionoptions=blank,buffers,curdir,folds,globals,help,localoptions,options,resize,tabpages,winsize,winpos

PS: Vim session doesnt keep track of undo history in each open file.

Advertisements

11 Responses to “Vim Sessions”

  1. Kuba said

    Thanks for this tip! Why I didn’t know about it before? You even don’t realize how many times it could make my life easier.

  2. Sai Mukund Sagar said

    Thanks a lot dude!! Really nice tip..

  3. nitin said

    hi i am kamal from kanpur.you knew that you have ten tabs having greater than 29 files open in vim and you have to reboot your PC or restart x server for that matter, it can get really irritating to close vim, and then open files respectively.
    ==================================================================================================

  4. Jakub said

    Thanks, really useful 🙂

  5. pinterest.com said

    2,600 miles on a Honda – part 4

  6. Yesterday, while I was at work, my sister stole my iPad and tested to see if it
    can survive a 40 foot drop, just so she can be a youtube sensation. My iPad is now
    destroyed and she has 83 views. I know this is entirely off topic but I had to
    share it with someone!

  7. Good day very cool website!! Guy .. Excellent ..
    Superb .. I’ll bookmark your web site and take the
    feeds also? I am glad to seek out a lot of useful information right here within the publish, we
    need develop extra techniques in this regard, thanks for
    sharing. . . . . .

  8. toyota said

    Very good article. I certainly love this website. Thanks!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: