vim-easyenv is a lightweight Vim/Neovim plugin for easily managing environment variables for your projects using a simple JSON configuration file. It automatically detects the root of your project based on common manifest files (like package.json, pyproject.toml, pom.xml, and more) and allows you to define environment variables for your project in a dedicated .easyenv.json file. These variables can then be loaded and unset with simple Vim commands, making it easier to keep project-specific environment variables isolated and under version control.
- Automatic Project Root Detection: Locates your project root by scanning for standard manifest files from a wide variety of ecosystems (Node.js, Python, Rust, Java, .NET, C/C++, Go, Docker, Kubernetes, and more).
- Simple Environment File: Use
.easyenv.jsonin your project root to define environment variables under anenvironmentkey. - Easy Commands:
:EasyEnvCreate— Creates a new.easyenv.jsonfile in your project root.:EasyEnvLoad— Loads and exports environment variables from.easyenv.jsoninto your Vim session.
- Automatic Unset: Previously loaded environment variables are automatically unset before new ones are loaded, ensuring a clean environment.
-
Install the Plugin
Use your favorite Vim plugin manager.Using vim-plug:
Plug 'josstei/vim-easyenv'Using packer.nvim (Lua)
use 'josstei/vim-easyenv'
After installation, restart Vim/Neovim and run :PlugInstall, :PackerSync, or the appropriate command for your plugin manager.
-
Initialize in Your Project
In your project root, run in Vim::EasyEnvCreateThis creates a
.easyenv.jsonfile with a default structure. -
Edit
.easyenv.json
Define your environment variables under theenvironmentkey. Example:{ "environment": { "API_URL": "https://dev.local/api", "DEBUG": "1" } } -
Load Environment Variables
:EasyEnvLoadYour environment variables will be available in your Vim session as
$API_URL,$DEBUG, etc.
vim-easyenv detects the project root using (but not limited to) files such as:
package.json,pyproject.toml,Cargo.toml,pom.xml,build.gradle,Makefile,go.mod,Dockerfile,Chart.yaml,next.config.js, etc.
This supports a wide variety of ecosystems including JavaScript, Python, Rust, Java, .NET, Go, Docker, Kubernetes, and major frontend frameworks.
- Clone your project and open it in Vim.
- Use
:EasyEnvCreateto generate the config file if it doesn't exist. - Edit
.easyenv.jsonand add your environment variables. - Use
:EasyEnvLoadto load them into your session. - Variables are automatically unset before loading new ones.
MIT License. See LICENSE for details.
Note: This plugin is under active development. Features and usage may change.