Archive for February, 2008

Vim Diff

Thursday, February 21st, 2008

For a long time now I’ve wanted to have the current diff of my working copy highlighted in vim. This would help a lot when you’re working in complicated code and want your modifications to pop out in case you’ve missed something. Unfortunately none of the existing tools do exactly what I want, so with the advice of some co-workers I’ve hacked up the svndiff vim script and made it work with git just like I wanted. Now I can turn on or refresh the highlights with Ctl-D and diff against a different branch with “:D <branch>”.

http://tekrat.com/images/vimdiff.jpg


gitdiff.vim
—————
if exists(”loaded_gitdiff”) || &cp
finish
endif
let loaded_gitdiff = 1

map <C-d> :call <SID>Gitdiff()<CR>
map <C-g> :set nodiff<CR>
noremap <unique> <script> <plug>Dh :call <SID>Gitdiff(”h”)<CR>
com! -bar -nargs=? D :call s:Gitdiff(<f-args>)

let g:gitdiff_rev = ”

function! s:Gitdiff(…)
if a:0 == 1
if a:1 == “none”
let g:gitdiff_rev = ”
else
let g:gitdiff_rev = a:1
endif
endif

let ftype = &filetype
let tmpfile = tempname()
let cmd = “cat ” . bufname(”%”) . ” > ” . tmpfile
let cmd_output = system(cmd)
let tmpdiff = tempname()
let cmd = “git diff ” . g:gitdiff_rev . ” ” . bufname(”%”) . ” > ” . tmpdiff
let cmd_output = system(cmd)
if v:shell_error && cmd_output != “”
echohl WarningMsg | echon cmd_output
return
endif

let cmd = “patch -R -p0 ” . tmpfile . ” ” . tmpdiff
let cmd_output = system(cmd)
if v:shell_error && cmd_output != “”
echohl WarningMsg | echon cmd_output
return
endif

if exists(”s:killbuffs”)
2,9999 bdelete
endif
let s:killbuffs = 1
if a:0 > 0 && a:1 == “h”
exe “diffsplit” . tmpfile
else
exe “vert diffsplit” . tmpfile
endif

exe “set filetype=” . ftype

hide
set foldcolumn=0
set foldlevel=100
set diffopt= ” removed filler so we don’t show deleted lines
highlight DiffAdd ctermbg=black ctermfg=DarkGreen
highlight DiffChange ctermbg=black ctermfg=DarkGreen
highlight DiffText ctermbg=black ctermfg=DarkGreen cterm=underline
highlight DiffDelete ctermbg=red ctermfg=white

endfunction

“autocmd CursorHold * call s:Gitdiff()

—————

Tags:



Open Web Vancouver 2008

Monday, February 18th, 2008

It looks like my talk has been accepted at the Open Web Vancouver 2008 conference. I’m really looking forward to this as this will be my first conference that isn’t strictly PHP. There will be a wider range of topics including Ruby on Rails, Python, Javascript, and even some mobile technology.

I’m really impressed with the site organization so far, I’ve got an account that looks like it lets me update my talk summary and tags. The conference is also really reasonably priced at only $150 (+$20 for a t-shirt)! My talk will be the “APC @ Facebook” talk that I’ve given in the past, but of course I’m hoping to update it with some recent changes and hopefully some new features that I’ve yet to complete.

My name has also apparently made it under the title “Some of the big names you can expect to hear”, although my name is the only one where the hyperlink is on “Facebook” rather than my name. I guess I’m riding in on the coat tails so to speak. ;-)

Update:  Turns out somebody does read my blog and the “coat tailing” is no more, thanks!

Tags: