25

I've been trying out OCaml. Sometimes its quicker just to test out some code using the interpreter shell but, it doesn't bring up the last command when I press the 'up' key.

Its a pain when I miss type something or wish to see what a little variation would produce.

Anyone know if there is another key for it?

Thanks,

neildaemond
  • 656
  • 1
  • 8
  • 17

3 Answers3

35

Use rlwrap:

rlwrap ocaml

ocaml itself has no readline support.

You can configure readline using ~/.inputrc. For example, you could add such lines to it:

$if ocaml
"\C-o": "()\C-b"
"\C-n": ";;\n"
$endif

Now you can use ctrl-o and ctrl-n hotkeys in ocaml. Just try it.

Igor Chubin
  • 61,765
  • 13
  • 122
  • 144
  • 3
    There is also `ledit`, which works like rlwrap: `ledit ocaml`. Install with `sudo apt-get install ledit` if you're using Debian or Ubuntu. – jrouquie Aug 01 '12 at 10:43
  • cool, ledit was already installed on my ubuntu machine. rlwrap was just as easliy installed with `sudo apt-get install rlwrap` too... is there any benefit in one over the other? – neildaemond Aug 01 '12 at 11:41
  • 3
    @neildaemond: I found `rlwrap` better. rlwrap gives you history, filename completion, prompt coloring, syntax completion, brackets matching, use of an external editor and easy configuration via .inputrc. – Igor Chubin Aug 01 '12 at 11:50
  • 1
    Thanks for adding more to your answer, rlwrap it is~ I just added `alias ocaml='rlwrap ocaml'` into my .bashrc :) – neildaemond Aug 01 '12 at 12:20
5

You can use the improved toplevel utop. Moreover, it includes nice completion capacities.

Pierre Chambart
  • 1,469
  • 12
  • 17
0

I used ctrl + arrow up for previous input