Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3231584
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:03:45+00:00 2026-05-17T17:03:45+00:00

I work in Vim with lots of open buffers in various windows on various

  • 0

I work in Vim with lots of open buffers in various windows on various tabs. I know it’s simple to just load one of the existing buffers into my current window. However, some of my buffers for large files use folding expressions that cause delay of several seconds when loading them into new window. On the other hand, if they are already open in window on a tab page I just need to hop to that tab page and that window.

I gather there’s no command to do this directly. Or is there?

To find window with desired buffer I could write a function that does this:

  1. for each tab
  2. for each window on each tab
  3. check each window to see if it has my desired buffer loaded
  4. move cursor to found window OR open buffer in window on new tab if not found

Has someone already written this? Or am I missing simpler way of getting what I want?

UPDATE: The ‘switchbuf’ answers were exactly what I was looking for, but I still may end up using a custom function because (1) I was not understanding the behavior of ‘newtab’ option, since windows were still being split, and (2) my function accommodates searches for unloaded files:

function! Sbuf(filename)
    let myvar = ''
    tabdo let myvar = bufwinnr(a:filename) > 0 ? tabpagenr() 
                    \    . ' ' . bufwinnr(a:filename) : myvar
    if myvar > ''
        silent execute split(myvar)[0] . "tabn"
        silent execute split(myvar)[1] . "wincmd w"
    else
        execute 'tab drop ' . a:filename
    endif
endfunction
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T17:03:45+00:00Added an answer on May 17, 2026 at 5:03 pm

    Just set the switchbuf option:

    :set switchbuf=useopen,usetab
    :sbuf [filename]
    

    If you don’t want the switchbuf option turned on all the time then you will need to write a function which changes and then resets the switchbuf option.

    function MySwitchBuf(filename)
      " remember current value of switchbuf
      let l:old_switchbuf = &switchbuf
      try
        " change switchbuf so other windows and tabs are used
        set switchbuf=useopen,usetab
        execute 'sbuf' a:filename
      finally
        " restore old value of switchbuf
        let &switchbuf = l:old_switchbuf
      endtry
    endfunction
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have Vim 7.2 installed on Windows. In GVim, the <C-PageUp> and <C-PageDown> work
I want Vim 's completion menu to work more like the one in Visual
Here's how global bookmarks work. Let's say I have two tabs in my vim
When I work with VIM, I always have multiple windows visible. Sometimes I would
I've just added vim to my current Cygwin installation, and it doesn't work properly.
Huge files take forever to load and work with in vim, due to syntax-highlighting.
I've been trying to get colourschemes to work properly in VIM when using it
Short version : echo testing | vim - | grep good This doesn't work
I currently work with both Visual Studio, Eclipse/Rad, and Vim heavily. Visual Studio and
I'm starting to use Linux and Vim at work. I'm started reading vims documentation

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.