tags:

views:

187

answers:

4

http://blog.tplus1.com/index.php/2007/08/29/how-to-use-vimdiff-as-the-subversion-diff-tool/ gives a simple way to use vim for svn diff. Unfortunately, vim doesn't understand the left-hand-side filetype so, there's no syntax highlighting. What's the simplest/best way of solving this?

A: 

a quick search for "vim set filetype" gave me this link, which shows you how to make this work "forever" by changing .vimrc a bit. If you're just stuck with a file for once, and you know its "correct" filetype, you can try (from the left hand side file):

:set filetype=XXX

where XXX is the appropriate format (e.g. python, c, etc)

a look at

:help filteype 

might also help a bit

Yoni H
I'm afraid not. The filetype of the left-hand-side file will <rhs-filename.svn-base>, i.e. it is dependent on the right-hand-side filename.
I see what you mean, but I suggested you "force vim's hand" into understanding the left hand side is a different filetype.I did this:echo "import time" > 1.pyecho "import time" > 2.cppnow on left handside typing :set filetype shows:filetype=pythonon rhs it shows:filetype=cppbut I can force the rhs by using::set filetype=pythonhope that helps.
Yoni H
A: 

it's as if vimdiff was invoked with the following command vimdiff .svn/text-base/foo.php.svn-base foo.php so you see, vim fails to recognize the filetype of the lhs file as php because of the different extension.

No proper solution is known to me. I use something like this in different scenario, but that only fixes the syntax highlighting:

au BufReadPost *.php.svn-base       set syntax=php

You can also try that:

au FileType *.php.svn-base          set filetype=php

but I can't test that as I have :filetype disabled. That should overwrite file type detection for the .php.svn-base files and map it to the desired php. I have checked that it overrides the 'filetype' and 'syntax': :set filetype? and :set syntax? produce expected output.

Dummy00001
A: 

When I use restructured text within a file with the .txt suffix, by default, vim won't highlight the text. So I put this at the top of my file:

.. vim: set filetype=rst :

And then vim does all the cute syntax highlighting.

Try adding a modeline to the first line of your files and then see if vim does what you want when you do a diff.

Incidentally, that's my blog you linked to! Can I get a prize?

W. Matthew Wilson
This works too, thanks Matthew.The solution given by "too much php" works of course, but I think this is a good practice and is independent of the file extension.
+1  A: 

Add the following code to ~/.vim/filetype.vim:

" only load filetypes once
if exists("did_load_filetypes")
  finish
endif

augroup filetypedetect

" when BufRead or BufNewFile event is triggered, pop off the .svn-base extension and
" manually restart filetype autocommands
autocmd! BufRead    *.svn-base execute 'doautocmd filetypedetect BufRead ' . expand('%:r')
autocmd! BufNewFile *.svn-base execute 'doautocmd filetypedetect BufNewFile ' . expand('%:r')

augroup END

As the comments state, this code will pick up .svn-base files and try to figure out what the filetype would be without that extension on the end.

:help new-filetype
:help :doautocmd
:help expand()
too much php
Works! Thank you.