![]() ![]() ( :mksession can be abbreviated to :mks, too.) Restoring session filesĪgain, restoring a session consists of sourcing the script file we saved. Lengthy, I know, but don’t worry - very soon we’re going to set things up so we don’t have to type stuff like that manually. Given all this, saving a session will look something like this: :mksession ~/vim-sessions/dy-project-name.vim Don’t worry about making the filenames too long, because we’re going to prevent you from having to type the whole thing, and don’t worry too much about having to remember the filename, because we’re going to be showing a list of existing files when we need to. vim, since technically these are Vim script files, and this could make them easier to identify in the future. Note that I’m also giving the file the extension. Within that directory, we can plan ahead to help us sort through the files that will eventually populate it by prefixing each filename with some kind of broad project/area/responsibility “scope” for instance, all my sessions for DockYard projects might start with dy-: dy-project-name.vim. We’ll think about some more advanced solutions later. To begin, we’re going to do the easy thing and commit to saving all our session files in a single subdirectory of our home directory. In the coming blog posts, I’m going to tackle each of these obstacles, hopefully leaving you with a path to session management that makes sense for you, from a light touch with a few remaps (for you Vim purists) to a more complete solution with plugins. Session updating: Sessions don’t “auto-update” when you make changes to your environment, so if I open a new tab, for instance, and I want that to be part of the session I saved earlier, I have to remember to do another :mksession, remembering the location and name of the file in the process.Knowing myself, this feels like it would result in sessions saved all over my disk, never to be opened again. Loading sessions: As if it isn’t hard enough to know where to save session files, if they’re to be useful at all, I’ve got to remember later where I saved them.I could store the file somewhere in my home directory, which feels too removed from my project and could litter that directory, or I could save somewhere inside my current working directory - but I rarely know exactly what that is at any given moment, and I don’t want to inadvertently save my session files deep into a project’s hierarchy. I’m terrible at deciding where to store files and what to name them, so even the first step of creating the session file has enough friction to send me running from sessions. I’ve always found this to be too burdensome to use for a couple reasons: You restore the session by sourcing it with this command: :source ~/sessionname Vim will save your environment into this file to be asked for later. ~/sessionname can be any path and filename you like. You can save this setup with the following command: :mksession ~/sessionname It looks something like this: Say you are working on a project and you have all your buffers and windows and tabs and folds and marks set up just how you want them, but you need to quit Vim for some reason. 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. From :help session:Ī Session keeps the Views for all windows, plus the global settings. ![]() Later, you can load these things from that same file to restore your session just as you left it. Vim sessions work by saving info about your open buffers, windows, and other stuff to a Vim script file on your disk in a location you specify. Hopefully if you’ve been keeping sessions at arm’s length up till now, there’ll be something in these posts that you’ll find useful.įirst, though, an introduction. It isn’t perfectly streamlined, but it does a lot of what I need with some (optional) small plugins and a minimum of damage to my ~/.vimrc. Now that I’ve dived in to sessions a little bit recently, I’d like to share the details of my setup over the course of a couple posts. These days I am rapidly switching among many feature branches, where I need a different set of files open in the same project depending on what feature or bugfix I’m working on. I’ve known about sessions in Vim for years, but until recently had never had enough need for them to overcome the relative difficulty of getting a proper workflow set up. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |