The attached patch adds two options which together allow dropped files
to always be loaded as tabs instead of in the current window or a
split window. Files loaded via the Windows shell extension ("Edit
with existing Vim...") should also be affected, since the shell
extension sends a WM_DROPFILES message to the exisiting Vim window.
This seems like something that should be possible with AutoCmds or
something, but my Googlings [1] didn't come up with anything except
other people wanting this type of behaviour [2].
It would be nice if this patch could find its way into 7.3, but I
realise it is a bit late.
[1] http://www.google.com/search?q=vim+open+dropped+file+new+tab
[2]
http://stackoverflow.com/questions/1891513/can-i-force-gvim-to-open-dragged-in-files-in-a-new-tab
--
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 7d1044b27eb5 -r 510c8e757def runtime/doc/gui.txt
--- a/runtime/doc/gui.txt Mon Aug 02 23:06:46 2010 +0200
+++ b/runtime/doc/gui.txt Tue Aug 03 17:29:18 2010 +0100
@@ -395,8 +395,10 @@
be opened as if a |:drop| command was used.
If you hold down Shift while doing this, Vim changes to the first dropped
-file's directory. If you hold Ctrl Vim will always split a new window for the
-file. Otherwise it's only done if the current buffer has been changed.
+file's directory. If you hold Ctrl, or if the |'dropsplit'| option is set,
+Vim will always split a new window for the file. Otherwise it's only done if
+the current buffer has been changed. If the |'dropnewtab'| option is set Vim
+will open a new tab instead of a new window.
You can also drop a directory on Vim. This starts the explorer plugin for
that directory (assuming it was enabled, otherwise you'll get an error
diff -r 7d1044b27eb5 -r 510c8e757def runtime/doc/gui_w16.txt
--- a/runtime/doc/gui_w16.txt Mon Aug 02 23:06:46 2010 +0200
+++ b/runtime/doc/gui_w16.txt Tue Aug 03 17:29:18 2010 +0100
@@ -164,9 +164,10 @@
*win16-drag-n-drop*
You can drag and drop one or more files into the vim window, where they will
be opened as normal. If you hold down Shift while doing this, Vim changes to
-the (first) dropped file's directory. If you hold Ctrl, Vim will always split
-a new window for the file. Otherwise it's only done if the current buffer has
-been changed.
+the (first) dropped file's directory. If you hold Ctrl, or if the
+|'dropsplit'| option is set, Vim will always split a new window for the file.
+Otherwise it's only done if the current buffer has been changed. If the
+|'dropnewtab'| option is set Vim will open a new tab instead of a new window.
You can also drop a directory's icon, but rather than open all files in the
directory (which wouldn't usually be what you want) Vim instead changes to
that directory and begins a new file.
diff -r 7d1044b27eb5 -r 510c8e757def runtime/doc/options.txt
--- a/runtime/doc/options.txt Mon Aug 02 23:06:46 2010 +0200
+++ b/runtime/doc/options.txt Tue Aug 03 17:29:18 2010 +0100
@@ -2437,6 +2437,27 @@
uhex Show unprintable characters hexadecimal as <xx>
instead of using ^C and ~C.
+ *'dropnewtab'*
+'dropnewtab' boolean (default off)
+ global
+ {not in Vi}
+ {not available when compiled without the +windows
+ feature}
+ When a dropped file would have opened in a new window, makes it open
+ in a new tab instead. See |drag-n-drop| for more information.
+
+ *'dropsplit'*
+'dropsplit' boolean (default off)
+ global
+ {not in Vi}
+ {not available when compiled without the +windows
+ feature}
+ When a file is dropped, makes it always open in a new window (or tab),
+ unless the Ctrl key is held down when the file is dropped.
+ See |drag-n-drop| for more information.
+ This option also affects files opened through the Windows shell
+ extension ("Edit with existing Vim...").
+
*'eadirection'* *'ead'*
'eadirection' 'ead' string (default "both")
global
diff -r 7d1044b27eb5 -r 510c8e757def runtime/doc/tags
--- a/runtime/doc/tags Mon Aug 02 23:06:46 2010 +0200
+++ b/runtime/doc/tags Tue Aug 03 17:29:18 2010 +0100
@@ -186,6 +186,8 @@
'dir' options.txt /*'dir'*
'directory' options.txt /*'directory'*
'display' options.txt /*'display'*
+'dropnewtab' options.txt /*'dropnewtab'*
+'dropsplit' options.txt /*'dropsplit'*
'dy' options.txt /*'dy'*
'ea' options.txt /*'ea'*
'ead' options.txt /*'ead'*
diff -r 7d1044b27eb5 -r 510c8e757def runtime/optwin.vim
--- a/runtime/optwin.vim Mon Aug 02 23:06:46 2010 +0200
+++ b/runtime/optwin.vim Tue Aug 03 17:29:18 2010 +0100
@@ -441,6 +441,10 @@
call append("$", "statusline\talternate format to be used for a status line")
call <SID>OptionG("stl", &stl)
endif
+call append("$", "dropnewtab\ta dropped file is opened in a new tab instead of a window")
+call <SID>BinOptionG("dropnewtab", &dropnewtab)
+call append("$", "dropsplit\ta dropped file is always opened in a new window (or tab)")
+call <SID>BinOptionG("dropsplit", &dropsplit)
call append("$", "equalalways\tmake all windows the same size when adding/removing windows")
call <SID>BinOptionG("ea", &ea)
if has("vertsplit")
diff -r 7d1044b27eb5 -r 510c8e757def src/ex_docmd.c
--- a/src/ex_docmd.c Mon Aug 02 23:06:46 2010 +0200
+++ b/src/ex_docmd.c Tue Aug 03 17:29:18 2010 +0100
@@ -6882,6 +6882,16 @@
if (updating_screen)
return;
+#ifdef FEAT_WINDOWS
+ /* If 'dropsplit' is set then invert split. This means than if
+ * the option is set dropped files will open in a split window by
+ * default, and holding CTRL will open dropped files in the same
+ * window.
+ */
+ if (p_dropsplit)
+ split = !split;
+#endif
+
/* Check whether the current buffer is changed. If so, we will need
* to split the current window or data could be lost.
* We don't need to check if the 'hidden' option is set, as in this
@@ -6896,6 +6906,10 @@
if (split)
{
# ifdef FEAT_WINDOWS
+ /* Force opening in a new tab if 'dropnewtab' is set. */
+ if (cmdmod.tab == 0 && p_dropnewtab)
+ cmdmod.tab = tabpage_index(curtab) + 1;
+
if (win_split(0, 0) == FAIL)
return;
# ifdef FEAT_SCROLLBIND
diff -r 7d1044b27eb5 -r 510c8e757def src/option.c
--- a/src/option.c Mon Aug 02 23:06:46 2010 +0200
+++ b/src/option.c Tue Aug 03 17:29:18 2010 +0100
@@ -1013,6 +1013,20 @@
{"display", "dy", P_STRING|P_VI_DEF|P_COMMA|P_RALL|P_NODUP,
(char_u *)&p_dy, PV_NONE,
{(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
+ {"dropnewtab", NULL, P_BOOL|P_VI_DEF,
+#ifdef FEAT_WINDOWS
+ (char_u *)&p_dropnewtab, PV_NONE,
+#else
+ (char_u *)NULL, PV_NONE,
+#endif
+ {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
+ {"dropsplit", NULL, P_BOOL|P_VI_DEF,
+#ifdef FEAT_WINDOWS
+ (char_u *)&p_dropsplit, PV_NONE,
+#else
+ (char_u *)NULL, PV_NONE,
+#endif
+ {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
{"eadirection", "ead", P_STRING|P_VI_DEF,
#ifdef FEAT_VERTSPLIT
(char_u *)&p_ead, PV_NONE,
diff -r 7d1044b27eb5 -r 510c8e757def src/option.h
--- a/src/option.h Mon Aug 02 23:06:46 2010 +0200
+++ b/src/option.h Tue Aug 03 17:29:18 2010 +0100
@@ -426,6 +426,10 @@
#endif
#define DY_LASTLINE 0x001
#define DY_UHEX 0x002
+#ifdef FEAT_WINDOWS
+EXTERN int p_dropnewtab; /* 'dropnewtab' */
+EXTERN int p_dropsplit; /* 'dropsplit' */
+#endif
EXTERN int p_ed; /* 'edcompatible' */
#ifdef FEAT_VERTSPLIT
EXTERN char_u *p_ead; /* 'eadirection' */