p5.nvim
Better editor support for p5.js in Neovim.
Warning
This plugin is still experimental but should work fine for most cases, I developed this on Linux so behaviour may not be uniform for certain edge cases. Any patches would be greatly appreciated ๐
Features โจ
- ๐ Create new p5.js projects
- ๐ Download and install p5.js libraries (core and contributor libraries)
- ๐ฅ๏ธ Cross-platform browser preview w/ live reload
- ๐ ๏ธ TypeScript support
- ๐ Comprehensive error reporting
๐ Requirements
-
Neovim 0.10.0+
-
plenary.nvim - Required for testing and utilities
-
curl or wget - For downloading p5.js libraries
-
One of the following for browser opening:
-
Linux:
xdg-open -
*macOSโฆ
p5.nvim
Better editor support for p5.js in Neovim.
Warning
This plugin is still experimental but should work fine for most cases, I developed this on Linux so behaviour may not be uniform for certain edge cases. Any patches would be greatly appreciated ๐
Features โจ
- ๐ Create new p5.js projects
- ๐ Download and install p5.js libraries (core and contributor libraries)
- ๐ฅ๏ธ Cross-platform browser preview w/ live reload
- ๐ ๏ธ TypeScript support
- ๐ Comprehensive error reporting
๐ Requirements
-
Neovim 0.10.0+
-
plenary.nvim - Required for testing and utilities
-
curl or wget - For downloading p5.js libraries
-
One of the following for browser opening:
-
Linux:
xdg-open -
macOS:
open -
Windows:
startcommand
Installation ๐
Using lazy.nvim (Recommended)
{
'prjctimg/p5.nvim',
dependencies = { 'nvim-lua/plenary.nvim' },
config = function()
require('p5.nvim').setup({
-- Optional configuration
auto_open_browser = true,
network_timeout = 30,
max_retries = 3,
})
end
}
Using packer.nvim
use {
'prjctimg/p5.nvim',
requires = { 'nvim-lua/plenary.nvim' },
config = function()
require('p5.nvim').setup()
end
}
โ๏ธ Configuration
p5.nvim can be customized with the following options:
require('p5.nvim').setup({
-- Directory where project templates are stored
-- Default: vim.fn.stdpath("config") .. "/p5.nvim/template"
template_dir = "~/.config/nvim/p5.nvim/template",
-- Version of p5.js to download from CDN
-- Default: "1.9.0"
p5_version = "1.9.0",
-- Automatically open browser when creating projects
-- Default: false
auto_open_browser = true,
-- Network timeout in seconds for downloads
-- Default: 30
network_timeout = 60,
-- Number of retry attempts for failed downloads
-- Default: 3
max_retries = 5,
})
๐ฎ Usage
Creating p5.js project (sketchspaceโ๏ธ)
:P5CreateProject
This will:
- Prompt you to select a directory for the project
- Create the project with validated templates
- Download p5.js libraries with retry logic
- Generate
jsconfig.jsonfor TypeScript support - Ask if you want to open the project
Installing contributor libraries
:P5InstallLibrary
Provides:
- Interactive library selection with descriptions
- Automatic HTML script tag insertion
- Error recovery and retry logic
Health check
:P5Health
Checks:
- plenary.nvim installation
- Network tool availability (curl/wget)
- Template directory status
Manual Setup
:P5Setup template_dir=/custom/path p5_version=2.0.0
Project Structure ๐
When you create a new project, it will have the following structure:
p5_sketch/
โโโ index.html # Main HTML file with p5.js includes
โโโ sketch.js # Your main sketch code
โโโ style.css # Basic styling for centered canvas
โโโ jsconfig.json # TypeScript configuration
โโโ libraries/ # Downloaded p5.js libraries
โโโ p5.min.js # Core p5.js library
โโโ p5.sound.min.js # Sound addon library
Available Libraries
p5.nvim supports installing any contributor libraries, (currently at the time of writing):
| Library | Description | Author |
|---|---|---|
| p5.accessibility | Canvas accessibility for visually impaired | Processing Foundation |
| p5.asciiart | Image-to-ASCII art converter | Pawel Janicki |
| grafica.js | 2D plotting and graphs | Javier Graciรก Carpio |
| mappa | Maps and geospatial data | Cristรณbal Valenzuela |
| ml5.js | Machine learning in the browser | NYU ITP/IMA |
| p5.collide2D | 2D collision detection | Ben Moren |
| p5.play | Game development tools | Paolo Pedercini |
| p5.speech | Speech recognition and synthesis | R. Luke DuBois |
| rita.js | Natural language processing | Daniel C. Howe |
๐ Troubleshooting
Common Issues
Downloads keep failing
- Check internet connection
- Try increasing
network_timeoutin configuration - Verify p5_version is correct and available
Browser wonโt open
- Ensure browser command is available (
xdg-open,open, orstart) - Manually open:
file:///path/to/your/project/index.html
Permission denied errors
- Check write permissions in target directory
- Verify template directory is accessible
- Run
:P5Healthfor detailed diagnosis
๐ค Contributing
Contributions are welcome! Please see our Contributing Guide for details.
Development Setup
- Clone the repository
- Install dependencies:
make install - Run tests:
make test - Format code:
make format - Check dependencies:
make check-deps
๐ Acknowledgments
- p5.vscode extension
- plenary.nvim
- Processing.org
License ๐
ยฉ๏ธ 2025 - Present Dean Tarisai
Released under the GNU GPL-3.0 License