Svn diff with vim but with the appropriate file type

This blog post provides an easy way to use Vim with svn diff. Unfortunately, Vim does not understand the left file, so there is no syntax highlighting. What is the easiest / best way to solve this?

+3
source share
6 answers

When I use restructured text in a file with the suffix .txt, by default vim will not highlight the text. So I put this at the top of my file:

.. vim: set filetype=rst :

And then vim makes all the cute syntax highlighting.

Try adding the model to the first line of your files, and then see if vim does what you want when you run diff.

, , ! ?

+3

~/.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

, .svn-base , .

:help new-filetype
:help :doautocmd
:help expand()
+8

"vim set filetype" , , "", .vimrc . , "" , ( ):

:set filetype=XXX

XXX - (, python, c ..)

:help filteype 

0

, vimdiff vimdiff .svn/text-base/foo.php.svn-base foo.php, , vim lhs php - .

. - , :

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

:

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

, :filetype. .php.svn-base php. , 'filetype' 'syntax': :set filetype? :set syntax? .

0

php, , svn filename. , vimdiff svn-base , - :

autocmd! BufRead *.svn-base if &diff && argc() == 2 |
    \     execute 'doautocmd filetypedetect BufRead '.argv(1) |
    \ endif
autocmd! BufNewFile *.svn-base if &diff && argc() == 2 |
    \     execute 'doautocmd filetypedetect BufNewFile '.argv(1) |
    \ endif
0

Using GVim 8.0 as the Diff Viewer for TortoiseSVN 1.9.7 on Windows 10 , I found that GVim correctly recognized the php file extension and displayed fine syntax highlighting.

0
source

Source: https://habr.com/ru/post/1756317/


All Articles