vim-go use environment file for :GoRun

217 views Asked by At

When I use an IDE like Goland I'm able to set an environment file for the process when I run the program. I've done the following to get a similar result. I added the following to the init.vim.

" Function to source only if file exists {
function! SourceIfExists(file)
  if filereadable(expand(a:file))
    exe 'source' a:file
  endif
endfunction

:command! GoRunEnv :call SourceIfExists(".env") | GoRun
:cabbrev GoRun GoRunEnv
:command! GoTestEnv :call SourceIfExists(".env") | GoTest
:cabbrev GoTest GoTestEnv

Every time I run :GoRun or :GoTest, all variables defined in the file .env will be added to the process. The .env file has to look like the following:

let $HUHU = "What ever"

Is there a way to include a normal environment file like this?

HUHU=What ever

Maybe I'm completely on the wrong way an there is a better approach?

0

There are 0 answers