Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use variable from external file in Neovim init.vim

Tags:

lua

neovim

I'm using Kubuntu 22.04, and Neovim 0.8 from the Konsole command-line.

I'm using vim-dadbod and vim-dadbod-ui plugins for MySQL database connection.

I don't want to have to type the password every time I open the connection, but I can't just use it directly in the mysql url (mysql://<username>:<password>@<host>:<port>/<db_name>) in the init.vim file, because this file WILL BE SHARED with other people.

Therefore, I want to store the user & password in a separate file, and call it with a variable inside my init.vim.

I've tried to create a ~/.config/nvim/lua/myVars.lua file and use require('myVars') in my init.vim file, but didn't work...

So, how can I import the variables from the lua file, and use it within init.vim?

like image 203
Borjovsky Avatar asked Sep 14 '26 13:09

Borjovsky


1 Answers

You could - instead of a required Lua config file - opt for an environment variable which you could then access from Lua using os.getenv.

like image 143
LMD Avatar answered Sep 17 '26 13:09

LMD