Hello Vim developers,
The current discussion about v:register and "unnamedplus" reminded me of
a patch I had sent some time ago. It used to be in the todo list, but
apparently isn't any more. (Maybe it was accidentally removed when Bram
accepted another related same-day patch from me.)
To recap, I'd like to improve the help text for v:register and correct
the edge case of v:register value immediately after startup. Old message
and revised help text suggestion below.
-- regards, ingo
-------- Original Message --------
Subject: PATCH: Startup value for v:register
Date: Sun, 16 Jan 2011 22:50:09 +0100
From: Ingo Karkat <[email protected]>
Reply-To: [email protected]
To: Vim Developers <[email protected]>
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,11 @@
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 (cp. 'clipboard') for the
+ last normal mode command (regardless of whether that command
+ actually used a register) or currently executing normal mode
+ mapping. (Use this in custom commands that take 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
--
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