14

I am starting with Prolog programming using XSB.

What syntax highlighting script or plugin for vim editor would you suggest for (XSB) Prolog ?

Mateusz Piotrowski
  • 8,029
  • 10
  • 53
  • 79
Sourabh Daptardar
  • 259
  • 1
  • 3
  • 7
  • 2
    What are you missing from the built-in Prolog support? – glts Oct 26 '13 at 19:21
  • 1
    @glts, I realize now that vim has built-in syntax highlighting for prolog, which by default works on extension .pdb. I can enable it using set syntax=prolog, however it looks pretty primitive. For example, variables and constants are in the same color. – Sourabh Daptardar Oct 26 '13 at 19:44
  • Yes, the Prolog support is quite basic. A quick search of http://www.vim.org/scripts/ produced nothing; it's possible that there are no good Prolog plugins available. (Please be aware that questions asking for tool recommendations are generally considered off-topic on Stackoverflow.) – glts Oct 26 '13 at 20:07
  • One man's awesome syntax/scheme is another man's color hell. ;) You could (1) make sure that `vim` is selecting the `prolog.vim` file (check `:set syntax`) and you can select a color scheme to your liking. The `prolog.vim` syntax file indicates to `vim` what keywords, operators, etc, are. Between that and he color scheme, you have your `vim` style. – lurker Oct 26 '13 at 23:46

3 Answers3

20

Vim (7.3) comes with filetype-specific settings and syntax highlighting for Prolog. Just make sure that your file is detected as such (i.e. :setlocal filetype? prints prolog), and you have the usual :filetype plugin on and :syntax on in your ~/.vimrc.

Vim auto-detects *.pdb and *.pl (depending on contents, can also be Perl); but you can configure additional patterns, see :help new-filetype.

Ingo Karkat
  • 167,457
  • 16
  • 250
  • 324
  • 14
    Yes, vim 7.3 has a decent (not awesome) syntax highlighter. My `vim` autodetects `*.pl` as Perl *unless* it starts with a Prolog comment line `% ...`, then it will interpret as Prolog. It seems to default to Prolog for `.pro` files. – lurker Oct 26 '13 at 20:26
  • I am looking for awesome syntax highlighter script for vim 7.3 :) – Sourabh Daptardar Oct 26 '13 at 20:54
  • 1
    @SourabhDaptardar haha I'm content with the vim 7.3 syntax highlighter. I just have to remember to put a `%...` comment at the top of a `*.pl` file, or it thinks it's a Perl file and it is definitely opposite of awesome. Maybe if I have time I'll tweak the syntax highlighter file (it's in the `/usr/share/vim` folder somewhere) and nudge it closer to awesome. :) – lurker Oct 26 '13 at 23:00
  • Hi @mbratch how do I get the comments syntax colors for the prolog files (*.pl) to work?, it just changing the color of the first word. – Balz Feb 27 '14 at 10:19
  • 1
    @Balz make sure the first line of your prolog file starts with a prolog comment line `% blah blah...` otherwise `vim` may think it's a Perl program. – lurker Feb 27 '14 at 10:52
  • My Vim detects *.pdb as prolog and *.pl as perl. Thanks for the information! – Scott Greenup Sep 17 '16 at 08:40
4

The Vim support for Logtalk is an alternative for syntax coloring of Prolog files. Given that Logtalk extends Prolog, you will get nice syntax coloring for official and de facto standard Prolog features. The latest version is available here:

https://github.com/LogtalkDotOrg/logtalk3/tree/master/coding/vim

You will need to configure Vim, however, to use the Logtalk syntax highlighter support for the Prolog files (basically to recognize the file extensions that you're using for Prolog; e.g. XSB, by default, prefers .P). Also do try different Vim themes. Some of them are more pleasant than others.

Paulo Moura
  • 18,373
  • 3
  • 23
  • 33
2

There are two big plugins "set" for working with Prolog in Vim:

You can check files of the second - they are extending standard prolog.vim which comes with Vim, but including it. Moreover they support different flavours of Prolog - SWI Prolog, GNU Prolog, etc. You can use them as an examble and create your own.

Anton Kochkov
  • 1,117
  • 1
  • 9
  • 25