Home

Awesome

micropython_nvim

<!-- panvimdoc-ignore-start --> <img width="1080" alt="image" src="./assets/cmd.png">

Theme: duskfox

<details> <summary>Showcase</summary> <img width="1080" alt="image" src="./assets/port.png"> <img width="1080" alt="image" src="./assets/run.png"> <img width="1080" alt="image" src="./assets/status.png"> </details> <!-- panvimdoc-ignore-end -->

Introduction

micropython_nvim is a plugin that aims to make it easier and more enjoyable to work on micropython projects in Neovim. See the quickstart section to get started.

N.B. If you open an existing project that has an .ampy configuration file in the root directory, the plugin will automatically configure the port and baud rate for you.

IMPORTANT This plugin assumes you are opening Neovim at the root of the project. Some commands will not behave in the expected way if you choose not to do this.

Goals

Features

Requirements

Quickstart

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

Next steps

Installation

<details> <summary>lazy.nvim</summary>
{
    "jim-at-jibba/micropython.nvim",
    dependencies = { "akinsho/toggleterm.nvim", "stevearc/dressing.nvim" },
}
</details> <details> <summary>packer</summary>
use {
    "jim-at-jibba/micropython.nvim",
    requires = { "akinsho/toggleterm.nvim", "stevearc/dressing.nvim" },
}
</details>

Usage

  local ignore_list = {
    ['.git'] = true,
    ['requirements.txt'] = true,
    ['.ampy'] = true,
    ['.vscode'] = true,
    ['.gitignore'] = true,
    ['project.pymakr'] = true,
    ['env'] = true,
    ['venv'] = true,
    ['__pycache__'] = true,
    ['.python-version'] = true,
    ['.micropy/'] = true,
    ['micropy.json'] = true,
  }

Project Setup

Steps to initialize a project

from machine import Pin
from time import sleep

led = Pin("LED", Pin.OUT)

while True:
    led.value(not led.value())
    print("LED is ON" if led.value() else "LED is OFF")
    sleep(0.5)
AMPY_BAUD=115200
# AMPY_PORT=
# Fix for macOS users' "Could not enter raw repl"; try 2.0 and lower from there:
# AMPY_DELAY=0.5
adafruit-ampy
rshell
micropython-rp2-stubs
ruff
{
  "reportMissingModuleSource": false
}

Now you be able to run the project using :MPRun.

Statusline

A statusline component can be easily added to show whether a buffer is tagged.

<!-- panvimdoc-ignore-start -->

Lualine Component

require("lualine").setup({
    sections = {
        lualine_b = {
            {
              require("micropython_nvim").statusline,
              cond = package.loaded["micropython_nvim"] and require("micropython_nvim").exists,
            },
        }
    }
})
<img width="1080" alt="image" src="./assets/status.png">

Not implemented (yet)

Inspiration and Thanks

<!-- panvimdoc-ignore-end -->