Hello Vim developers,
I think that the initial value of v:register directly after Vim startup is
inconsistent. Observe:
vim -N -u NONE -c 'nmap ,x :echo string(v:register)<CR>' -c 'normal ,x'
''
vim -N -u NONE -c 'nmap ,x :echo string(v:register)<CR>' -c 'normal ,x,x'
'"'
vim -N -u NONE -c 'nmap ,x :echo string(v:register)<CR>' -c 'normal "a,x'
'a'
The first mapping receives an empty v:register if none was specified, all
subsequent mapping invocations will receive the default (unnamed) register.
Looking this up in the help, I misread "Empty if none were supplied." to mean
"if none were supplied to the last normal mode command", whereas in fact this
means "if no normal mode command was submitted yet to Vim."
I think it would be more consistent to default to the unnamed register from the
very start, and eliminate the possibility of an empty v:register, so that
v:register always contains the effective register for the current mapping. The
following patch implements this and tries to improve on the help text.
-- regards, ingo
diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt
--- a/runtime/doc/eval.txt
+++ b/runtime/doc/eval.txt
@@ -1542,8 +1542,9 @@
Read-only.
*v:register* *register-variable*
-v:register The name of the register supplied to the last normal mode
- command. Empty if none were supplied. |getreg()| |setreg()|
+v:register The name of the register in effect for the current normal mode
+ command (regardless of whether that command actually uses a
+ register). |getreg()| |setreg()|
*v:scrollstart* *scrollstart-variable*
v:scrollstart String describing the script or function that caused the
diff --git a/src/eval.c b/src/eval.c
--- a/src/eval.c
+++ b/src/eval.c
@@ -873,6 +873,7 @@
hash_add(&compat_hashtab, p->vv_di.di_key);
}
set_vim_var_nr(VV_SEARCHFORWARD, 1L);
+ set_reg_var(0);
#ifdef EBCDIC
/*
diff --git a/src/main.c b/src/main.c
--- a/src/main.c
+++ b/src/main.c
@@ -898,6 +898,16 @@
#ifdef FEAT_AUTOCMD
apply_autocmds(EVENT_VIMENTER, NULL, NULL, FALSE, curbuf);
TIME_MSG("VimEnter autocommands");
+#endif
+
+#if defined(FEAT_EVAL) && defined(FEAT_CLIPBOARD)
+ /* Adjust default register name for "unnamed" in 'clipboard'. Can only be
+ * done after the clipboard is available and all initial commands that may
+ * modify the 'clipboard' setting have run; i.e. just before entering the
+ * main loop. */
+ int default_regname = 0;
+ adjust_clip_reg(&default_regname);
+ set_reg_var(default_regname);
#endif
#if defined(FEAT_DIFF) && defined(FEAT_SCROLLBIND)
--
-- Ingo Karkat -- /^-- /^-- /^-- /^-- /^-- /^-- http://ingo-karkat.de/ --
-- http://vim.sourceforge.net/account/profile.php?user_id=9713 --
--
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