# Dev Environment Stack
Modern terminal-based development environments are built on multiple layers working together. Understanding these layers helps you customize your workflow and troubleshoot issues effectively.
## The Four-Layer Architecture
Your development environment operates on four distinct layers, each with specific responsibilities:
```
┌─────────────────────────────────────┐
│ Layer 4: Editor (Neovim/LazyVim) │ ← File editing, IDE features
├─────────────────────────────────────┤
│ Layer 3: Shell (zsh/bash) │ ← Command execution, line editing
├─────────────────────────────────────┤
│ Layer 2: Multiplexer (tmux) │ ← Session management, panes
├─────────────────────────────────────┤
│ Layer 1: Terminal (Ghostty/iTerm) │ ← Window management, rendering
└─────────────────────────────────────┘
```
## Layer 1: Terminal Emulator
**Examples:** Ghostty, iTerm2, Alacritty, Warp, Kitty
**Responsibilities:**
- Rendering text and colors on screen
- Tab and window management (Cmd+T for new tabs)
- Font rendering and ligature support
- GPU acceleration for smooth scrolling
- Color scheme configuration
**What it does NOT do:**
- Persistent sessions (sessions die when you close the terminal)
- Advanced pane splitting and management
- Command-line editing
**Key insight:** The terminal is just the display layer. Closing it kills everything inside.
## Layer 2: Terminal Multiplexer (tmux)
**See:** [[tmux - Terminal Multiplexer]]
**Responsibilities:**
- Session persistence (survives terminal closure)
- Advanced pane splitting and layout management
- Multiple windows within a session
- Session attach/detach workflows
- Scriptable preset layouts
**Why you need it:**
- Create development environments with preset layouts
- Detach from work, close laptop, reattach later without losing state
- Work on remote servers and maintain persistent sessions
- Better pane management than terminal-native splits
**Example workflow:**
```bash
# Create a dev session with 3 panes
tmux new -s dev \; \
split-window -h \; \
split-window -v \; \
send-keys -t 0 'nvim' C-m \; \
send-keys -t 1 'npm run dev' C-m \; \
send-keys -t 2 'git status' C-m
```
This creates:
```
┌─────────────┬─────────────┐
│ │ Server │
│ Editor │ Running │
│ (nvim) ├─────────────┤
│ │ Git │
└─────────────┴─────────────┘
```
## Layer 3: Shell (zsh/bash)
**See:** [[Shell Line Editing with Zsh]], [[Terminal Keyboard Shortcuts]]
**Responsibilities:**
- Command execution and environment variables
- Command-line editing (Ctrl+W, Option+arrows, etc.)
- Command history and search
- Tab completion
- Aliases and functions
- Prompt customization (via Starship, Oh My Zsh, etc.)
**Key features most people don't know:**
- Readline/emacs keybindings for fast line editing
- Reverse search with Ctrl+R
- History expansion with `!!`, `!
, etc.
- Directory navigation with `cd -`, `pushd`, `popd`
**Keyboard shortcuts you use every day:**
- Ctrl+W: Delete word backward
- Ctrl+U: Delete to start of line
- Ctrl+A/E: Jump to start/end of line
- Option+←/→: Move by word
- Ctrl+R: Reverse history search
## Layer 4: Editor (Neovim/LazyVim)
**See:** [[Neovim/Neovim - The Vim Ecosystem]], [[Neovim/LazyVim Setup]]
**Responsibilities:**
- File editing with modal editing (insert mode vs normal mode)
- LSP integration for code intelligence
- Git integration
- Fuzzy finding files and text
- Terminal emulation within the editor
**Why Neovim over VS Code in terminal:**
- Extremely fast, even on remote servers
- Modal editing is faster once you learn it
- Scriptable with Lua
- Works over SSH without lag
- Composable with tmux and shell workflows
**The LazyVim advantage:**
- Pre-configured with sane defaults
- Modern IDE features out of the box
- Easy plugin management
- Still pure Neovim underneath
## How the Layers Work Together
**Scenario 1: Opening a new project**
1. **Terminal layer:** Press Cmd+T to open new tab in Ghostty
2. **Multiplexer layer:** Run `tmux new -s myproject` to create persistent session
3. **Shell layer:** Run `cd ~/Code/myproject` to navigate
4. **Editor layer:** Run `nvim .` to open Neovim in project directory
**Scenario 2: Editing a command before running it**
1. **Shell layer:** Type long command
2. **Shell layer:** Use Ctrl+A to jump to start, Ctrl+W to delete words
3. **Shell layer:** Use Option+→ to navigate by word
4. **Shell layer:** Press Enter to execute
**Scenario 3: Persistent development session**
1. **Multiplexer layer:** Create tmux session with preset layout
2. **Editor layer:** Open Neovim in first pane
3. **Shell layer:** Run dev server in second pane
4. **Multiplexer layer:** Detach with Ctrl+B D, close laptop
5. **Terminal layer:** Later, reopen terminal
6. **Multiplexer layer:** Reattach with `tmux attach -t dev` - everything still running!
## Common Confusion Points
**"Why isn't my session persistent when I close the terminal?"**
→ You need tmux (Layer 2). The terminal emulator alone doesn't persist sessions.
**"Why don't Vim keybindings work in my shell?"**
→ Shell (Layer 3) and Editor (Layer 4) are separate. Use `set -o vi` in shell for vi-mode, or learn emacs keybindings (Ctrl+W, etc.).
**"How do I split panes?"**
→ Use tmux (Layer 2) for persistent splits, not terminal-native splits. Tmux splits survive terminal closure.
**"Why is my text rendering weird?"**
→ Terminal emulator (Layer 1) issue. Check font configuration and ligature support.
## Recommended Setup for Maximum Productivity
1. **Terminal:** Ghostty or Alacritty (fast, GPU-accelerated)
2. **Multiplexer:** tmux with custom keybindings and preset layouts
3. **Shell:** zsh with Starship prompt and custom aliases
4. **Editor:** LazyVim (Neovim with modern IDE features)
**Further reading:**
- [[tmux - Terminal Multiplexer]] - Session management and layouts
- [[Terminal Keyboard Shortcuts]] - Master shell line editing
- [[Neovim/Neovim - The Vim Ecosystem]] - Understanding Vim/Neovim/LazyVim
- [[Neovim/LazyVim Workflows/File Navigation in LazyVim]] - Efficient file management