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 2


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
  • 1
    And you could map :set syntax=prolog to something (maybe <Leader>-p).
    – bsmith89
    Feb 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.

See “Modelines” in the user manual and :help modeline.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.