0

I recently started looking into Vim/NeoVim as a lightweight fast IDE. I followed some tutorials and managed to set it up with nvim-tree, treesitter, telescope etc. (all the basic stuff) My Project opens fine with it, and I can use all the plugins I installed. It color codes my code files.

However when I execute :GoRun it prints { } (blank) environment variables from my .env file.

I wrote a small golang server that works fine when I execute it from vscode command line or just the terminal. I can use postman to make get and post requests and it returns valid json.

I am using the viper library to read the .env file.

I have searched through forums, asked chatgpt but I have not been able to find a solution to my problem. I changed paths from relative to absolute for the .env file, I copied the .env file to my project root directory. I tried using :source and :ch command in neovim but nothing seems to work.

=====================================================================

Here is the error it throws, remember this code works through command line but not through neovim

:!'go' 'run' '/home/user/Projects/project1/cmd/main.go'  2>&1| tee /tmp/nvim.user1/rI2p6E/7

[GIN-debug] [WARNING] Creating an Engine instance with the Logger and Recovery middleware already attached.

[GIN-debug] [WARNING] Running in "debug" mode. Switch to "release" mode in production.

  • using env: export GIN_MODE=release
  • using code: gin.SetMode(gin.ReleaseMode)

2023/04/16 16:41:25 sql: unknown driver "" (forgotten import?) exit status 1

I need help.

Rohit Gupta
  • 4,022
  • 20
  • 31
  • 41
  • Is your working directory the same from the CLI and within vim? You should not be using filename arguments with `go run`, which implies different package and module parameters than if you are building a package as a whole within a module. – JimB Apr 17 '23 at 13:41
  • Thanks for responding, that helped, "working directory" was the keyword in your answer. I did some search and came across this https://stackoverflow.com/questions/3847796/change-working-directory-to-currently-opened-file In my ~/.config/nvim/.vimrc file I added this setting ":set autochdir" saved it. Then I reopened vim at the root of my project and executed :pwd to see if it picked up my project directory as the root. I then updated the path to the .env file with the right number of directory changes "../.." and it worked like a charm. – user2192534 Apr 17 '23 at 18:02
  • Just wanted to say ... Thank You for pointing me in the right direction. – user2192534 Apr 17 '23 at 18:06

0 Answers0