Giter Site home page Giter Site logo

gitsessions.vim's Introduction

gitsessions.vim

Description

gitsessions.vim improves on vim's :mksession command (saving open windows, tabs, splits, marks, etc) by eliminating most of the unnecessary work:

  • automatically save, load, and update sessions
  • automatically determine a session save location

Usage

Once sessions have been initialized by running :GitSessionSave, session management is automatically handled thereafter. Opening vim without a file in the project folder will automatically resume a session, and sessions are automatically saved upon exit and entering a buffer (in case vim crashes).

A project directory is based on the location of the git repository and branch name. If you're not in a git repository then it's based on vim's current working directory (determined by where vim was opened).

To load a session, run vim in the same git repository and branch (or path for non-git projects) and previous sessions should automatically be reloaded.

Commands

  • :GitSessionSave save session
  • :GitSessionLoad load session
  • :GitSessionDelete delete session

Example Keybindings

nnoremap <leader>gss :GitSessionSave<cr>
nnoremap <leader>gsl :GitSessionLoad<cr>
nnoremap <leader>gsd :GitSessionDelete<cr>

Options

Change sessions save location

Default session directory is ~/.vim/sessions and can be modified in .vimrc:

let g:gitsessions_dir = 'relative/path/in/.vim/'

Or

let g:gitsessions_dir = '/absolute/path/'

Toggle auto load session behavior

If you don't want the session to be loaded automatically when launching vim, you can disable this behavior:

let g:gitsessions_disable_auto_load = 1

You need to set this variable before loading the plugin.

Toggle session caching behavior

By default the plugin caches the session file so it's not recalculated when switching between buffers. However this means when switching between git branches the user needs manually save to start saving against the new branch's git session.

To disable this behavior and always save vim sessions against the current git branch name please add the following toggle to .vimrc:

let g:gitsessions_use_cache = 0

This does mean that the user has to actively purge the cache (by running GitSessionSave) on all open vim programs using a repository if the underlying git repo has changed branches. For example:

# on terminal 1:
$ cd ~/project && git checkout master
$ vim
<vim> :let g:gitsessions_use_cache = 1
# save / load a gitsession, continue working

# on terminal 2:
$ cd ~/project && git checkout feature_branch

# on terminal 1, vim is still running
# If I exit vim now, it is still using the cached branch and will save to
# the `master` session file instead of `feature_branch`.
# Manually purge the cached session file:
<vim> :GitSessionSave
# If I exit vim now, it will save to the `feature_branch` session file.

* ~550ms when working in extremely large git repositories.

Misc

plugin updates

Vim sessions save plugin state and keybindings. If you update a plugin and load a session, vim might complain about not being able to find old plugin functions that were changed / removed. Either ignore the errors or start a new session from scratch that does not have old plugin state.

git branch names

/ in git branch names are replaced with _. As a result, it is possible to clobber sessions if one branch is named foo/123 and another foo_123 in the same repository.

Installation

Using Vundle

  1. Add Bundle 'wting/gitsessions.vim' to ~/.vimrc
  2. vim +BundleInstall +qall

Using Pathogen

  1. cd ~/.vim/bundle
  2. git clone git://github.com/wting/gitsessions.vim.git

Acknowledgement

This plugin is based on Vim Wikia's Go Away And Come Back entry.

License

Released under MIT License, full details in LICENSE file.

gitsessions.vim's People

Contributors

wting avatar biscuitvile avatar rleon avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.