Welcome back, brave LazyVim adventurer! 🚀 In Part 1, you tamed LazyVim and learned the basics. Now it’s time to level up and conquer project management with LazyVim. This guide will teach you how to handle multiple files, navigate directories, and even integrate your terminal like a pro. Let’s dive in!
🏗️ Step 1: Project Setup
Let’s start by creating a project structure. Fire up your terminal (not LazyVim yet):
Create Your Project
mkdir -p MyAwesomeProject/src
mkdir MyAwesomeProject/tests
touch MyAwesomeProject/src/main.py
touch MyAwesomeProject/tests/test_main.py
Now you have this:
MyAwesomeProject/
├── src/
│ └── main.py
└── tests/
└── test_main.py
🎨 Step 2: Open the Project in LazyVim
Navigate to your project folder:
cd MyAwesomeProject
Open LazyVim:
nvim .
Yes, the .
tells LazyVim to open the current directory as a workspace. You'll see a file explorer pop up on the left. 🎉
📁 Step 3: Navigating the File Explorer (Nvim-Tree)
LazyVim comes preloaded with Nvim-Tree, a file explorer for your projects.
Open and Close the File Explorer
Press:
<leader> + e
(Reminder: <leader>
= spacebar
)
The file tree shows your project structure. Use the arrow keys to navigate:
- Enter: Open a file or folder.
- Backspace: Go up one level.
- a: Create a new file or folder.
- d: Delete a file or folder.
- r: Rename a file or folder.
🔀 Step 4: Switching Between Files
You can’t just live in one file, right? LazyVim makes switching files a breeze.
Buffers Are Your Friends
Every file you open becomes a buffer. Think of buffers as open tabs in a browser.
Switch Buffers:
PressShift + h
(previous buffer) orShift + l
(next buffer).View Open Buffers:
Press:
<leader> + b
Select your file from the list.
- Close Buffers: Press:
<leader> + c
🧭 Step 5: Move Around the Project
LazyVim is all about quick navigation.
Navigate Between Splits
Want to edit two files side by side? Use splits:
Horizontal Split:
PressCtrl-w s
.Vertical Split:
PressCtrl-w v
.
Switch between splits:
Ctrl-w + arrow keys
Jump to Definitions
If you’re working on a Python file, move to a function definition with gd
(go to definition). To return, press Ctrl-o
.
💻 Step 6: Run Terminal Commands
Sometimes, you need to execute commands without leaving LazyVim. Here’s how:
Open the Terminal
LazyVim lets you pop up a terminal with ease. Press:
<leader> + t
Now you can run commands like:
pytest tests/test_main.py
To exit the terminal, type exit
or press Ctrl-d
.
Open a Floating Terminal
Need a quick terminal overlay? Press:
<leader> + f + t
This opens a terminal in a floating window. Close it with Ctrl-w q
.
🔍 Step 7: Searching and Jumping
You don’t have to scroll endlessly—LazyVim has your back!
Search Across Files
Press:
<leader> + /
Type your search term, and LazyVim will look across your project. Navigate through results with Enter
.
Jump to a File
Want to quickly open a specific file? Press:
<leader> + p
Start typing the file name, and LazyVim will find it for you.
🛠️ Step 8: Project-Specific Commands
Sometimes, you’ll want to run project-specific commands like linting or testing.
Create a Makefile
Add a Makefile
to your project:
run:
python src/main.py
test:
pytest tests/
Now you can run these commands in LazyVim’s terminal:
make run
make test
🎯 Step 9: Save Time with Key Mappings
LazyVim has built-in key mappings for efficiency. Here are a few gems:
- Format Code: Press:
<leader> + =
- Toggle Comments: Press:
<leader> + /
-
Find and Replace:
Press
:%s/old_text/new_text/g
to replace all occurrences ofold_text
withnew_text
in the current file.
🎉 Step 10: Flex Your LazyVim Skills
Congrats, you’ve unlocked Part 2 of the LazyVim adventure. By now, you’re managing projects, navigating files like a ninja, and running commands like a pro.
Remember: LazyVim is your dragon. Keep taming it, and soon you’ll be flying through code faster than ever. Stay curious, have fun, and may your projects always compile on the first try. 🚀
Top comments (0)