aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/nvim/eval.c12
-rw-r--r--src/nvim/testdir/test_unlet.vim24
2 files changed, 36 insertions, 0 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index 41a9eeeb40..2aab2d72a7 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -2818,6 +2818,18 @@ static void ex_unletlock(exarg_T *eap, char_u *argstart, int deep)
lval_T lv;
do {
+ if (*arg == '$') {
+ const char *name = (char *)++arg;
+
+ if (get_env_len((const char_u **)&arg) == 0) {
+ EMSG2(_(e_invarg2), name - 1);
+ return;
+ }
+ os_unsetenv(name);
+ arg = skipwhite(arg);
+ continue;
+ }
+
// Parse the name and find the end.
char_u *const name_end = (char_u *)get_lval(arg, NULL, &lv, true,
eap->skip || error,
diff --git a/src/nvim/testdir/test_unlet.vim b/src/nvim/testdir/test_unlet.vim
index 3f06058d03..dbddffb492 100644
--- a/src/nvim/testdir/test_unlet.vim
+++ b/src/nvim/testdir/test_unlet.vim
@@ -28,3 +28,27 @@ endfunc
func Test_unlet_fails()
call assert_fails('unlet v:["count"]', 'E46:')
endfunc
+
+func Test_unlet_env()
+ let envcmd = has('win32') ? 'set' : 'env'
+
+ let $FOOBAR = 'test'
+ let found = 0
+ for kv in split(system(envcmd), "\r*\n")
+ if kv == 'FOOBAR=test'
+ let found = 1
+ endif
+ endfor
+ call assert_equal(1, found)
+
+ unlet $FOOBAR
+ let found = 0
+ for kv in split(system(envcmd), "\r*\n")
+ if kv == 'FOOBAR=test'
+ let found = 1
+ endif
+ endfor
+ call assert_equal(0, found)
+
+ unlet $MUST_NOT_BE_AN_ERROR
+endfunc