Simple Vim interface for Bazaar

Teemu Likonen tlikonen at iki.fi
Sun Sep 7 21:55:04 BST 2008


Here's a very simple bzr plugin for Vim editor. Actually this is 
a plugin to run any shell commands and have their output displayed in 
a Vim scratch buffer. Anyway, Vim commands for some VCS tools are 
included for convenience.

I'm aware that there are VCS plugins for Vim. I made this because I like  
to use the same interface as the command line tools and without 
restrictions. Filename completion and piping works, and Vim command line 
expands % to current filename. Inside Vim, :Bzr command works just like 
"bzr" from shell. Commands :Git, :Hg and :Svn work similarly. Examples:

    :Bzr log -l20
    :Bzr diff -c -1
    :Bzr annotate %
    :Bzr help merge

    :Git shortlog -ns %
    :Hg heads
    :Svn info

    :Shell ls -a | column


" Add the following lines to your ~/.vimrc file or save them to a file 
" in ~/.vim/plugin/ directory.

command! -complete=file -nargs=* Bzr call s:RunShellCommand('bzr '.<q-args>)

" Other VCS tools
command! -complete=file -nargs=* Git call s:RunShellCommand('git '.<q-args>)
command! -complete=file -nargs=* Hg call s:RunShellCommand('hg '.<q-args>)
command! -complete=file -nargs=* Svn call s:RunShellCommand('svn '.<q-args>)

" Run any shell command
command! -complete=file -nargs=+ Shell call s:RunShellCommand(<q-args>)

" Shell commands may launch $EDITOR so we need to set it to something
" that works inside Vim.
let $EDITOR = '/usr/bin/gvim --nofork'

function! s:RunShellCommand(cmdline)
    botright new
    setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile nowrap
    call setline(1,a:cmdline)
    call setline(2,substitute(a:cmdline,'.','=','g'))
    execute 'silent $read !'.escape(a:cmdline,'()%#')
    setlocal nomodifiable
    1
    if search('\m\C^--- .*\n+++ .*\n@@','n')
        setlocal filetype=diff
    endif
    if a:cmdline =~ '\m\C^git '
        2match Statement /\v\C<commit \x{7,}>/
    elseif a:cmdline =~ '\m\C^bzr log'
        2match Statement /\v-{50,}/
    endif
endfunction



More information about the bazaar mailing list