git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Teemu Likonen <tlikonen@iki.fi>
To: git@vger.kernel.org
Subject: Extremely simple Vim interface for Git
Date: Sat, 6 Sep 2008 22:37:44 +0300	[thread overview]
Message-ID: <20080906193744.GA3122@mithlond.arda.local> (raw)

Here's a very simple idea for using Git from Vim editor. Add these lines 
to your ~/.vimrc file:


    command! -complete=file -nargs=* Git   call s:RunShellCommand('git '.<q-args>)
    command! -complete=file -nargs=* Svn   call s:RunShellCommand('svn '.<q-args>)
    command! -complete=file -nargs=+ Shell call s:RunShellCommand(<q-args>)

    let $EDITOR = '/usr/bin/gvim --nofork'

    function! s:RunShellCommand(cmdline)
        botright new
        setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile
        setlocal nowrap
        call setline(1,a:cmdline)
        call setline(2,substitute(a:cmdline,'.','=','g'))
        execute 'silent 2read !'.escape(a:cmdline,'()%#')
        setlocal nomodifiable
        1
    endfunction


Now, command :Git works just like "git" from shell except that the 
output is displayed in a Vim scratch buffer/window. The buffer will be 
wiped out from memory when the window is closed. Filename completion and 
piping works. Examples:

    :Git diff --cached
    :Git help merge
    :Git branch | column

(I am aware that there are VCS plugins for Vim. I happen like this 
approach better because it works just like the command line Git which 
I'm familiar with.)

As a "side effect" this also adds similar :Svn command as well as :Shell 
command which can be used to run any shell command and have its output 
displayed in a Vim window. Using the first two letters of :Shell is 
enough in my system because I don't have other custom commands which 
start with letters "Sh".

    :Sh ls -l

             reply	other threads:[~2008-09-06 19:38 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-09-06 19:37 Teemu Likonen [this message]
2008-09-07 10:32 ` Extremely simple Vim interface for Git Michael Wookey
2008-09-07 13:13   ` Teemu Likonen
2008-09-07 17:46     ` Teemu Likonen
2008-09-07 22:47     ` Michael Wookey
2008-09-08  5:26       ` Teemu Likonen
2008-09-07 13:23 ` Thomas Adam
2008-09-07 13:59   ` Teemu Likonen
2008-09-07 14:11     ` Thomas Adam
2008-09-08 17:41   ` Bob Hiestand
2008-09-09  6:26     ` "Peter Valdemar Mørch (Lists)"

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080906193744.GA3122@mithlond.arda.local \
    --to=tlikonen@iki.fi \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).