Vim Tips Wiki
Register
(Add subpage to TipProposed to fix link)
No edit summary
 
(6 intermediate revisions by 3 users not shown)
Line 1: Line 1:
  +
{{TipNew
{{TipProposed
 
|id=0
+
|id=1589
|previous=0
+
|previous=1588
|next=0
+
|next=1590
|created=February 16, 2008
+
|created=2008
 
|complexity=basic
 
|complexity=basic
 
|author=Metacosm
 
|author=Metacosm
 
|version=7.0
 
|version=7.0
 
|subpage=/200802
 
|subpage=/200802
  +
|category1=
  +
|category2=
 
}}
 
}}
  +
Vim can read and write environment variables within your current shell session. Use a <code>$</code> prefix to identify an environment variable, as in the following examples.
Use $VAR, as in <code>:let $path = 'c:\foo;c:\bar'</code> and <code>:echo $path</code> and <code>:let baz = $path</code>. Read {{help|expr-env}} (and {{help|expression-syntax}} in general) for more detail.
 
   
  +
Display the contents of the PATH environment variable:
==Comments==
 
  +
<pre>
  +
:echo $PATH
  +
</pre>
   
  +
Assign the PATH environment variable to a Vim variable:
----
 
  +
<pre>
  +
:let myvar = $PATH
  +
</pre>
  +
  +
Change the PATH environment variable for the current session:
  +
<pre>
  +
:let $PATH = '/foo:/bar'
  +
</pre>
  +
  +
Insert the contents of the PATH environment variable into the buffer:<br>
  +
Press <code>i</code> to enter insert mode, press Ctrl-r then <code>=$PATH</code> and press Enter.
  +
  +
Append to the Existing Path.
  +
<pre>
  +
:let $PATH .= ':/foo:/bar'
  +
</pre>
  +
  +
==References==
  +
*{{help|expr-env}}
  +
*{{help|expression-syntax}}
  +
*{{help|i_CTRL-R_=}}
  +
 
==Comments==

Latest revision as of 13:40, 14 July 2013

Tip 1589 Printable Monobook Previous Next

created 2008 · complexity basic · author Metacosm · version 7.0


Vim can read and write environment variables within your current shell session. Use a $ prefix to identify an environment variable, as in the following examples.

Display the contents of the PATH environment variable:

:echo $PATH

Assign the PATH environment variable to a Vim variable:

:let myvar = $PATH

Change the PATH environment variable for the current session:

:let $PATH = '/foo:/bar'

Insert the contents of the PATH environment variable into the buffer:
Press i to enter insert mode, press Ctrl-r then =$PATH and press Enter.

Append to the Existing Path.

:let $PATH .= ':/foo:/bar'

References[]

Comments[]