dev-resources.site
for different kinds of informations.
π LazyVim Adventure Part 2: Managing Projects Like a Boss! π
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. π
Featured ones: