Ideal OCaml setups with VIM, Emacs, IntelliJ/IDEA?

I am new to OCaml and trying to setup a productive OCaml environment.

I am familiar with VIM (first editor), Emacs (when I saw how well C-x C-e REPLs worked), IntelliJ/IDEA (when I saw Java/Kotlin auto completion “just worked”).

My current IDE of choice is IntelliJ/IDEA. I have installed, but I don’t think I’m using it right.

Can someone provide links for:

  • ideal VIM/OCaml setup
  • ideal Emacs/OCaml setup
  • ideal IntelliJ/OCaml setup
    ? (I want to study all 3 and pick one.)

The main features that matter to me are:

  • easy access to the OCaml REPL
  • “it just works” reference resolution – I should be able to put cursor over a Struct / Field / Function, hit some hot key, and jump to (1) where it is defined and (2) list of where it is used
  • hot key to show all Structs (which starts “narrowing” to completion candidates as I type), and jumps to Struct definition when I hit ENTER
  • easy way to run unit tests
  • auto jump to correct line on compile errors

Not sure if it’s ideal and but here are a few steps to get you started with emacs.

Since merlin supports LSP protocol, completions, jump-to-definitions and other such stuff should just work in the majority of editors. REPL integration could be a little bit trickier, tho. There should be a mode for editor supporting utop.

There is reasonml plugins for both Idea and VS Code, which provide a good support out-of-the box. However, neither supports repl yet AFAIK. Emacs have a good utop and merlin integration, if you want to give it a try, both Doom-emacs and spacemacs have a preconfigured OCaml support.

Merlin / utop is breaking assumptions I made regarding how OCaml works.

A slightly different question: what are popular work flows that proficient OCaml programmers use? (Links to tutorials / setups / screencasts would be great).

Here is my Vim setup. I program not only OCaml though, but some config parts can be useful. I am far from being proficient though, more like an average, closer to the beginner one.

Also note the recent update of OCaml and Dune support in the mainline Vim. So Vim patch level above 8.1.1630 is recommended. It also should become a part of NeoVim 0.4 release in a month.

A small update: the OCaml and Dune runtime files landed in NeoVim as well, so you can already try them if you use it from git:

1 Like

I agree with one of commenters above: as of now the most value in any editor (while working with OCaml code :slight_smile: ) you get from merlin.

My personal Emacs setup is pretty straightforward and simple: tuareg-mode + merlin. But now I’m moving my projects to dune with aim to integrate my workflow with its utop feature.

@zeroexcuses I published a video this week to explain how to import an ocaml project with latest plugin version. You can find it here:
I hope you can find it useful.
It’ll give you completion/documentation out of the box for ocaml stdlib. And it works on any OS (hint: Windows)
Idea plugin is more focused on ReasonML because that’s my main usage now, but I’m slowly integrating more OCaml related functionalities. But far from “ideal” :slight_smile:

1 Like