# File Navigation in LazyVim Fast file navigation is the foundation of efficient coding. LazyVim provides multiple tools for finding and opening files—learn when to use each one. ## The Three Ways to Navigate 1. **Telescope** - Fuzzy finding (most common) 2. **Neo-tree** - File explorer (visual browsing) 3. **Buffer navigation** - Switch between open files ## Telescope - Fuzzy Finding **Telescope** is your primary navigation tool. It's a fuzzy finder that searches files, text, symbols, and more. ### Find Files ``` Space + f + f ``` **How it works:** - Type partial filename (fuzzy match) - No need for exact matches or paths - Instant results as you type **Examples:** ``` # Project structure: src/components/UserProfile.tsx src/utils/formatDate.ts tests/components/UserProfile.test.tsx # Find "UserProfile.tsx": Space + f + f Type: "upro" → Matches UserProfile.tsx Type: "userpro" → Also matches Type: "cmp/user" → Also matches (path aware) ``` **Pro tips:** - Use `Ctrl+j` / `Ctrl+k` to move down/up in results - `Enter` to open file - `Ctrl+x` to open in horizontal split - `Ctrl+v` to open in vertical split - `Ctrl+t` to open in new tab ### Search Text in Files (Grep) ``` Space + s + g ``` **Find any text across your entire project:** ``` Space + s + g Type: "function handleClick" → Shows all files containing that text → Shows line number and preview ``` **Use cases:** - Find where a function is defined - Find all TODOs - Find API endpoint usage - Find error messages **Pro tip:** Use regex: ``` Space + s + g Type: "const.*=.*useState" → Finds all useState declarations ``` ### Find Recent Files ``` Space + f + r ``` **Shows files you recently opened:** - Faster than fuzzy finding when you just edited a file - Great for switching between 2-3 files repeatedly ### Find Buffers (Open Files) ``` Space + f + b ``` **Lists currently open files:** - Use this instead of cycling with `:bn` / `:bp` - Type partial filename to filter **Example workflow:** ``` # You have 10 files open Space + f + b Type: "user" → Shows only UserProfile.tsx, UserSettings.tsx Enter → Opens selected file ``` ### Find Symbols (Go to Symbol) ``` Space + s + s ``` **Shows all functions, classes, variables in current file:** ```javascript // Your file has: function handleSubmit() {} function validateForm() {} const API_URL = "..." class UserService {} Space + s + s Type: "valid" → Jump directly to validateForm() ``` **Great for navigating large files without scrolling.** ### Find Git Files ``` Space + f + g ``` **Only shows files tracked by git:** - Ignores node_modules, build artifacts, etc. - Faster than `Space + f + f` in large repos ## Neo-tree - File Explorer **Visual file browser** for when you need to see directory structure. ### Toggle Explorer ``` Space + e ``` **Navigation:** - `j` / `k` - Move up/down - `Enter` - Open file or expand folder - `a` - Create new file/folder - `d` - Delete - `r` - Rename - `c` - Copy - `x` - Cut - `p` - Paste - `q` - Close explorer **Keybindings in Neo-tree:** | Key | Action | |-----|--------| | `a` | Add (create file/folder) | | `d` | Delete | | `r` | Rename | | `c` | Copy | | `x` | Cut | | `p` | Paste | | `y` | Copy filename | | `Y` | Copy relative path | | `gy` | Copy absolute path | | `o` | Open file | | `s` | Open in split | | `t` | Open in tab | ### When to Use Neo-tree **Use Neo-tree when:** - ✅ Exploring unfamiliar codebase - ✅ Need to see folder structure - ✅ Creating/deleting/renaming multiple files - ✅ Visual context helps you think **Use Telescope when:** - ✅ You know the filename - ✅ Quick file switching - ✅ Searching for text - ✅ You're already in flow state ## Buffer Navigation **Buffers** are open files in memory. ### Switch Between Buffers ``` ]b # Next buffer [b # Previous buffer ``` **Or use Telescope:** ``` Space + f + b ``` ### Close Buffer ``` Space + b + d # Close current buffer ``` ### List All Buffers ``` Space + f + b # Telescope buffer search ``` **Or see buffer list:** ``` :buffers # Show numbered list :b <number> # Jump to buffer number :b <partial> # Jump to buffer by partial name ``` ## Window (Split) Navigation **Windows** are the visible panes on screen. ### Navigate Between Windows ``` Ctrl + h # Left window Ctrl + j # Down window Ctrl + k # Up window Ctrl + l # Right window ``` ### Create Splits ``` Ctrl + w + s # Horizontal split Ctrl + w + v # Vertical split ``` ### Close Window ``` Ctrl + w + c # Close current window Ctrl + w + o # Close all other windows (keep current) ``` ### Resize Windows ``` Ctrl + w + = # Equal size Ctrl + w + > # Wider Ctrl + w + < # Narrower Ctrl + w + + # Taller Ctrl + w + - # Shorter ``` ## Tab Navigation **Tabs** are collections of windows. ### Tab Management ``` Space + <tab> + l # List tabs Space + <tab> + n # New tab Space + <tab> + d # Close tab gt # Next tab gT # Previous tab ``` **Tabs are useful when:** - Working on two separate features simultaneously - Keeping different contexts (e.g., code vs config files) **Most people don't need tabs—buffers + splits are enough.** ## Real-World Workflows ### Scenario 1: "I need to edit UserProfile.tsx" **Method 1: Telescope (fastest)** ``` Space + f + f Type: "upro" Enter ``` **Method 2: Neo-tree (visual)** ``` Space + e Navigate to src/components/ Enter on UserProfile.tsx ``` ### Scenario 2: "Where is the login function defined?" ``` Space + s + g Type: "function login" Enter on result ``` ### Scenario 3: "Switch between 3 files I'm actively editing" ``` # First time: Open via Telescope Space + f + f → Open File1 Space + f + f → Open File2 Space + f + f → Open File3 # Then: Quick switch via buffers Space + f + b Type partial filename Enter ``` ### Scenario 4: "Navigate large file" ``` # Inside the file: Space + s + s # Symbol search Type function name Enter → Jump there ``` ### Scenario 5: "Explore new codebase" ``` Space + e # Open file explorer Navigate folders j/k to move Enter to open files ``` ## Advanced Techniques ### Jump to Definition (LSP) ``` gd # Go to definition ``` **This is NOT file navigation—it's code intelligence:** - Cursor on a function name - Press `gd` - Jumps to where it's defined (even in another file) **Go back:** ``` Ctrl + o # Jump back Ctrl + i # Jump forward ``` ### Jump List Neovim tracks everywhere you've been: ``` Ctrl + o # Jump to older position Ctrl + i # Jump to newer position ``` **Example:** ``` 1. You're in File A 2. Press gd → Jump to File B 3. Press gd → Jump to File C 4. Press Ctrl+o → Back to File B 5. Press Ctrl+o → Back to File A ``` ### Marks **Set marks** to bookmark locations: ``` m + a # Set mark 'a' at cursor `a # Jump to mark 'a' :marks # List all marks ``` **Use marks for:** - Temporary bookmarks within a file - Quick navigation between important spots ### Search and Replace in Multiple Files ``` # 1. Find all occurrences Space + s + g Type: "oldFunction" # 2. Send results to quickfix list Ctrl + q # 3. Search and replace :cdo s/oldFunction/newFunction/g # 4. Save all changes :wa ``` ## Keyboard Shortcut Summary | Action | Keybinding | When to Use | |--------|------------|-------------| | **Find files** | `Space f f` | Know filename, quick navigation | | **Find text** | `Space s g` | Search across all files | | **Recent files** | `Space f r` | Recently edited files | | **File explorer** | `Space e` | Visual browsing, creating files | | **Buffers** | `Space f b` | Switch between open files | | **Symbols** | `Space s s` | Navigate within file | | **Next buffer** | `]b` | Cycle through open files | | **Go to def** | `gd` | Jump to function definition | | **Jump back** | `Ctrl o` | Undo jump | | **Jump forward** | `Ctrl i` | Redo jump | ## Pro Tips 1. **Default to Telescope** - It's fast and works for 90% of navigation 2. **Learn fuzzy matching** - Type "upr" instead of "UserProfile", it's faster 3. **Use Neo-tree sparingly** - Only when you need visual context 4. **Master jump list** (Ctrl+o / Ctrl+i) - Navigate your code history 5. **Don't overuse tabs** - Buffers are usually enough 6. **Memorize `gd`** - Jump to definition is the most used LSP feature ## Common Mistakes **❌ Using arrow keys in Telescope** → Use Ctrl+j / Ctrl+k instead (faster) **❌ Scrolling through file explorer** → Use Telescope fuzzy find instead **❌ Opening too many splits** → Keep it simple: 2-3 splits max **❌ Not learning jump list** → Ctrl+o is how you navigate code efficiently **Related:** - [[LazyVim Setup]] - Initial configuration - [[Code Editing Workflows]] - Once you've found the file - [[LSP and Code Intelligence]] - Using gd, gr, and other LSP features - [[Neovim - The Vim Ecosystem]] - Understanding the bigger picture