Vim Tips Wiki
(Remove html character entities)
(Change <tt> to <code>, perhaps also minor tweak.)
 
(10 intermediate revisions by 4 users not shown)
Line 3: Line 3:
 
|id=1282
 
|id=1282
 
|previous=1280
 
|previous=1280
|next=1284
+
|next=1285
|created=July 12, 2006
+
|created=2006
 
|complexity=intermediate
 
|complexity=intermediate
 
|author=Leif Arne Storset
 
|author=Leif Arne Storset
Line 18: Line 18:
 
</pre>
 
</pre>
   
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 <tt>:wqa</tt> when you're finished writing the commit message.
+
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 <code>:wqa</code> when you're finished writing the commit message.
   
 
==Comments==
 
==Comments==
  +
See {{script|id=90}} for VCS integration with Vim.
Even more elegant, add this line to your .bashrc (or the startup script for your shell):
 
  +
 
Add this line to your .bashrc (or the startup script for your shell):
 
<pre>
 
<pre>
export SVN_EDITOR='vim -c new -c "read ! svn diff" -c "set syntax=diff buftype=nofile" -c go'
+
export SVN_EDITOR='vim -c "4,\$!cut -c-5 --complement | xargs svn diff --no-diff-deleted -x --ignore-eol-style" -c "set syntax=diff" +0'
 
</pre>
 
</pre>
   
  +
Or for a separate window:
The only problem is that you must press Enter another time to see the file.
 
  +
<pre>
  +
export SVN_EDITOR='\
  +
vim -c "4,\$y" \
  +
-c "below new" \
  +
-c "put" \
  +
-c "set syntax=diff buftype=nofile nowrap nobackup previewwindow bufhidden=delete" \
  +
-c "silent execute \"%!cut -c-5 --complement | xargs svn diff --no-diff-deleted -x --ignore-eol-style\" | redraw" \
  +
-c "wincmd k" +0'
  +
</pre>
   
  +
Replace <code>below new</code> with <code>vnew</code> for a vertical split.
----
 
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.
 
   
 
----
 
----

Latest revision as of 06:17, 13 July 2012

Tip 1282 Printable Monobook Previous Next

created 2006 · complexity intermediate · author Leif Arne Storset · version 6.0


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 for 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[]

See script#90 for VCS integration with Vim.

Add this line to your .bashrc (or the startup script for your shell):

export SVN_EDITOR='vim -c "4,\$!cut -c-5 --complement | xargs svn diff --no-diff-deleted -x --ignore-eol-style" -c "set syntax=diff" +0'

Or for a separate window:

export SVN_EDITOR='\
                vim -c "4,\$y" \
                -c "below new" \
                -c "put" \
                -c "set syntax=diff buftype=nofile nowrap nobackup previewwindow bufhidden=delete" \
                -c "silent execute \"%!cut -c-5 --complement | xargs svn diff --no-diff-deleted -x --ignore-eol-style\" | redraw" \
                -c "wincmd k" +0'

Replace below new with vnew for a vertical split.


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).