I have the following configuration for OCaml development which works fine:
" --------------- OCaml -----------------------------
" Merlin
let g:opamshare = substitute(system('opam config var share'),'\n$','','''')
execute 'set rtp+=' . g:opamshare . '/merlin/vim'
" ocp-indent
execute 'set rtp^=' . g:opamshare . '/ocp-indent/vim'
" enable deoplete
let g:deoplete#enable_at_startup = 1
Given that I use differents languages, I want to just use this configuration with OCaml files so I tried to create a function and to call it if the FileType is ocaml:
augroup OCaml_Environment
autocmd!
autocmd FileType ocaml :call OCamlEnvSetup()
augroup END
function! OCamlEnvSetup()
let g:opamshare = substitute(system('opam config var share'),'\n$','','''')
execute 'set rtp+=' . g:opamshare . '/merlin/vim'
" ocp-indent
execute 'set rtp^=' . g:opamshare . '/ocp-indent/vim'
" enable deoplete
let g:deoplete#enable_at_startup = 1
endfunction
But now I can not access to commands defined in merlin/vim for example. What am I doing wrong?
Edit
Based on the answers I modified my function:
augroup OCaml_Environment
autocmd!
autocmd FileType ocaml :call OCamlEnvSetup()
augroup END
function! OCamlEnvSetup()
let g:opamshare = substitute(system('opam config var share'),'\n$','','''')
execute 'set rtp+=' . g:opamshare . '/merlin/vim'
execute 'runtime ' . g:opamshare . '/merlin/vim'
" ocp-indent
execute 'set rtp^=' . g:opamshare . '/ocp-indent/vim'
execute 'runtime ' . g:opamshare . '/ocp-indent/vim'
endfunction
let g:deoplete#enable_at_startup = 1
With this I have the following error:
[deoplete] Merlin not found, make sure ocamlmerlin is in your path and merlin's vim plugin is installed.
After that I tried to use a filetype-plugin too, creating the file ~/.config/nvim/ftplugin/ocaml.vim with the following content:
let g:opamshare = substitute(system('opam config var share'),'\n$','','''')
execute 'set rtp+=' . g:opamshare . '/merlin/vim'
execute 'runtime ' . g:opamshare . '/merlin/vim/plugin/**/*.vim'
" ocp-indent
execute 'set rtp^=' . g:opamshare . '/ocp-indent/vim'
execute 'runtime ' . g:opamshare . '/ocp-indent/vim/plugin/**/*.vim'
But now it looks like the configuration is not loaded, because for example, I can not use the :MerlinTypeOf
that is available with merlin.vim.
runtime <filename>
after changing the rtp to get it to work~/.config/nvim/ftplugin/ocaml.vim
with the initial configuration but it does not work. I also used the initial configuration addingruntime g:opamshare . '/merlin/vim'
but it doesn't help neither.