loading...
Cover image for Vim to the rescue: Sessions

Vim to the rescue: Sessions

l04db4l4nc3r profile image Angad Sharma ・2 min read

Vim to the rescue (9 Part Series)

1) Vim to the rescue: Prologue 2) Vim to the rescue: Tree to Markdown 3 ... 7 3) Vim to the rescue: Repetition Made Easy 4) Vim to the rescue: Human Readable Processes 5) Vim to the rescue: Multiple Cursors 6) Vim to the rescue: Sessions 7) Vim to the rescue: Attached Terminal 8) Vim to the rescue: Subduing the Shell 9) Vim to the rescue: PDF Preview

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

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

:bel term

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

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

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.

Vim to the rescue (9 Part Series)

1) Vim to the rescue: Prologue 2) Vim to the rescue: Tree to Markdown 3 ... 7 3) Vim to the rescue: Repetition Made Easy 4) Vim to the rescue: Human Readable Processes 5) Vim to the rescue: Multiple Cursors 6) Vim to the rescue: Sessions 7) Vim to the rescue: Attached Terminal 8) Vim to the rescue: Subduing the Shell 9) Vim to the rescue: PDF Preview

Posted on by:

l04db4l4nc3r profile

Angad Sharma

@l04db4l4nc3r

Backend Developer and DevOps SysAdmin

Discussion

markdown guide