3

I don't know whether it's a feature or bug,but it's really annoying me.

When a specific file is already opened(tabnew) ,I just want to switch to that tab.

Is there a workaround?

2 Answers 2

3

Try:

:tab drop filename

Source: Edit a file or jump to it if already open

1
  • This can only delete a specific duplicate one,I want vim to deny load another tab of the same file automatically...
    – new_perl
    Commented Jul 15, 2011 at 4:32
2

The only way I know to accomplish this with tabs is to write a function to search for a file open within another tab and if so switch to the tab otherwise do a tab new command. Then instead of calling tabnew you would call your function. These kind of solutions always feel hackish to me though.

I believe the main thing here is that vim's tabs aren't the same as other editors' tabs. They are not meant to manage this one to one relationship of one file one tab. Tabs in vim are more of, for the lack of a better word, "viewports". Allowing you to have different sets of windows viewing the various open buffers you have.

If you really want the idea of one tab per file you might try not using the 'tab' feature of vim and look into simply editing the files in the original fashion with :edit and using the buffers commands such as :bn :bp :ls :bfirst :blast. In addition the plugin MiniBufExplorer will give you a tabbed representation for the buffers. From my experience this model tends to better represent what users are expecting from multi file editing.

If you still want to use the tabs let me know and I can probably whip up a short example function that will do something close to what you want.

If you give the buffers method a try I recommend binding either C-n/C-p or C-/C- to the :bn/:bp commands since they are used so often.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .