UTOP(1)
β¨ UTOP(1) β the Universal toplevel for OCaml, bestie edition β¨
okay so you opened the UTOP(1) page from the General Commands Manual and honestly? you ate by being here. let's get into it π
πΈ NAME πΈ
utop β Universal toplevel for OCaml. that's it, that's the girlboss π
π¦ SYNOPSIS π¦
utop [ options ] [ object-files ] [ script-file ]
π DESCRIPTION π
utop is an enhanced toplevel for OCaml and it has so many features, not the least of which is context sensitive completion. it's giving main character energy fr fr.
When you start utop, what you see is the prompt followed by a bar containing words. That's the completion bar: it holds the possible completions and it updates as you type β¨. The highlighted word in the completion bar is the selected word. You can navigate using the keys M-Left and M-Right, and select one completion using M-down. Here M is the meta key, which is Alt on most systems (iykyk). You can configure these bindings in the file ~/.config/lambda-term-inputrc β see lambda-term-inputrc(5) for the deets.
utop supports completion on:
- directives and directive arguments
- identifiers
- record fields
- variants
- function labels
- object methods
Colors are by default configured for terminals with dark colors, like white on black, so the prompt may look too bright on light-colored terminals π no cap. You can change that by setting the color profile of utop. To do that, type:
UTop.set_profile UTop.Light;;
You can then add this line to your ~/.config/utop/init.ml file.
To turn off utop's advanced prompt features, add the following to init.ml to turn off respectively (a) colors and the upper information line, and (b) the lower boxed list of possible completions:
#utop_prompt_dummy;;
UTop.set_show_box false
You can enable basic syntax highlighting in utop by writing a ~/.utoprc file. See utoprc(5) for that π.
Vi edit mode is enabled by the command:
#edit_mode_vi
It currently supports three vi modes: normal, insert, visual mode, and you can get/set content with vim-like registers. iconic honestly.
utop.el is a package that provides utop integration with Emacs π. The package allows you to run utop inside Emacs and to evaluate code in it straight from your source buffers (with the help of utop-minor-mode). The recommended way to install utop.el is via Emacs's built-in package manager package.el. More detailed installation and configuration instructions may be found on the project's code repository at https://github.com/ocaml-community/utop.
You can start utop inside Emacs with M-x utop.
The default install also has a minor mode with the following key bindings:
C-c C-s Start a utop buffer (utop)
C-x C-e Evaluate the current phrase (utop-eval-phrase)
C-x C-r Evaluate the selected region (utop-eval-region)
C-c C-b Evaluate the current buffer (utop-eval-buffer)
C-c C-k Kill a running utop process (top-kill)
C-c C-z Switch to utop process (utop-switch-to-repl)
then you can run utop by pressing M-x and typing "utop". utop supports completion in Emacs mode β just press Tab to complete a word π«Ά. You can also integrate it with the tuareg, caml or typerex mode. For that, add the following lines to your ~/.emacs file:
(autoload 'utop-minor-mode "utop" "Minor mode for utop" t)
(add-hook 'tuareg-mode-hook 'utop-minor-mode)
π OPTIONS π
See utop --help for the full list of available options. There is considerable overlap with options available for ocaml(1).
A commonly used option is -require package to load package into the execution environment. It is equivalent to using #require from inside utop(1).
-absnameβ Show absolute filenames in error message.-Idir β Add dir to the list of include directories.-initfile β Load file instead of the default init file.-labelsβ Use commuting label mode.-no-app-functβ Deactivate applicative functors.-noassertβ Do not compile assertion checks.-nolabelsβ Ignore non-optional labels in types.-nostdlibβ Do not add the default directory to the list of include directories.-ppxcommand β Pipe abstract syntax trees through the preprocessor command.-principalβ Check principality of type inference.-safe-stringβ Make strings immutable.-short-pathsβ Shorten paths in types (the default).-no-short-pathsβ Do not shorten paths in types.-rectypesβ Allow arbitrary recursive types.-stdinβ Read script from standard input.-strict-sequenceβ Left-hand part of a sequence must have typeunit.-unsafeβ Do not compile bounds checking on array and string access.-versionβ Print version and exit.-vnumβ Print version number and exit.-wlist β Enable or disable warnings according to list.-warn-errorlist β Enable or disable error status for warnings according to list. See option-wfor the syntax of list. Default setting is-a+31.-warn-helpβ Show description of warning numbers.-emacsβ Run in emacs mode.-hide-reservedβ Hide identifiers starting with a'_'(the default).-show-reservedβ Show identifiers starting with a'_'.-no-implicit-bindingsβ Don't add implicit bindings for expressions (the default).-implicit-bindingsβ Add implicit bindings:expr;; -> let _0 = expr;;-no-autoloadβ Disable autoloading of files in$OCAML_TOPLEVEL_PATH/autoload.-requirepackage β Load this package.-dparsetreeβ Dump OCaml AST after rewriting.-dsourceβ Dump OCaml source after rewriting.-helpβ Display this list of options.--helpβ Display this list of options.
π FILES π
~/.config/utop/init.mlβ The initialization file of the toplevel.~/.ocamlinitβ The alternative initialization file of the toplevel.~/.utoprcβ The configuration file forutop. Seeutoprc(5).~/.config/lambda-term-inputrcβ The file containing key bindings. Seelambda-term-inputrc(5).
π AUTHOR π
JΓ©rΓ©mie Dimino <jeremie@dimino.org> β king behavior, we love to see it π
β SEE ALSO β
utoprc(5), lambda-term-inputrc(5), ocaml(1).
and that's the whole page bestie, you're officially a utop girlie now ππ¦β¨
sending you off with love from the UTOP(1) manual page, part of the General Commands Manual β mwah, go slay some OCaml π πΈ
π¦ where this page comes from
- debian trixie: utop 2.15.0-1+b9 Β· BSD-3-Clause
- fedora 43: utop 2.16.0-1.fc43 Β· BSD-3-Clause
- fedora 44: utop 2.16.0-5.fc44 Β· BSD-3-Clause
- fedora 44: utop 2.17.0-2.fc44 Β· BSD-3-Clause
- nixos 26.05: ocaml5.4.1-utop 2.17.0
- nixpkgs unstable: ocaml5.5.1-utop 2.17.0
- ubuntu questing: utop 2.16.0-1build1
- ubuntu resolute: utop 2.16.0-1build6 Β· BSD-3-Clause
- ubuntu stonking: utop 2.17.0-1build2 Β· BSD-3-Clause
- (c) 2011, Jeremie Dimino <jeremie@dimino.org>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms