DEV Community

Cover image for Vim to the rescue: Sessions
Angad Sharma
Angad Sharma

Posted on

Vim to the rescue: Sessions

Introduction

One of the reasons that people go for IDEs is that the moment you open one, you have everything exactly how you want it. With a file browser on the left hand side, coding window on the right and an attached terminal below. But whenever you open vim, you have to open the file browser and terminal from scratch.

Alt Text

Well there is a quick way around it. You can actually store sessions in vim. You can then open that particular session to see exactly what you want to see.


Creating a session in vim

Open vim. Now open the programs that you want to see in your session. Let us open the Lex file browser:

:Lex
Enter fullscreen mode Exit fullscreen mode

Now let us open any file, and the open a terminal below by running the following command:

:bel term
Enter fullscreen mode Exit fullscreen mode

To save a session, you can use the mks[ession] command. Note that all sessions have a .vim extension. Vim sessions also store the split sizes, so feel free to resize your terminal without worrying about ever doing it again after opening vim

:mks session.vim
Enter fullscreen mode Exit fullscreen mode

You can now safely exit out of vim without worrying about loosing your layout. You will be able to see a session.vim file in your current directory. To open it use the -S flag in vim:

vim -S session.vim
Enter fullscreen mode Exit fullscreen mode

A few things to note

  • If you add a ! symbol after mks, it overwrites the file you specify.
  • If no file name is supplied then the default file is Session.vim
  • Want to store multiple files open on multiple tabs? Go ahead!
  • Want to use additional UI details while opening a session? Go ahead and create a x.vim file in the same directory and go ahead.

Top comments (0)