All of lore.kernel.org
 help / color / mirror / Atom feed
* Extremely simple Vim interface for Git
@ 2008-09-06 19:37 Teemu Likonen
  2008-09-07 10:32 ` Michael Wookey
  2008-09-07 13:23 ` Thomas Adam
  0 siblings, 2 replies; 11+ messages in thread
From: Teemu Likonen @ 2008-09-06 19:37 UTC (permalink / raw)
  To: git

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

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2008-09-09  6:27 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-09-06 19:37 Extremely simple Vim interface for Git Teemu Likonen
2008-09-07 10:32 ` 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)"

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.