Add readline features in OCaml toplevel

Posted on In QA

It is painful for a Linux user to use the OCaml toplevel without the readline features.

Is there a method to enable/add these kinds of features in readline to the OCaml toplevel?

I find 2 options that work very well for me:

utop provides a beautiful interface and supports completion, colors, parenthesis matching, etc. It can be installed by OPAM: opam install utop.

Another simple way I found is to use the rlwrap for line editing support: https://www.systutorials.com/docs/linux/man/1-rlwrap/

To start the OCaml toplevel with rlwrap, run:

$ rlwrap ocaml

Or wrap it in a shell script:

#!/bin/sh
exec rlwrap /usr/bin/ocaml "$@"

Leave a Reply

Your email address will not be published. Required fields are marked *