sponsor Vim development Vim logo Vim Book Ad

dotenv.vim : Basic support for .env and Procfile

 script karma  Rating 2/2, Downloaded by 1141  Comments, bugs, improvements  Vim wiki

created by
Tim Pope
 
script type
utility
 
description
## Interactive Usage

Use `:Dotenv {file}` or `:Dotenv {dir}` to load a `.env` file and set the corresponding environment variables in Vim.  Use `:verbose Dotenv` to see what variables are actually being set.

## Projections

With projectionist.vim (vimscript #4989) and dispatch.vim (vimscript #4504) installed, you'll get a default `:Start` of `foreman start` for projects with a `Procfile`, and a default `:Dispatch` of `foreman check` for the `Procfile` itself.

## Dispatch

If you call `:Dispatch foreman run whatever` or `:Dispatch dotenv whatever`, the compiler will be correctly selected for the `whatever` command.

## API

While the above are all marginally helpful, this is the use case that inspired the plugin.  Other plugins can call `DotenvGet('VAR')` to get the value of `$VAR` globally or from the current buffer's `.env`.  Here's a wrapper to optionally use `DotenvGet()` if it's available.

    function! s:env(var) abort
      return exists('*DotenvGet') ? DotenvGet(a:var) : eval('$'.a:var)
    endfunction

    let db_url = s:env('DATABASE_URL')

There's also `DotenvExpand()`, a drop-in replacement for `expand()`.

    function! s:expand(expr) abort
      return exists('*DotenvExpand') ? DotenvExpand(a:expr) : expand(a:expr)
    endfunction
 
install details
Extract in ~/.vim (~\vimfiles on Windows).
 

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
dotenv.zip 1.0 2015-05-17 7.0 Tim Pope Initial upload
ip used for rating: 44.220.184.63

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
   
Vim at Github