Forem

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)