Also available at

Also available at my website http://tosh.me/ and on Twitter @toshafanasiev

Wednesday, 26 January 2011

Using vim as Visual Studio diff tool

I love vim (http://www.vim.org/). I use it for as much of my work as I can get away with and I have recently started using it as my diff/merge tool for Visual Studio/TFS. So far the diffing has been great but I have yet to use  it to merge conflicted changes, so I can't vouch for that.

To set up vim as your diff tool in Visual Studio choose Tools > Options from the menu and select the Source Control > Visual Studio Team Foundation Server node in the tree on the left (these instructions are TFS specific), giving you this view:


Click the Configure User Tools button and then click Add, giving you this box:


Fill in the values as shown (obviously the Command path may be different on your machine), and hit OK. Use the OK buttons to close the remaining two dialogs.

The file extension can be used to determine what kinds of files are diffed in this way, the command is the program used.

The argument string is as follows:
  • -d puts vim into diff mode (kinda important)
  • -R puts vim into readonly mode (making comparisons safer)
  • %1 and %2 are the names of the files to be compared, the arrow to the right of
    this box gives a full list of those available

Additionally I have added this clause to my .vimrc file:
if &diff
  set columns=240
endif

My .vimrc file specifies 120 columns so doubling this for side-by-side diffing results in a consistent experience.

Setting up for merging is identical except you choose Merge from the operation dropdown and you additionally specify %4 for the merged file name in the argument list (I put this last). Rather obviously, you do not specify -R for merge operations as you need to edit the resulting file.

2 comments:

  1. Thanks for sharing. Did you know that a virtual data room contains strictly confidential data and documents with restrictions and controlled access on viewing, copying or printing? A VDR allows documents to be accessed by regulators and investors in a timely manner during the allowed time period. So check out data room m&a if you don't believe me.

    ReplyDelete