

#Vimr from command line windows#
While working on an ongoing project, it’s possible that your Vim screen has many windows and/or tabs opened, and it helps a lot to be able to save the state before stop working, to be able to open it next day at the same state. It is very useful for projects that have many custom session files, allowing the user to change sessions without exiting Vim.Įxample Use Cases: Daily Saving Sessions of an Ongoing Project If Vim is already running and you want to restore a session, you can use the command :source ( :so) to restore a session, for example, :so my-session.vim. Inside vim, using the :source or :so command: If you need to start from a custom session file, you might provide the file name with the command, example: vim -S my-session.vim. If your project already has a session autogenerated file ( Session.vim), you can start Vim with the command vim -S, and it will look for the Sessions.vim file and start the session. (Assuming your pwd on the terminal is the project’s root directory). There are basically two ways to restore a Vim session: - On the terminal, before starting Vim, with the vim -S option: To Restore a Session ( :source, :so, vim -S) (You may consider creating a vim-sessions/ folder inside your project’s root directory if the number of session files for the project keeps growing). This allows you to save different sessions that can be used to work on different parts of the same project, for example, backend-api.vim, frontend.vim, devops.vim. You can specify a custom file name to save the session :mks! my-session.vim. Using exclamation mark, :mks! the command overwrites Session.vim file if it exists in the directory. If used alone, :mks will create a Session.vim file on the directory where the current Vim execution was started. What the command actually does is that it writes a Vim script file that restores the current session. The :mksession command, or :mks, is responsible for saving the current session. Understanding the Commands: To Save a Session ( :mksession, :mks) Lastly, we’ll create a bonus custom command to help quickly save the session, save modified files, and exit Vim with class, all at once!

In this post, we’ll start by taking a look at the commands used to deal with sessions, and then, check some use cases for different workflows.Īfter that, we’ll bring some attention to whether or not session files should be committed to the project’s git repository.

Vim’s sessions is basically a tool to instantly save the state of everything in your current Vim session, allowing you to restore it the next time, instead of opening from scratch all the tabs/windows/buffers again. You can use a Session to quickly switch between different projects, automatically loading the files you were last working on in that project. You can save a Session and when you restore it later the window layout looks the same.
#Vimr from command line plus#
It’s called sessions.Ī Session keeps the Views for all windows, plus the global settings. Vim provides a native tool to save your time, helping you to get back to the previous mindset of the last time you left the project.
