aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--runtime/doc/news.txt4
-rw-r--r--src/nvim/main.c13
2 files changed, 16 insertions, 1 deletions
diff --git a/runtime/doc/news.txt b/runtime/doc/news.txt
index 708e127136..2d4017e3c4 100644
--- a/runtime/doc/news.txt
+++ b/runtime/doc/news.txt
@@ -87,7 +87,9 @@ DEFAULTS
EDITOR
-• TODO
+* On Windows, filename arguments on the command-line prefixed with "~\" or
+ "~/" are now expanded to the user's profile directory, not a relative path
+ to a literal "~" directory.
EVENTS
diff --git a/src/nvim/main.c b/src/nvim/main.c
index 30b6b6e86b..17a0bbf082 100644
--- a/src/nvim/main.c
+++ b/src/nvim/main.c
@@ -1444,6 +1444,19 @@ scripterror:
ga_grow(&global_alist.al_ga, 1);
char *p = xstrdup(argv[0]);
+ // On Windows expand "~\" or "~/" prefix in file names to profile directory.
+#ifdef MSWIN
+ if (*p == '~' && (p[1] == '\\' || p[1] == '/')) {
+ char *profile_dir = vim_getenv("HOME");
+ size_t size = strlen(profile_dir) + strlen(p);
+ char *tilde_expanded = xmalloc(size);
+ snprintf(tilde_expanded, size, "%s%s", profile_dir, p + 1);
+ xfree(p);
+ xfree(profile_dir);
+ p = tilde_expanded;
+ }
+#endif
+
if (parmp->diff_mode && os_isdir(p) && GARGCOUNT > 0
&& !os_isdir(alist_name(&GARGLIST[0]))) {
char *r = concat_fnames(p, path_tail(alist_name(&GARGLIST[0])), true);