I love to have a lot of tabs open at the same time in Vim. Being the deputy Scrum master (Yeah, it is a thing) of our dev-team, I have to keep track of a lot of things going on in the team. I maintain a repository of all the links to product documentation, stories, tasks etc. I also need to keep track of the discussions that happened in various team meetings. On top of this, as a backend engineer I have my own stories and tasks to manage as well. All of this means that, I have a ton of tabs and splits open at any given time in Vim. Something like the following:

Vim multiple tabs open

Now, the problem comes when I have to shutdown and start my computer. All the tabs I have kept open for several days will be gone and I have to open them up all again and put them in the order I want. Oh, the pain!. There has to a better way!

There has to be a better way

Luckily for us, Vim always has a better way to do something. There is an inbuilt feature just for this.

It is called Vim-sessions and with that you can get back all your tabs with just one command. How nice!

How to create a new session?

To create a vim session, run the command :mksession episodes.session. Here episodes is the name of the session I want to create.

In short, :mks <session-name>.session. And that’s it. Your session is now saved. It saves information about what tabs are currently open, what splits are open and even what buffers are open, all into that session file.

Note: The .session suffix is not needed. But it is the preferred way as you can easily identify the session file.

Once this is done, you can go ahead and close your tabs as all of that is stored in the session file.

How to open an existing session?

The next time you want to open all of those tabs, all you have to do is tell Vim to run that session. You do that by running the command :so <session-file-path>(:so is short for :source).

And boom! All of your windows and tabs are back with just one command. You don’t have to have multiple tmux or screen buffers running anymore. Vim can do all of that with just one command.

That is all you need to know about sessions in vim to make yourself productive. You can always try the vim help with :help session-file and find out more.


For more Vim articles, checkout Freblogg/Vim

Beginner Vim Tutorials - Your First Lesson In Vim

Vim Color scheme used: Eclipse


This is the first article as part of my twitter challenge #30DaysOfBlogging. Twenty-nine more articles on various topics including but not limited to Java, Git, Vim, Software Development, Python, to come.

If you are interested in this, make sure to follow me on Twitter @durgaswaroop.


If you are interested in contributing to any open source projects and haven’t found the right project or if you were unsure on how to begin, I would like to suggest my own project, Delorean which is a Distributed Version control system, built from scratch in scala. You can contribute not only in the form of code, but also with usage documentation and also by identifying any bugs in the functionality.


Thanks for reading. See you again in the next article.



Published

Category

software

Tags