Question

I am reading book/documentation in Vim written in rst (reStructuredText) format. Book is about PHP, so it is full of code. If I manually set filetype to PHP, code has syntax highlight.

set ft=php

But if place this line in my .vimrc, filetype is reckognized by vim, but there is no code syntax highlighting.

au BufRead,BufNewFile,FileType *.rst set ft=php

Anybody knows how to fix that ?

Thanks

Was it helpful?

Solution

Redirecting all reStructuredText files to show up as PHP looks wrong. Instead of messing with the filetype detection, I would rather explicitly specify the filetype:

:edit +setf\ php phpbook.rst

If there are several files, and this is permanent, I'd configure this path-based:

:autocmd BufRead,BufNewFile /path/to/dir/*.rst setf php

Alternatively, you can use one of the local vimrc plugins; there are several on vim.org; I can recommend the localrc plugin, which even allows local filetype-specific configuration.

Alternative

With my SyntaxRange plugin, you can keep the default reStructuredText syntax, and only mark the PHP snippet sections as PHP:

:12,42SyntaxInclude php

If the sections are delimited by certain patterns, this can even be automated.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top