Vimagit

A new way to use git within vim


Project maintained by jreybert Hosted on GitHub Pages — Theme by mattgraham

vimagit

This is a new (and hopefully very efficient) way to use git from vim.

From a very single vim buffer, you can perform all basic git operations. To name a few:

Example of vimagit 1.5.1

Some screencasts:

This workflow is 100% inspired from magnificent emacs Magit plugin.

Take a look at TL;DR to start using it immediatly.

Outstanding features

More to come:

Why should I use vimagit, there are already plethora git plugins for vim?

Integration

Branches master and next are continuously tested on travis when published on github.

vimagit is tested with various versions of vim on linux: vim 7.3.249, vim 7.4.273, and latest neovim version. It is also tested for macos X: vim, macvim and neovim. Anyway, if you feel that vimagit behaves oddly (slow refresh, weird display order...) please fill an issue.

For the most enthusiastic, you can try the branch next. It is quite stable, just check its travis status before fetching it.

Travis status:

TL;DR

This is the minimal required set of command you must know to start playing with vimagit. See Mapping for a complete description.

To simply test vimagit, modify/add/delete/rename some files in a git repository and open vim.

:Magit

Open magit buffer with :Magit command.

N

S

CC

Once you have stage all the required changes, press CC. A new section "Commit message" appears and cursor move to it. Type your commit message, in Insert mode this time. Once it's done, go back in Normal mode, and press CC: you created your first commit with vimagit!

Usage

Sections

IMPORTANT: mappings can have different meanings regarding the cursor position.

There are 5 sections:

Inline modifications

Visual selection

It is possible to stage part of hunk, by different ways:

Visual selection and marked lines have some limitations for the moment:

Commands

magit#show_magit()

Function to open magit buffer. This buffer will handle the git repository including focused file. It is possible to handle multiple git repositories within one vim instance.

It takes 3 parameters:

:Magit

Open magit buffer in a vertical split (see details).

:MagitOnly

Open magit buffer in current window (see details).

You can create a bash alias like magit="vim -c MagitOnly"

Mappings

For each mapping, user can redefine the behavior with its own mapping. Each variable is described in vimagit help like vimagit-g:magit_nameofmapping_mapping

Global mappings

Following mappings are broadly set, and are applied in all vim buffers.

<Leader>M

Open Magit buffer

Local mappings

Following mappings are set locally, for magit buffer only, in normal mode.

Enter,<CR>
zo,zO
zc,zC
S
F
L
M
DDD
N,P
CC
CA
CF
I
R
q
h

Options

User can define in its prefered |vimrc| some options.

g:magit_enabled

To enable or disable vimagit plugin. Default value is 1.

let g:magit_enabled=[01]

g:magit_show_help

To disable chatty inline help in magit buffer (default 1)

let g:magit_show_help=[01]

g:magit_default_show_all_files

When this variable is set to 0, all diff files are hidden by default. When this variable is set to 1, all diff for modified files are shown by default. When this variable is set to 2, all diff for all files are shown by default. Default value is 1. NB: for repository with large number of differences, display may be slow.

let g:magit_default_show_all_files=[012]

g:magit_default_fold_level

Default foldlevel for magit buffer. When set to 0, both filenames and hunks are folded. When set to 1, filenames are unfolded and hunks are folded. When set to 2, filenames and hunks are unfolded. Default value is 1.

let g:magit_default_fold_level=[012]

g:magit_default_sections

With this variable, the user is able to choose which sections are displayed in magit buffer, and in which order. Default value:

let g:magit_default_sections = ['info', 'global_help', 'commit', 'staged', 'unstaged']

g:magit_warning_max_lines

This variable is the maximum number of diff lines that vimagit will display without warning the user. If the number of diff lines to display is greater than this variable, vimagit will ask a confirmation to the user before refreshing the buffer. If user answer is 'yes', vimagit will display diff lines as expected. If user answer is 'no', vimagit will close all file diffs before refreshing. Default value is 10000.

let g:magit_warning_max_lines=val

Installation

The plugin hierarchy tree respects the vim plugin standard. It is compatible with pathogen (and most probably vundle).

To install:

cd ~/.vim/bundle
git clone https://github.com/jreybert/vimagit

Requirements

This part must be refined, I don't see any minimal version for git and vim, but for sure there should be one.

At least, it is tested with vim 7.3.249 and git 1.8.5.6 (see Integration).

Credits

License

Copyright (c) Jerome Reybert. Distributed under the same terms as Vim itself. See :help license.