Skip to content

Instantly share code, notes, and snippets.

@masak
Created October 17, 2012 15:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save masak/3906115 to your computer and use it in GitHub Desktop.
Save masak/3906115 to your computer and use it in GitHub Desktop.
Extending a vim editor with native Git functionality

This is a thought experiment, but one I've wanted to try for a long time.

  • Start with an editor that does everything vim does.
  • Remove the ability to load and save files.
  • From now on, all operations happen directly on a repository. You don't save a file, you stage changes. Or stash them. Any save-like operation takes place through git.

There are five views: edit file, status, diff, log, and merge file.

Edit file

  • You can easily switch directly from this view to any of the other three views.
  • Additionally, you can easily switch into this view from the status, or diff views. You're taken to an appropriate place in the file.
  • You can toggle blame information in this view.

Status

  • In this view, you can easily stage and unstage changes that have been made to the files.
  • You can also create a commit in this view. The lightweight way of doing this is just to type a one-line commit comment directly in this view. If you want to write a longer comment, you're taken to the customary "edit file" view.
  • You can stash all your changes from this view, or from the diff or edit views.
  • As opposed to git's own git status, you also get a list of pristine files in this view, so that you can open them for editing. They are listed below staged files, unstaged changed files, and unknown files.
  • You can switch branches in this view.
  • You can create new branches in this view.

Diff

  • If you switch to this view from the edit view, you're taken to the hunk closest to your location in the file.
  • You can make changes directly in the green parts of the diff.
  • This is also the view used to look at individual commits, except that you then also get commit header information at the top.
  • This is the view you would commit --amend in. Just edit the commit comment, or stage/unstage files. There will likely be a yes/no question before the first such change, just to make sure you know you're messing with existing commits.

Log

  • In the log view, you look at commits. You can easily navigate between different commits, as well as toggle various decorations: oneline, branch names, HEAD, tags, graph.
  • You can switch branches in this view.
  • You can create, merge, rebase, or remove branches in this view.
  • You can create, change or remove tags in this view.
  • You can cherry-pick individual commits.
  • From here, you can also easily do interactive rebases. Once you start reordering commits, or editing commit messages, you're taken into "interactive rebase" mode, and only when you choose to exit this mode successfully is the rebase carried out.
  • While you can push and fetch/pull from any view, this view also offers some interactive previews of what you are pushing or fetching.

Merge file

  • Will be accessible from the status view if conflicts happen during some operation. Opening the file takes you into this view.
  • The screen is divided into three windows: one at the top and two at the bottom.
  • You can navigate easily between conflicts.
  • For each conflict, you can choose to pick either of the three versions directly, or to edit the conflict markers yourself and resolve the conflict manually.
  • From this view, you can easily abort the entire operation that caused the conflict. The command for aborting is the same regardless of the original operation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment