How do I change the working directory for only the current window without affecting other windows or tabs?
Answer
:lcd
Explanation
:cd changes the global working directory, affecting every window and tab in the session. :lcd {path} does the same thing but scoped to the current window only. This lets you have different windows rooted at different project directories simultaneously — handy when editing files from two separate repositories at once.
How it works
:lcd {path}sets a window-local CWD; the global CWD is unchanged:lcd -navigates to the previous window-local CWD (likecd -in a shell):pwdshows the effective CWD for the current window- If no local CWD is set, the window inherits the global CWD
:tcd {path}is the tab-scoped equivalent — applies to all windows in a tab but not others
Example
Open two vertical splits and give each its own project root:
:vsplit
:lcd ~/projects/frontend
:wincmd h
:lcd ~/projects/backend
Now :e tab-completion, gf, :find, and shell commands via :! all respect the per-window directory.
Tips
- Use
:lcd %:hto switch to the directory of the current file — useful when opening a file and immediately wanting to navigate relative to it :cd(no args) returns to$HOME;:lcd(no args) in some versions removes the local override:tcdis useful when a tab represents a logical project and you want all its splits to share the same root