I'm editing Prolog files as part of an exploratory project, and some of the files I'm working with have the extension .pl
, which is shared by Perl files. Whenever I do work on a Prolog file named [somefile].pl
, Vim gives me syntax highlighting and error detection for Perl, rather than Prolog. I could totally disable syntax highlighting for Perl or force .pl
to be recognized as Prolog, but I'd like to know if there's a less dictatorial way of fixing the issue. Is there a way I can set the syntax highlighting programmatically, or use some sort of a key combination to tell Vim that I'm editing a Prolog file rather than a Perl file?
2 Answers
I can only answer the second part of your question. You can tell Vim that you're editing a Prolog file with this command:
:set syntax=prolog
If you never work in Perl, then it wouldn't seem "dictatorial" to add custom configuration in your ~/.vimrc
:
autocmd BufNewFile,BufRead *.pl setfiletype prolog syntax=prolog
-
1And you could map
:set syntax=prolog
to something (maybe<Leader>-p
).– bsmith89Feb 4, 2015 at 15:38
You could add the following to the top or the bottom of the file.
%vim: ft=prolog
This will tell Vim to treat the file as a Prolog file.