Merlin is the tool used for code completion, type querying, locating definitions etc for OCaml. Regardless of which editor you use, you’ll want to install Merlin for your ocaml compiler with
opam install merlin.
Visual Studio Code
This is the easiest editor to set up for OCaml. Just install the OCaml and Reason IDE extension:
code --install-extension freebroccolo.reasonml
Vim or Neovim
Vim and Neovim are relatively complex tools, and their configuration requires editing their
.vimrc file (in the case of Neovim, it’s
.config/nvim/init.vim on Linux).
In order to just have basic Merlin support, all you need is to add this snippet to enable Merlin’s VIM plugin:
if executable('opam') let g:opamshare=substitute(system('opam config var share'),'\n$','','''') if isdirectory(g:opamshare."/merlin/vim") execute "set rtp+=" . g:opamshare."/merlin/vim" endif endif
This approach has the advantage of loading the same plugin version as is available in Merlin via OPAM, preventing any mismatches.
:help merlin to find out the keybindings.
A completion engine, like
Ale, is recommended as well.
Install tooling libraries and the user-setup assitant with
opam install user-setup merlin tuareg ocamlformat ocp-indent
Then run the user-setup installation
opam user-setup install