Autocompletion in utop
Asked Answered
L

1

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?

Lewis answered 23/2, 2015 at 10:23 Comment(0)
S
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.

Switzerland answered 23/2, 2015 at 10:29 Comment(9)
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?Lewis
(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)Lewis
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.Switzerland
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).Lewis
I added your useful feedback to my post. Thanks!Switzerland
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.Laurynlausanne
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 bindingsExtraordinary
For Ubuntu: Alt + left - right to navigate and Alt + down to select. Tab if there is only one suggestion.Gens
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 preferencesPaisano

© 2022 - 2024 — McMap. All rights reserved.