vimtricks.wiki Concise Vim tricks, one at a time.

How do I set the working directory for just the current tab page without affecting other tabs?

Answer

:tcd {path}

Explanation

:tcd (tab-local cd) changes the current working directory only for the current tab page. Other tab pages keep their own working directories. This is invaluable for multi-project workflows — each project gets its own tab with its own root directory.

Commands

Command Scope
:cd {path} Changes directory globally (all windows and tabs)
:lcd {path} Changes directory for the current window only
:tcd {path} Changes directory for the current tab only
:cd - Return to the previous directory
:pwd Show the current working directory

Example workflow

Open two projects in separate tabs:

:tabnew
:tcd ~/projects/frontend
:tabnew
:tcd ~/projects/backend

Now each tab has its own working directory:

  • gt to frontend tab: :pwd~/projects/frontend
  • gt to backend tab: :pwd~/projects/backend

Practical uses

  • :find and gf search relative to the tab's directory
  • Shell commands (:!make, :terminal) run in the tab's directory
  • FZF, CtrlP, and other file-finding plugins search from the tab's root

Tips

  • :tcd %:h sets the tab directory to the directory of the currently open file
  • :tcd - returns to the previous directory for this tab
  • After :tcd, the tab's statusline can show the local directory using %{getcwd()}
  • Plugins like vim-rooter can automatically :lcd or :tcd to the project root when you open a file

Next

How do I run a search and replace only within a visually selected region?