#vim #neovim #command-line #file-manager #mksession

bin+lib vsm

A simple, interactive, command line vim session file manager

2 releases

0.1.1 Nov 11, 2022
0.1.0 Nov 10, 2022

#29 in #vim

Custom license

300KB
930 lines

Vim Session Manager


Crates.io Crates.io docs.rs Crates.io

A BLAZINGLY FAST, simple, interactive command line session manager

Table of Contents

Background

If you use vim or neovim on a daily basis and work in large codebases, it is probably not uncommon for you to have 10+ tabs open at a time, with various splits. Once you close this vim session the layout is lost to the ethers. the mksession command in vim(neovim) can save you, thus saving the session to a directory, promising to return you to your work exactly how you left it. However, the problem is most of us accrue many of these session files scattered about, personally I have 41 vim session files, easily loading them, rememembering the context of each one, and removing stale sessions becomes a hassle. enter vsm (Vim Session Manager), it allows you to list, open, and remove sessions files, either interactively or by name. It also manages different variations of vim, and allows you to switch between them. For example you may be a neovide user rather than neovim, vsm currently supports vim, neovim, neovide and gvim.

Similar projects

Currently I have only found one other project which allows more indepth session file management. However it didn't suit my desires, as it is written in vim script, suffers from useless feature rot, and relies heavily on the xolox misc plugin, together loading in over 1200 or so lines of vim script just to manage some session files, it also seems to be unmaintained as the last change recorded was July 6, 2014. Because of this I wrote vsm, it seemed like a better solution to make an external cli program and off load work from vim and shorten my plugin list as much as possible.

Install

Install with cargo

cargo install vsm

Building from source

Installs the optimized binary to $HOME/.local/bin

git clone https://gitlab.com/thebashpotato/vsm
cargo install just
just install

Usage

Set up

An environement variable VIM_SESSIONS is expected on the system, if it is not defined vsm will default to ~/.config/vim_sessions when it looks for your session files. Below are 2 examples for settings the variable in different shells. You can set the path where ever you want.

  • bash/zsh export VIM_SESSIONS="$HOME/.config/vim_sessions"

  • fish set -Ux VIM_SESSIONS "$HOME/.config/vim_sessions"

Create session files easier (in vim)

vsm can load, list and remove session files, but it can't create them. That is the job of vim.

Add the below snippet to your .vimrc or init.vim to make creating new session files much easier. Now in normal mode you can press mk to quickly save your session file.

if isdirectory(expand($VIM_SESSIONS))
  " Create a new sesion file (must give the file a unique name
  nnoremap mk :mksession $VIM_SESSIONS/
  " Overwrite an existing sessioon file with your current layout
  nnoremap mo :mksession! $VIM_SESSIONS/
else
  nnoremap mk :echo "VIM_SESSIONS directory does not exist"<CR>
  nnoremap mo :echo "VIM_SESSIONS directory does not exist"<CR>
endif

Development

Only requires just to bootstrap all tools and configuration.

cargo install just
just init # setup repo, install hooks and all required tools

To run:

just run

To test:

just test

Before committing your work:

just pre-commit

To see all available commands:

just list

Maintainers

@thebashpotato

Contributing

PRs accepted.

Small note: If editing the README, please conform to the standard-readme specification.

License

This project is licensed under:

Dependencies

~9–20MB
~286K SLoC