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 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

biscuitvile avatar cfsalguero avatar go2null avatar rleon avatar wting avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

gitsessions.vim's Issues

No syntax highlighting for automatic session loading.

Loading a vim session explicitly with vim -S ~/.vim/sessions/path/to/my/gitsessions/vim/session results in expected syntax highlighting.
Loading a vim session automatically with vim results in no syntax highlighting. Reloading the file(s) with :e and I get the syntax highlighting expected.

Does not work with vim-haml

See tpope/vim-haml#49 for the issue caused by loading gitsessions in conjunction with vim-haml. On launch with both gitsessions.vim and vim-haml loaded (I'm currently using Vundle), Vim complains about syntax errors in ~./vim/bundle/haml/syntax/sass.vim and doesn't load the syntax for SCSS. Removing gitsessions.vim from my Vim bundles makes this issue go away.

Issue with branches likes feature/1234-feature

When having branches like feature/1234-feature and trying to save the session, I get the following error:

screen shot 2013-05-29 at 11 15 17 am

The plugin-doesn't seem to create a directory for the 'feature' branch, because my ~/.vim/sessions looks like this:

[master][~/.vim]$ tree sessions                                                                                                                                               
sessions
└── Users
    └── kenny
        └── work
            └── minerva
                └── bookville

add GitSessionList

Hi,

Thanks for the great plugin, I wonder if it could be possible to implement a GitSessionList to know what sessions exists.

XDG directory support & Tmux errors

First of all I would like to thank you for your work! I have long been looking for some sane session management in vim and your plugin is the best option I have found so far. Unfortunately I have found some bugs though. I've been trying at fixing them myself but since I don't know any viml this would be non-trivial for me. I'll just list them here in one list but if you want me to split them up in more scoped bugs I'd be happy to do that too.

  1. It works with Neovim but the sessions dir is hardcoded to ~/.vim directory on *nix systems.
    Neovim uses the xdg default of ~/.config/nvim so it would be great to use that directory when neovim is detected.
  2. When I then tried the option for setting an absolute path with let g:gitsessions_dir = '/absolute/path/' to let g:gitsessions_dir = '~/.config/nvim/sessions/' it didn't work either.
    It looks like the ~ is not properly expanded or escaped because the sessions directory will again be created under .vim with an empty ~ directory.
    Setting the complete path with /Users/username/... works but using ~ is easier and a habit for many people.

Porting the tmux issue into a separate ticket: #19

3. When saving form inside a Tmux session the session file gets a faulty name. In my case: ?Ptmux\;\e\e\]50\;CursorShape=0\cg\emaster. The contents of the file look good but it cannot be loaded afterwards because of the faulty filename.

I think a hashing strategy would fix or avoid some of these errors and also avoid some of the overhead of creating all the shadow directories in the sessions dir.
For example:

if git:
    session_string = fully_qualified_path + git_branch_name
else:
    session_string = fully_qualified_path

session_hash = hash(unique_session_string)

function save(session_hash):
    write(sessions_dir/session_has.vim)

function restore(session_hash):
    read(sessions_dir/session_has.vim)

What do you think? I don't know if this is even possible in viml but I think this would definitely solve some problems.

Unable to use gitsessions within tmux

@olbrew: Porting this issue from #15.

  1. When saving form inside a Tmux session the session file gets a faulty name. In my case: ?Ptmux\;\e\e\]50\;CursorShape=0\cg\emaster. The contents of the file look good but it cannot be loaded afterwards because of the faulty filename.

I think a hashing strategy would fix or avoid some of these errors and also avoid some of the overhead of creating all the shadow directories in the sessions dir.
For example:

if git:
    session_string = fully_qualified_path + git_branch_name
else:
    session_string = fully_qualified_path

session_hash = hash(unique_session_string)

function save(session_hash):
    write(sessions_dir/session_has.vim)

function restore(session_hash):
    read(sessions_dir/session_has.vim)

What do you think? I don't know if this is even possible in viml but I think this would definitely solve some problems.

vim-session compatible version

Don't lose NERDTree/Tagbar buffers, bg colors etc...
Vim-session is great plugin for saving sessions. But it wasn't git or directory based.
Then i found gitsessions.vim, it is handy for autoload and autosave. However the sessions wasn't save properly this time...

And i linked them.

You might check this version from here.

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.