8

I'd like gVim to open files dragged into it to open in a new tab, instead of replacing the current file. This question is on the right track, but I'd like to be able to run multiple instances of gVim, just able to drag files to the window I want.

I'm running on Windows 7.

Community
  • 1
  • 1
wes
  • 7,795
  • 6
  • 31
  • 41

8 Answers8

4

You can start by typing :tabe and then drag and drop your file. I can't fully confirm this (I only have a mac) but I think this will end up with :tabe filename displayed. You can then hit enter and off you go...

Peter
  • 127,331
  • 53
  • 180
  • 211
  • That works, but I'd rather not have to "prepare" the editor to get a new file. Is there a way to make that the default action for a 'drop'? – wes Dec 11 '09 at 23:33
  • This isn't actually any better than preparing by just opening a new tab (`:tabnew`), then dropping the file into the new tab. – James Haigh Mar 01 '14 at 00:09
4

No you cannot, the default action on drag and drop is specified in the implementation of a windows application (OLE DoDragDrop). It has not been implemented to open dropped files in a new tab and thus won't. But gVim is open source... so you could submit a patch if you really want this :)

Pierre-Antoine LaFayette
  • 24,222
  • 8
  • 54
  • 58
3

You could add the following in your .vimrc

autocmd BufReadPost * tab ball

This will open tabs for all buffers, including the newly dropped file. Notice it does so for all buffers, so also the ones already opened in gvim.

Vincent Traag
  • 660
  • 4
  • 6
3
  1. Holding CTRL while dragging the file to Vim will open the new file in a new window split in Vim.
  2. Then simply convert that split to a new tab with <C-W>T as I found here.
Community
  • 1
  • 1
2

You can put the following option to vimrc. VIM will open the file with new tab. You can also drag and drop to gVim, it will open in new tab. It works for me, I'm also using on Windows 7.

:au BufAdd,BufNewFile * nested tab sball

Calm Hill
  • 21
  • 1
  • 1
    More info [here](http://vim.wikia.com/wiki/Open_every_buffer_in_its_own_tabpage) unfortunately it messes up other things. If I load a saved sessions for example, it loads the files twice. Or if a buffer is loaded but not currently in a tab, after dragging a new file, that buffer also gets a tab. –  Nov 13 '12 at 14:35
  • It solves the question asked, but it also changes :vs behavior from split screen to a new tab. – Jonathan Koren Aug 18 '19 at 20:07
2

Opening a new file in gvim doesn't replace the one that's currently open. The new file is opened in a new buffer and that buffer is show. You can switch between buffers using the :b command. In your case, you can simply drop the file, then create a new tab with :tabedit, and switch that tabs buffer to the one you want with :b <filename>. Of course that's not exactly what you're searching for, but it's sufficient for me.

bluebrother
  • 8,636
  • 1
  • 20
  • 21
1

These Windows friendly mappings can make this problem more bearable. Still have to remember to press Ctrl-T before dragging the file though...

" CTRL-T opens a new tab, CTRL-W closes tab, CTRL-Left/Right switches tabs
noremap   <C-T> :tabnew<return>
noremap   <C-W> :tabclose<return>
noremap   <C-Left> :tabprevious<return>
noremap   <C-Right> :tabNext<return>
0

Since files cannot be drag and dropped to gvim correctly, I use a batch file to accomplish this. The dragged files can be dropped to the batch file or a shortcut to it. It may also be used in the send to menu of windows explorer.

Here is the content of the batch file (change the path and the name of the gvim server):

@ECHO OFF
:TOP
IF (%1) == () GOTO END
    I:\apps\vim\vim73\gvim.exe --servername GVIM --remote-tab "%1"
SHIFT
GOTO TOP

:END
ECHO End
Jon Lin
  • 142,182
  • 29
  • 220
  • 220
alex
  • 9
  • 1