Vim Tips Wiki
Register
(rewrite to use :drop)
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
  +
{{TipNew
{{TipProposed
 
|id=0
+
|id=1600
|previous=0
+
|previous=1599
|next=0
+
|next=1601
|created=August 8, 2008
+
|created=2008
 
|complexity=basic
 
|complexity=basic
 
|author=Fritzophrenic
 
|author=Fritzophrenic
Line 15: Line 15:
 
It turns out, Vim ''does'' have this functionality, but it is hard to find.
 
It turns out, Vim ''does'' have this functionality, but it is hard to find.
   
The <tt>:drop</tt> command will edit a new file, or jump to the window containing it if it already exists. Using <tt>:tab</tt> with it (i.e. <tt>:tab drop {file}</tt>) will open the file in a new tab if it isn't already open.
+
The <code>:drop</code> command will edit a new file, or jump to the window containing it if it already exists. Using <code>:tab</code> with it (i.e. <code>:tab drop {file}</code>) will open the file in a new tab if it isn't already open.
   
Dragging and dropping a file into gvim automatically invokes the <tt>:drop</tt> command.
+
Dragging and dropping a file into gvim automatically invokes the <code>:drop</code> command. If you hold down the CTRL key while doing this, it will force a window to split (there isn't a way to force a tab, but CTRL-W T right afterwards will do that for you easily). If you hold down SHIFT, it will set Vim's working directory to that of the file.
   
 
==References==
 
==References==
 
*{{help|:drop}}
 
*{{help|:drop}}
  +
*{{help|drag-n-drop}}
   
 
==Comments==
 
==Comments==
  +
  +
You can use <code>:command! -nargs=1 -complete=file O tab drop <args></code> to open the file or jump to it using <code>:O FILENAME</code>.

Revision as of 11:14, 25 September 2013

Tip 1600 Printable Monobook Previous Next

created 2008 · complexity basic · author Fritzophrenic · version 7.0


When using most tabbed editors, if you open a file for editing, and the file is already open in another tab, the editor will simply jump to that tab. There are very good reasons that Vim does not act this way, which are too numerous to go into detail about here – suffice it to say that there are many excellent features in Vim that would not be possible if it acted like "most tabbed editors". Nevertheless, it would be nice if Vim had this functionality when the user wishes to use it.

It turns out, Vim does have this functionality, but it is hard to find.

The :drop command will edit a new file, or jump to the window containing it if it already exists. Using :tab with it (i.e. :tab drop {file}) will open the file in a new tab if it isn't already open.

Dragging and dropping a file into gvim automatically invokes the :drop command. If you hold down the CTRL key while doing this, it will force a window to split (there isn't a way to force a tab, but CTRL-W T right afterwards will do that for you easily). If you hold down SHIFT, it will set Vim's working directory to that of the file.

References

Comments

You can use :command! -nargs=1 -complete=file O tab drop <args> to open the file or jump to it using :O FILENAME.