Hello,

I posted issue #3072 on the GitHub issue tracker:

https://github.com/vim/vim/issues/3072

I created a patch to fix the issue, although I'm not sure if it will work on all systems (specifically Windows). I also created a test for it in test_expand.vim.

diff --git a/src/ex_docmd.c b/src/ex_docmd.c
index 4d5036f22..0602b82ef 100644
--- a/src/ex_docmd.c
+++ b/src/ex_docmd.c
@@ -10612,6 +10612,26 @@ find_cmdline_var(char_u *src, int *usedlen)
     return -1;
 }

+/*
+ * Issue #3072
+ * When eval_vars() is used on a string of '%:p' and the current
+ * filename is exactly '~', the filename is expanded to the home
+ * directory instead of the full path to the file. This replaces
+ * the '~' name with './~' so the path expansion works correctly.
+ */
+static void fix_tilde_filename(char_u *src, int usedlen, char_u **result, char_u **resultbuf)
+{
+    if ((*result)[0] == '~'
+    && (*result)[1] == NUL
+    && src[usedlen] == ':'
+    && src[usedlen + 1] == 'p')
+    {
+    *result = vim_strnsave(*result, 4);
+    *resultbuf = *result; /* remember allocated string */
+    vim_strncpy(*result, (char_u *)"./~", 4);
+    }
+}
+
 /*
  * Evaluate cmdline variables.
  *
@@ -10715,7 +10735,10 @@ eval_vars(
             valid = 0;        /* Must have ":p:h" to be valid */
         }
         else
+        {
             result = curbuf->b_fname;
+            fix_tilde_filename(src, *usedlen, &result, &resultbuf);
+        }
         break;

     case SPEC_HASH:        /* '#' or "#99": alternate file */
@@ -10779,7 +10802,10 @@ eval_vars(
             valid = 0;        /* Must have ":p:h" to be valid */
             }
             else
+            {
             result = buf->b_fname;
+            fix_tilde_filename(src, *usedlen, &result, &resultbuf);
+            }
         }
         break;

diff --git a/src/testdir/test_expand.vim b/src/testdir/test_expand.vim
index c099edae1..0161f7cb3 100644
--- a/src/testdir/test_expand.vim
+++ b/src/testdir/test_expand.vim
@@ -39,3 +39,9 @@ func Test_with_tilde()
   call delete('Xdir ~ dir', 'd')
   call assert_false(isdirectory('Xdir ~ dir'))
 endfunc
+
+" Issue #3072
+func Test_expand_tilde_filename()
+  e ~
+  call assert_notequal(expand('%:p'), expand('~/'))
+endfunc


Hopefully this is helpful, and let me know if I've made any mistakes in submitting this patch.

Thank you,
Aidan Shafran

--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- You received this message because you are subscribed to the Google Groups "vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Raspunde prin e-mail lui