Vim Tips Wiki
No edit summary
 
(Added to VersionControl category)
Line 58: Line 58:
 
----
 
----
 
<!-- parsed by vimtips.py in 0.573835 seconds-->
 
<!-- parsed by vimtips.py in 0.573835 seconds-->
  +
[[Category:VersionControl]]

Revision as of 12:10, 6 June 2007

Previous TipNext Tip

Tip: #1282 - Open SVN diff window

Created: July 12, 2006 3:24 Complexity: intermediate Author: Leif Arne Storset Version: 6.0 Karma: 22/18 Imported from: Tip#1282

If you use SubVersion for version control (http://subversion.tigris.org) you will naturally already have set your EDITOR environment variable to 'vim' or 'gvim -f' so you can write commit messages in Vim. But you will also want to view the diff so you can write sensible comments in the log. Opening the diff manually is tedious, so here is a mapping from the F9 key:


map <F9> :new<CR>:read !svn diff<CR>:set syntax=diff buftype=nofile<CR>gg


This opens a new buffer, reads the SVN diff, sets syntax highlighting and tells Vim not to save the buffer, and places the cursor at the top. Since the buffer won't be saved, you may quit using :wqa when you're finished writing the commit message.

Comments

Even more elegant, add this line to your .bashrc (or the startup script for your shell):

export SVN_EDITOR='vim -c new -c "read ! svn diff" -c "set syntax=diff buftype=nofile" -c go'

The only problem is that you must press Enter another time to see the file.

leifarne--AT--storset.net , July 12, 2006 3:44


One concern I have here though is that it will execute a full diff -- not just of those files listed for committing. I frequently only commit a subset of files, and would only want to see those.

Anonymous , July 12, 2006 8:48


I find the 'gvimdiff' bash script here http://yolinux.com/TUTORIALS/Subversion.html#GDIFF works great for diff'ing single files. (Compare your current local copy with the original copy you checked out).

Anonymous , July 12, 2006 17:28


Hi,

I have been solving the same issue, and I came with my plugin for it. It's not of a release quality (no comments, licenses, help etc.) but it works for me quite well. http://www.neuronix.cz/coding/svndiff.vim Place this script into your ~/.vim/plugin directory. I also recommend to do this map:

nnoremap <C-]> :call DiffGoFile()<CR>

If you do "svn commit" and you are presented with vim window, just run ":call SvnCommitReadDiff()". It parses the commit temporary file and presents diff only for files playing active role in the commit. Now you can go over the diff. If you spot a place you want to tweak, just press C-] (like for tags) and the file will be opened with cursor on a place where you have been looking at the diff. Do you changes, save the file and return back to the commit message. Now run ":call SvnCommitReadDiff()" again and the diff will be updated accordingly.

Hope this helps

--

Vladimir 


vlmarek--AT--volny.cz , July 14, 2006 5:57