PlatformIO with Vim/Neovim

๐Ÿš€ Using PlatformIO with Vim/Neovim: Complete Setup Guide

This is a practical log of how to set up and integrate PlatformIO with Vim/Neovim โ€” including project generation, language server (IntelliSense), building, uploading, and even serial monitoring (like Arduino IDE or Deviot in Sublime).


๐Ÿ“ฆ 1. Install PlatformIO Core

First, make sure you have PlatformIO Core (CLI) installed:

pip install platformio

Verify:

pio --version

๐Ÿ“ 2. Create and Initialize a Project

Make a project folder and generate a PlatformIO project for Vim:

mkdir my_project && cd my_project
pio project init --ide vim --board <BOARD_ID>

๐Ÿ‘‰ Find your board ID with:

pio boards

โš ๏ธ If you later add libraries, you must reinitialize the project:


For Vim/Neovim youโ€™ll want:

  • coc.nvim โ†’ LSP client for IntelliSense

  • clangd โ†’ C/C++ language server (autocompletion, diagnostics)

  • neomake โ†’ async builds & linting

  • vim-pio โ†’ PlatformIO command helpers


๐Ÿ”Œ 4. Installing Plugins (vim-plug)

First install vim-plugarrow-up-right:

Then in ~/.vimrc (Vim) or ~/.config/nvim/init.vim (Neovim):

Install plugins:


โš™๏ธ 5. clangd Setup (LSP)

Install clangd:

Inside Vim/Neovim:

Now you get autocompletion, jump-to-definition, error squiggles, etc.


๐Ÿ›  6. Build & Upload Integration

Add these mappings in your ~/.vimrc or init.vim:

Add this to auto-build on save:


๐Ÿ–ฅ 7. Serial Monitor Integration

PlatformIO has a built-in serial monitor:

Option 1: Run directly in Vim (works in both Vim & Neovim)

Option 2: Open in a split terminal (Neovim only)

Option 3: Add to Makefile

Add this target:

Then run:

โšก You can also fix baud rate:

or set monitor_speed = 115200 in platformio.ini.


๐ŸŽน 8. Suggested Workflow Mappings

Hereโ€™s a smooth Arduino-like experience inside Vim/Neovim:


โœ… 9. What You Get

  • PlatformIO project generation inside Vim/Neovim

  • IntelliSense, go-to-definition, error highlighting via coc.nvim + clangd

  • Async builds with Neomake

  • Keybindings for build, upload, monitor

  • Arduino-like workflow, but in Vim/Neovim ๐Ÿ’ช


๐Ÿ”ฎ Final Notes

  • For Vim 8: You must use coc.nvim since it works in both Vim and Neovim.

  • For Neovim (0.5+): You could instead use the built-in LSP client (nvim-lspconfig + clangd), but coc.nvim keeps things universal.

  • Always re-run pio project init after adding new libraries.

Last updated

Was this helpful?