# Running merlin from MacVim

**URL:** <https://discuss.ocaml.org/t/running-merlin-from-macvim/10256>\
**Category:** Ecosystem\
**Tags:** vim, merlin, macos\
**Created:** [August 4, 2022, 2:44pm UTC](https://discuss.ocaml.org/t/running-merlin-from-macvim/10256 "2022-08-04T14:44:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![lindig](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/lindig/32/532_2.png) [@lindig](https://discuss.ocaml.org/u/lindig)\
**Post date:** [August 4, 2022, 2:44pm UTC](https://discuss.ocaml.org/t/running-merlin-from-macvim/10256/1 "2022-08-04T14:44:08Z")

</div>

I’m using MacVim on macOS and it has trouble executing merlin despite being set up as suggested. The same setup works on Linux where I’m using GVim. I suspect that MacVim, which is a macOS application bundle, does not pass the expected environment to merlin. Has anybody experience with this combination? It used to work but I suspect macOS sandboxing became stronger over time. Below are the lines in my `.vimrc` to set up merlin integration.

```auto
let g:opamshare = substitute(system('opam config var share'),'\n$','','''')
execute "set rtp+=" . g:opamshare . "/merlin/vim"
execute "set rtp+=" . g:opamshare . "/ocp-indent/vim"

```

---

<div class="post-metadata">

**Author:** ![beajeanm](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/beajeanm/32/189_2.png) [@beajeanm](https://discuss.ocaml.org/u/beajeanm)\
**Post date:** [August 4, 2022, 3:59pm UTC](https://discuss.ocaml.org/t/running-merlin-from-macvim/10256/2 "2022-08-04T15:59:48Z")

</div>

Do you have an error log?  
My guess the `opam` binary is not in the path of the MacOs applications.  
On my system, opam, installed with homebrew, is in `/opt/homebrew/bin/opam` which is not part of the default `$PATH` (or whatever MacOs app use to find executables…) but it’s added by my fish configuration when I launch a terminal.  
I think on my previous system, homebrew was more than happy to populate something in /usr/local and that was making it more compatible with non-terminal based app.

---

<div class="post-metadata">

**Author:** ![lindig](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/lindig/32/532_2.png) [@lindig](https://discuss.ocaml.org/u/lindig)\
**Post date:** [August 4, 2022, 5:52pm UTC](https://discuss.ocaml.org/t/running-merlin-from-macvim/10256/3 "2022-08-04T17:52:31Z")

</div>

```auto
:e ~/src/fit/bin/main.ml
main.ml main.mli
merlin: unknown flag /Users/lindig/src/fit/bin/main.ml, flag -filename: error, Unix.Unix_error(Unix
.ENOENT, "create_process", "dune")

```

This suggests to me that Merlin is executed but something else goes wrong. You can find on Google other people reporting the problem but it’s murky.

---

<div class="post-metadata">

**Author:** ![beajeanm](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/beajeanm/32/189_2.png) [@beajeanm](https://discuss.ocaml.org/u/beajeanm)\
**Post date:** [August 5, 2022, 12:12pm UTC](https://discuss.ocaml.org/t/running-merlin-from-macvim/10256/4 "2022-08-05T12:12:02Z")

</div>

Doesn’t `Unix.Unix_error(Unix .ENOENT, "create_process", "dune")` means the `create_process` function couldn’t find dune?

So I’m guessing the vim config can find merlin, but merlin expect dune to be in the path, which doesn’t happen unless opam is allowed to dynamically add the current switch `bin` to $PATH.

As a test, if you have admin access, you could add your current switch bin folder to `/etc/paths` and see if that works? (Not a solution of course, but at least it would clarify the issue)

---

<div class="post-metadata">

**Author:** ![lindig](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/lindig/32/532_2.png) [@lindig](https://discuss.ocaml.org/u/lindig)\
**Post date:** [August 5, 2022, 4:55pm UTC](https://discuss.ocaml.org/t/running-merlin-from-macvim/10256/5 "2022-08-05T16:55:10Z")

</div>

Indeed, the `bin/` directory containing `dune` must be mentioned in `/etc/paths` or via `/etc/paths.d`. MacVim does not inherit my shell environment and this creates the problem. To solve the problem within Vim, I’ve added to my `.vimrc`:

```auto
let g:opambin = substitute(system('opam config var bin'),'\n$','','''')
let $PATH .= ":" . g:opambin

```
