diff runtime/doc/eval.txt @ 16604:1e0a5f09fdf1 v8.1.1305

patch 8.1.1305: there is no easy way to manipulate environment variables commit https://github.com/vim/vim/commit/691ddeefb545d8488e5a495af61caba2e57b3de9 Author: Bram Moolenaar <Bram@vim.org> Date: Thu May 9 14:52:41 2019 +0200 patch 8.1.1305: there is no easy way to manipulate environment variables Problem: There is no easy way to manipulate environment variables. Solution: Add environ(), getenv() and setenv(). (Yasuhiro Matsumoto, closes #2875)
author Bram Moolenaar <Bram@vim.org>
date Thu, 09 May 2019 15:00:07 +0200
parents ff3c99bd1038
children 1eaf34420bb3
line wrap: on
line diff
--- a/runtime/doc/eval.txt
+++ b/runtime/doc/eval.txt
@@ -1369,6 +1369,13 @@ environment variable					*expr-env*
 
 The String value of any environment variable.  When it is not defined, the
 result is an empty string.
+
+The functions `getenv()` and `setenv()` can also be used and work for
+environment variables with non-alphanumeric names.
+The function `environ()` can be used to get a Dict with all environment
+variables.
+
+
 						*expr-env-expand*
 Note that there is a difference between using $VAR directly and using
 expand("$VAR").  Using it directly will only expand environment variables that
@@ -2303,6 +2310,7 @@ did_filetype()			Number	|TRUE| if FileTy
 diff_filler({lnum})		Number	diff filler lines about {lnum}
 diff_hlID({lnum}, {col})	Number	diff highlighting at {lnum}/{col}
 empty({expr})			Number	|TRUE| if {expr} is empty
+environ()			Dict	return environment variables
 escape({string}, {chars})	String	escape {chars} in {string} with '\'
 eval({string})			any	evaluate {string} into its value
 eventhandler()			Number	|TRUE| if inside an event handler
@@ -2360,6 +2368,7 @@ getcompletion({pat}, {type} [, {filtered
 				List	list of cmdline completion matches
 getcurpos()			List	position of the cursor
 getcwd([{winnr} [, {tabnr}]])	String	get the current working directory
+getenv({name})			String	return environment variable
 getfontname([{name}])		String	name of font being used
 getfperm({fname})		String	file permissions of file {fname}
 getfsize({fname})		Number	size in bytes of file {fname}
@@ -2568,6 +2577,7 @@ setbufvar({expr}, {varname}, {val})
 				none	set {varname} in buffer {expr} to {val}
 setcharsearch({dict})		Dict	set character search from {dict}
 setcmdpos({pos})		Number	set cursor position in command-line
+setenv({name}, {val})		none	set environment variable
 setfperm({fname}, {mode})	Number	set {fname} file permissions to {mode}
 setline({lnum}, {line})		Number	set line {lnum} to {line}
 setloclist({nr}, {list} [, {action} [, {what}]])
@@ -3905,6 +3915,14 @@ diff_hlID({lnum}, {col})				*diff_hlID()
 		The highlight ID can be used with |synIDattr()| to obtain
 		syntax information about the highlighting.
 
+environ()						*environ()*
+		Return all of environment variables as dictionary. You can
+		check if an environment variable exists like this: >
+			:echo has_key(environ(), 'HOME')
+<		Note that the variable name may be CamelCase; to ignore case
+		use this: >
+			:echo index(keys(environ()), 'HOME', 0, 1) != -1
+
 empty({expr})						*empty()*
 		Return the Number 1 if {expr} is empty, zero otherwise.
 		- A |List| or |Dictionary| is empty when it does not have any
@@ -4970,13 +4988,11 @@ getcwd([{winnr} [, {tabnr}]])
 			" Get the working directory of current tabpage
 			:echo getcwd(-1, 0)
 <
-getfsize({fname})					*getfsize()*
-		The result is a Number, which is the size in bytes of the
-		given file {fname}.
-		If {fname} is a directory, 0 is returned.
-		If the file {fname} can't be found, -1 is returned.
-		If the size of {fname} is too big to fit in a Number then -2
-		is returned.
+getenv({name})						*getenv()*
+		Return the value of environment variable {name}.
+		When the variable does not exist |v:null| is returned.  That
+		is different from a variable set to an empty string.
+		See also |expr-env|.
 
 getfontname([{name}])					*getfontname()*
 		Without an argument returns the name of the normal font being
@@ -5009,6 +5025,14 @@ getfperm({fname})					*getfperm()*
 
 		For setting permissions use |setfperm()|.
 
+getfsize({fname})					*getfsize()*
+		The result is a Number, which is the size in bytes of the
+		given file {fname}.
+		If {fname} is a directory, 0 is returned.
+		If the file {fname} can't be found, -1 is returned.
+		If the size of {fname} is too big to fit in a Number then -2
+		is returned.
+
 getftime({fname})					*getftime()*
 		The result is a Number, which is the last modification time of
 		the given file {fname}.  The value is measured as seconds
@@ -8012,6 +8036,11 @@ setcmdpos({pos})					*setcmdpos()*
 		Returns 0 when successful, 1 when not editing the command
 		line.
 
+setenv({name}, {val})						*setenv()*
+		Set environment variable {name} to {val}.
+		When {val} is |v:null| the environment variable is deleted.
+		See also |expr-env|.
+
 setfperm({fname}, {mode})				*setfperm()* *chmod*
 		Set the file permissions for {fname} to {mode}.
 		{mode} must be a string with 9 characters.  It is of the form