Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question
add comment

2 Answers

Try:

:tab drop filename

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

share|improve this answer
    
This can only delete a specific duplicate one,I want vim to deny load another tab of the same file automatically... –  new_perl Jul 15 '11 at 4:32
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.