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

How do I use Vim tabs as separate workspaces with different working directories?

Answer

:tabnew | lcd /path/to/project

Explanation

Vim's :lcd (local change directory) sets the working directory per window. Combined with tabs, this lets you use each tab as an independent workspace with its own project root.

How it works

  • :cd /path changes the working directory globally (all windows)
  • :lcd /path changes the working directory for the current window only
  • :tcd /path (Vim 8.1+) changes the directory for the current tab (all windows in it)

Setting up project tabs

" Tab 1: Frontend project
:tabnew
:tcd ~/projects/frontend
:edit src/App.tsx

" Tab 2: Backend project  
:tabnew
:tcd ~/projects/backend
:edit main.go

" Tab 3: Documentation
:tabnew
:tcd ~/projects/docs
:edit README.md

Navigating tabs

gt        " Next tab
gT        " Previous tab
3gt       " Go to tab 3
:tabs     " List all tabs
:tabclose " Close current tab

Tips

  • Use :tcd (Vim 8.1+) instead of :lcd — it applies to the whole tab, not just one window
  • :pwd shows the current working directory, useful for confirming which project you're in
  • File completion (<C-x><C-f>) and :find use the local directory, making them project-aware
  • Each tab can have its own splits, buffers, and working directory — a true multi-project setup
  • Combine with :mksession to save and restore your entire multi-project layout

Next

How do I always access my last yanked text regardless of deletes?