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 6659145
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:59:51+00:00 2026-05-26T01:59:51+00:00

When I switch buffers in Vim (using :bn and :bp), I want it to

  • 0

When I switch buffers in Vim (using :bn and :bp), I want it to automatically set the working directory, BUT not to be the directory of the opened file. I want Vim to search recursively upwards for a file called “tags”, and when it finds that file, set the working directory to the directory with the “tags” file.

Example:

:e ~/programming/projects/foobar/src/js/scripts.js

As you can see, “foobar” is kind of the “project root”. Let’s assume the “tags” file is in the foobar directory. Now Vim should look in “js”, but there’s no tags file. Then it should look in “src”, no tags file there. Then it should look in “foobar” and find the “tags” file, then do:

:cd ~/programming/projects/foobar/

Is there a simple way to do this? 🙂

  • 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-26T01:59:51+00:00Added an answer on May 26, 2026 at 1:59 am

    If your whole point is to get to the correct “tags”-file then this could be done easier:

    set tags=./tags,tags;$HOME/programming,$HOME/programming/your/global/tags
    

    The tags option accepts a comma (or space) delimited list of entries. In my example I have the following entries:

    • ./tags this means it should look first for a tags-file in the current directory
    • tags;$HOME/programming this means look for a tags-file from the current directory up to $HOME/programming (that’s what the semicolon does, see file-searching). If you don’t specify the “stop”-directory using the semicolon then it searches up to the root directory /
    • $HOME/programming/your/global/tags lastly this is a tags file referred to by absolute file name

    My example is probably overkill for your purpose from your description you only need this:

    set tags=tags;$HOME/programming
    

    But if you really need to change the working directory then you could add something like this (change lcd to cd if you have to) to your .vimrc:

    au BufNewFile,BufRead *.js execute ":lcd " . fnamemodify(findfile("tags", ".;"), ":p:h")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I can switch between windows with C-x o, but if I have opened multiple
I want to be able to open Vim and automatically make some commands in
When I'm working in vim, I usually have multiple buffers on screen at once
I use buffer-menu extensively to switch between buffers. I want to list the buffers
I want to try out vim, but have a little trouble with the config
Possible Duplicate: How to switch between visible buffers in emacs? I'm using C-x 2
let's say currently there are two buffers in my vim session, and I want
When I switch between buffers in vim with :bn and :bp, my status line
Since our switch from Visual Studio 6 to Visual Studio 2008, we've been using
Management wants us to switch to Infragistics. But my boss says that any 3rd

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.