DEV Community

Ayedoun Châ-Fine ADEBI
Ayedoun Châ-Fine ADEBI

Posted on

🎉 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
Enter fullscreen mode Exit fullscreen mode

Now you have this:

MyAwesomeProject/
├── src/
│   └── main.py
└── tests/
    └── test_main.py
Enter fullscreen mode Exit fullscreen mode

🎨 Step 2: Open the Project in LazyVim

Navigate to your project folder:

cd MyAwesomeProject
Enter fullscreen mode Exit fullscreen mode

Open LazyVim:

nvim .
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

(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:

    Press Shift + h (previous buffer) or Shift + l (next buffer).

  • View Open Buffers:

    Press:

  <leader> + b
Enter fullscreen mode Exit fullscreen mode

Select your file from the list.

  • Close Buffers: Press:
  <leader> + c
Enter fullscreen mode Exit fullscreen mode

🧭 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:

    Press Ctrl-w s.

  • Vertical Split:

    Press Ctrl-w v.

Switch between splits:

Ctrl-w + arrow keys
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Now you can run commands like:

pytest tests/test_main.py
Enter fullscreen mode Exit fullscreen mode

To exit the terminal, type exit or press Ctrl-d.

Open a Floating Terminal

Need a quick terminal overlay? Press:

<leader> + f + t
Enter fullscreen mode Exit fullscreen mode

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> + /
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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/
Enter fullscreen mode Exit fullscreen mode

Now you can run these commands in LazyVim’s terminal:

make run
make test
Enter fullscreen mode Exit fullscreen mode

🎯 Step 9: Save Time with Key Mappings

LazyVim has built-in key mappings for efficiency. Here are a few gems:

  • Format Code: Press:
  <leader> + =
Enter fullscreen mode Exit fullscreen mode
  • Toggle Comments: Press:
  <leader> + /
Enter fullscreen mode Exit fullscreen mode
  • Find and Replace: Press :%s/old_text/new_text/g to replace all occurrences of old_text with new_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)