8

I am sorry for the newb question, but I am just starting with OCaml and I could not find how to ues utop autocompletion.

When I start typing something in utop, I see a list of choices at the bottom of the shell. If there is only one valid choice, pressing TAB will autocomplete what I am writing. But if there are multiple valid choices, and I spot the one I want, I have not found a way to select it (other than keep writing).

For instance (assuming I have imported Core.Std) I type

Float.of

The first suggestion is Float.of_float, the second one is Float.of_int. How do I select the second one?

Andrea
  • 20,253
  • 23
  • 114
  • 183

1 Answers1

13

To quote utop's README:

utop display a bar after the prompt which is used to show possible completions in real-time. You can navigate in it using M-left and M-right, and select one completion using M-tab. The M denotes the meta key, which is Alt most of the time.

So, you can navigate through completions using Alt.

Have fun with utop!

EDIT:

It seems Alt doesn't always work, depending on the terminal. Typing Esc then the good keys, however, works.

Also, the bindings can be easily rebinded through a ~/.lambda-term-inputrc file, see here.

PatJ
  • 5,996
  • 1
  • 31
  • 37
  • 1
    Actually, I had already tried all combinations of modifiers + arrow keys, but they do not work for me. In particular Alt+left and Alt+right do nothing on my system, while Win+left and Win+right are bound to window resizing (I am using Ubuntu 14.04 with Gnome shell). Any ways to rebind the keys? – Andrea Feb 23 '15 at 10:36
  • 5
    (and by the way, using Alt+Tab to actually choose the completion is going to fail on every system I have tried - this is consistently used to switch between open windows) – Andrea Feb 23 '15 at 10:38
  • 1
    Have you tried `Esc` then `arrow` or `Esc` then `tab`? `Esc` is often bound to put a `Meta` on the next key pressed, so that may solve it. – PatJ Feb 23 '15 at 10:45
  • 1
    Right, Esc works! Still, I really would appreciate to be able to rebind keys in utop, as it is quite uncomfortable, especially given that I have to press Esc one time for each movement (that is, it does not behave as a modifier). – Andrea Feb 23 '15 at 10:56
  • 1
    I added your useful feedback to my post. Thanks! – PatJ Feb 23 '15 at 12:01
  • 1
    For macOS users: in Terminal.app, M-left/M-right are bound to escape sequences and won't work with utop. To unbind them, while running Terminal, go to Preferences (Command-,) -> Profiles -> Keyboard, select each one and click "-". It's good to make a new profile before doing this, in case you want to revert later. While you're on this page, select "Use Option as Meta key" too. After doing this, start a new Terminal with this profile, run utop, and now M-left/M-right will select different completions on the completion bar. – Matt Curtis Jan 05 '18 at 04:50
  • Btw, you can run `lambda-term-actions` command in your terminal to see the list of possible actions. You can also run `#utop_bindings;;` inside `utop` to see the current bindings – smac89 Sep 08 '18 at 08:22
  • For Ubuntu: `Alt` + left - right to navigate and `Alt + down` to select. `Tab` if there is only one suggestion. – Quan VO Nov 23 '18 at 11:07
  • fyi on macos, with iterm2, I have to press CMD + ALT (the apple key and left alt) with "Left option key" mapped to Esc+ in profiles -> keys in iterm's preferences – nicolas Jan 03 '22 at 16:02