Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8138235
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T11:25:42+00:00 2026-06-06T11:25:42+00:00

When Vim is started, it grabs many of the environment variables from the operating

  • 0

When Vim is started, it grabs many of the environment variables from the operating system (like PATH) and it also sets it own environment variables (like MYVIMRC).

How do I list or view all the environment variables that Vim understands, together with their respective values from inside Vim?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T11:25:44+00:00Added an answer on June 6, 2026 at 11:25 am

    In Vimscript, there is not a direct way of getting the list of
    currently defined environment variables. However, it is possible
    to exploit Vim command-line completion feature to make one.

    Consider possible completions for the following unfinished command:

    :echo $
    

    It is not difficult to see that, according to Vimscript syntax,
    the completions must be the names of the environment variables.
    Pressing the wildchar key (Tab, by default) or
    Ctrl+D will display all of them.

    In order to get this list of completions from within a script, we need
    to overcome its interactive nature. A possible trick that I propose
    herein relies on a combination of features. The first of them is the
    Ctrl+A command. In Command-line mode, this
    shortcut triggers insertion of every available completion in front of
    the cursor. The inserted completions are listed in alphabetical order
    and separated with spaces.

    If we could make Vim print those completions out right into the
    command line, we would easily capture them by redirecting command
    output with the :redir command. But all we need to achieve that
    side effect is to quote the text inserted with Ctrl+A:
    Quoting makes the rest of our :echo command a string literal that
    can be just printed out!

    :echo 'NAME1 NAME2 NAME3'
    NAME1 NAME2 NAME3
    

    To edit the command line in this way, the user can type :ec (an
    alias for :echo) followed by $, press
    Ctrl+A, type ', jump to the beginning of the
    line by pressing Ctrl+B, move the cursor over
    the dollar sign by pressing ⇾ (the right arrow key) twice,
    delete that $, and, finally, insert ' instead. The same sequence
    of key presses can easily be reproduced non-interactively using the
    :normal command.

    Putting all these pieces together, we obtain the following function:

    function! Env()
        redir => s
        sil! exe "norm!:ec$\<c-a>'\<c-b>\<right>\<right>\<del>'\<cr>"
        redir END
        return split(s)
    endfunction
    

    For this approach to work, Vim must be compiled with the
    +cmdline_compl feature.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I started to use vim recently, but I miss the character/line selection methods from
I have recently started moving to vim as my main development environment, and I
I come from an Eclipse/Vim background, and I've just started using Emacs for the
I asked this question previously ( any-good-tutorial-for-moving-from-eclipse-to-vim ) From the inputs, I started using
I have just started using Vim in a terminal (PuTTY or MinTTY), after always
I started playing with Haskell and I use Vim. I have autoindent on in
I recently started using NERDTree with vim, and have set it to automatically open
I've just started using the NERDTree vim plugin for my project. I can't find
Greetings. I've been using vim for years, and I've recently started toying with XCode.
I started learning vim today and installed it using sudo apt-get install vim Now,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.