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:
gtto frontend tab::pwd→~/projects/frontendgtto backend tab::pwd→~/projects/backend
Practical uses
:findandgfsearch 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 %:hsets the tab directory to the directory of the currently open file:tcd -returns to the previous directory for this tab- After
:tcd, the tab'sstatuslinecan show the local directory using%{getcwd()} - Plugins like vim-rooter can automatically
:lcdor:tcdto the project root when you open a file