Using :make in Vim for OCaml

Vim’s OCaml mode supports compiling a project by calling :make and subsequently going trough errors using the quickfix list. My problem is: this only works when calling :make in the project’s top-level directory and when in OCaml mode. Many projects don’t contain an ML file at the top-level – how can I still invoke :make in OCaml mode short of creating a fake ML file? Maybe this problem is specific to my setup - I am using autochdir.

1 Like

I don’t have an answer but a question – I’ve been wanting to use :make but never figured out how to set it up. Does :make run dune for you? What does the config look like?

1 Like

I’m using a top-level Makefile that invokes Jbuilder or Dune. This is just for convenience. https://github.com/lindig/hello. There is no special configuration file. The OCaml mode sets up the error format to recognize error messages which I can jump to using :cn, :cc and so on.

I believe using autochdir in Vim is part of my problem. Without it, invoking :make works if my working directory is at the top level and the current file is an OCaml file.

1 Like

I think your issue is indeed because of autochdir. In the past what i’ve done is to setup vim to look for the root of my project using git, but these days i use something like neomake or ale to get errors while i’m using vim. Another alternative is to use something like https://github.com/airblade/vim-rooter. By default it looks for the project root using git/mercurial etc but it can be configured to look for other files. Maybe looking for .opam files will be a good default for an ocaml project?

1 Like

Links to neomake and ale:

1 Like