Micropython.nvim :: Neovim Plugin

lua neovim micropython tool

micropython_nvim

Streamlined MicroPython Development Inside Neovim

micropython_nvim is a powerful Neovim plugin I created to enhance the MicroPython development experience. It brings the convenience of modern development workflows to microcontroller programming, allowing you to run code, manage files, and access the REPL without ever leaving your editor.

Key Features

  • Seamless Code Execution: Run your Python files directly on your microcontroller with a single command
  • Simplified File Management: Upload individual files or entire projects with intelligent file filtering
  • Integrated REPL Access: Interact with your device’s REPL inside Neovim
  • Smart Project Setup: Initialize new projects with sensible defaults and required configuration
  • Device Configuration: Easily manage connection settings like port and baud rate
  • Statusline Integration: See your connection status at a glance

Getting Started

Prerequisites

Installation

Using lazy.nvim:

{
    "jim-at-jibba/micropython.nvim",
    dependencies = { "akinsho/toggleterm.nvim", "stevearc/dressing.nvim" },
}

Basic Configuration

Add a keybinding to run your code:

vim.keymap.set("n", "<leader>mr", require("micropython_nvim").run)

For the best experience, add the status component to your statusline:

require("lualine").setup({
    sections = {
        lualine_b = {
            {
              require("micropython_nvim").statusline,
              cond = package.loaded["micropython_nvim"] and require("micropython_nvim").exists,
            },
        }
    }
})

Core Commands

CommandDescription
:MPRunRun current buffer on the microcontroller
:MPSetPortConfigure the connection port
:MPSetBaudSet the baudrate for device communication
:MPReplOpen the integrated REPL
:MPInitInitialize a new project structure
:MPUploadUpload the current file to the device
:MPUploadAllUpload the entire project with smart filtering
:MPEraseOneRemove a file from the device
:MPSetStubsConfigure board-specific stubs for autocomplete

Project Setup Workflow

  1. Create a new project directory and optional virtual environment
  2. Run :MPInit to generate the basic project structure
  3. Configure your connection with :MPSetPort and :MPSetBaud
  4. Select appropriate board stubs with :MPSetStubs
  5. Install dependencies with pip install -r requirements.txt
  6. Start developing with :MPRun to test your code

The initialization process creates several helpful files:

  • A starter main.py example that blinks the onboard LED
  • Configuration files for Ampy, type stubs, and linting
  • A requirements.txt with necessary dependencies

Smart Defaults

The plugin comes with intelligent defaults to make your workflow smoother:

  • Automatic port and baud rate detection from existing .ampy files
  • Smart file filtering during uploads (ignoring git files, caches, etc.)
  • Board-specific stub configuration for improved code completion
  • Sensible default delay settings for reliable device communication

Development Status

Feature roadmap:

  • ✅ Single file execution and upload
  • ✅ Full project upload with filtering
  • ✅ File deletion capabilities
  • ✅ Project initialization and configuration
  • ⏳ Bulk file deletion option
  • ⏳ Retrieve files from device

Acknowledgments

This project was inspired by nvim-platformio.lua and aims to bring similar workflow improvements to the MicroPython ecosystem.


View the full documentation on GitHub.