Hello,
I want yank and paste commands to use the system clipboard by default.
Vim has an option for this: clipboard=unnamed which makes yank and
paste work with the register '*' instead of the unnamed register. This
works great on Windows where '*' is the clipboard. However, on X11 the
clipboard is the '+' register, and so I find myself having to type "+y
and "+p instead of the shorter y and p when I want to use the
clipboard.
Attached is a patch which adds a new flag "unnamedplus" to the
'clipboard' option, which behaves exactly like the "unnamed" flag,
except that it uses the '+' register. Please, consider it for
inclusion in Vim. Thanks.
--
Ivan Krasilnikov
--
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
diff -r b2789846ed39 runtime/doc/options.txt
--- a/runtime/doc/options.txt Wed Nov 24 18:48:12 2010 +0100
+++ b/runtime/doc/options.txt Sun Nov 28 11:40:52 2010 +0300
@@ -1434,6 +1434,13 @@
explicitly accessed using the "* notation. Also see
|gui-clipboard|.
+ unnamedplus A variant of "unnamed" flag which uses the clipboard
+ register '+' (|quoteplus|) instead of register '*' for
+ all operations except yank. Yank shall copy the text
+ into both registers.
+ Only available with the |+x11| feature.
+ Availability can be checked via has("unnamedplus").
+
autoselect Works like the 'a' flag in 'guioptions': If present,
then whenever Visual mode is started, or the Visual
area extended, Vim tries to become the owner of the
diff -r b2789846ed39 src/eval.c
--- a/src/eval.c Wed Nov 24 18:48:12 2010 +0100
+++ b/src/eval.c Sun Nov 28 11:40:52 2010 +0300
@@ -12135,6 +12135,9 @@
#ifdef FEAT_TOOLBAR
"toolbar",
#endif
+#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
+ "unnamedplus",
+#endif
#ifdef FEAT_USR_CMDS
"user-commands", /* was accidentally included in 5.4 */
"user_commands",
diff -r b2789846ed39 src/globals.h
--- a/src/globals.h Wed Nov 24 18:48:12 2010 +0100
+++ b/src/globals.h Sun Nov 28 11:40:52 2010 +0300
@@ -512,7 +512,11 @@
# define clip_plus clip_star /* there is only one clipboard */
# define ONE_CLIPBOARD
# endif
-EXTERN int clip_unnamed INIT(= FALSE);
+/*
+ * clip_unnamed=1 if 'clipboard' has "unnamed", 2 if it has "unnamedplus",
+ * 0 if it has none of the above.
+ */
+EXTERN int clip_unnamed INIT(= 0);
EXTERN int clip_autoselect INIT(= FALSE);
EXTERN int clip_autoselectml INIT(= FALSE);
EXTERN int clip_html INIT(= FALSE);
diff -r b2789846ed39 src/ops.c
--- a/src/ops.c Wed Nov 24 18:48:12 2010 +0100
+++ b/src/ops.c Sun Nov 28 11:40:52 2010 +0300
@@ -1584,9 +1584,12 @@
adjust_clip_reg(rp)
int *rp;
{
- /* If no reg. specified, and "unnamed" is in 'clipboard', use '*' reg. */
- if (*rp == 0 && clip_unnamed)
- *rp = '*';
+ /*
+ * If no reg. specified, and "unnamed" or "unnamedplus" is in 'clipboard',
+ * use '*' or '+' reg, respectively.
+ */
+ if (*rp == 0 && clip_unnamed != 0)
+ *rp = clip_unnamed == 1 ? '*' : '+';
if (!clip_star.available && *rp == '*')
*rp = 0;
if (!clip_plus.available && *rp == '+')
@@ -3115,7 +3118,7 @@
*/
if (clip_star.available
&& (curr == &(y_regs[STAR_REGISTER])
- || (!deleting && oap->regname == 0 && clip_unnamed)))
+ || (!deleting && oap->regname == 0 && clip_unnamed == 1)))
{
if (curr != &(y_regs[STAR_REGISTER]))
/* Copy the text from register 0 to the clipboard register. */
@@ -3130,8 +3133,14 @@
* If we were yanking to the '+' register, send result to selection.
* Also copy to the '*' register, in case auto-select is off.
*/
- else if (clip_plus.available && curr == &(y_regs[PLUS_REGISTER]))
+ else if (clip_plus.available
+ && (curr == &(y_regs[PLUS_REGISTER])
+ || (!deleting && oap->regname == 0 && clip_unnamed == 2)))
{
+ if (curr != &(y_regs[PLUS_REGISTER]))
+ /* Copy the text from register 0 to the + register. */
+ copy_yank_reg(&(y_regs[PLUS_REGISTER]));
+
/* No need to copy to * register upon 'unnamed' now - see below */
clip_own_selection(&clip_plus);
clip_gen_set_selection(&clip_plus);
diff -r b2789846ed39 src/option.c
--- a/src/option.c Wed Nov 24 18:48:12 2010 +0100
+++ b/src/option.c Sun Nov 28 11:40:52 2010 +0300
@@ -7304,7 +7304,7 @@
static char_u *
check_clipboard_option()
{
- int new_unnamed = FALSE;
+ int new_unnamed = 0;
int new_autoselect = FALSE;
int new_autoselectml = FALSE;
int new_html = FALSE;
@@ -7316,9 +7316,16 @@
{
if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
{
- new_unnamed = TRUE;
+ new_unnamed = 1;
p += 7;
}
+#ifdef FEAT_X11
+ else if (STRNCMP(p, "unnamedplus", 11) == 0 && (p[11] == ',' || p[11] == NUL))
+ {
+ new_unnamed = 2;
+ p += 11;
+ }
+#endif
else if (STRNCMP(p, "autoselect", 10) == 0
&& (p[10] == ',' || p[10] == NUL))
{