Skip to content

A Neovim plugin for JavaScript, TypeScript projects. It provides a way to execute npm scripts without leaving the editor.

Notifications You must be signed in to change notification settings

sajjathossain/nvim-npm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Nvim NPM

A modern Neovim plugin for JavaScript, TypeScript, and Node.js projects. Execute npm/yarn/pnpm/bun scripts seamlessly without leaving your editor.

FeaturesScreenshotsInstallationCommandsAPIDefault MappingsConfigurationHealth Check

Features

  • 🚀 Execute npm/yarn/pnpm/bun scripts without leaving the editor
  • 🔧 Powered by @antfu/ni - Universal package manager interface
  • 🔍 Auto-detect package manager (npm, yarn, pnpm, bun) based on lock files
  • 📁 Multi-project support - works with monorepos and nested projects
  • 🎯 Telescope integration for fuzzy finding scripts and projects
  • 💻 Terminal management with toggleterm.nvim integration
  • 📦 Package installation/removal with interactive package name input
  • Smart caching for better performance
  • 🛠️ Health check command to verify setup
  • 🎨 Highly configurable with sensible defaults
  • 🔄 Auto-installation of ni if not present

Screenshots

  • Search projects that contain a package.json file

search projects

  • Show scripts in a telescope window

search scripts in the project

  • execute script

execute command

Installation

Install the plugin with your favorite package manager:

Plug 'sajjahossain/nvim-npm'
Plug 'akinsho/toggleterm.nvim',
Plug 'nvim-telescope/telescope.nvim'
Plug 'rcarriga/nvim-notify'
use 'sajjahossain/nvim-npm'
use 'akinsho/toggleterm.nvim',
use 'nvim-telescope/telescope.nvim'
use 'rcarriga/nvim-notify'
require('lazy').setup({
  {
    'sajjahossain/nvim-npm',
    config = true,
    dependencies = {
      'nvim-telescope/telescope.nvim',
      'akinsho/toggleterm.nvim',
      'rcarriga/nvim-notify',
    }
  }
})

Commands

Command Description
:ShowScriptsInTelescope Shows the available scripts in a telescope window
:OpenTerminal Opens one of the available terminals
:InstallPackage Installs a package in the current project using ni
:RemovePackage Removes a package from the current project using ni
:RefreshPackageJsonCache Refreshes the package.json cache
:ExitTerminalSession Exits the selected terminal session
:ExitAllTerminalSession Exits all terminal sessions
:PrintScripts Prints package.json scripts paths (debug)

API

Function Description
require('nvim-npm').showScripts() Shows the available scripts in a telescope window
require('nvim-npm').openTerminal() Opens one of the available terminals
require('nvim-npm').installPackage() Installs a package in the current project using ni
require('nvim-npm').removePackage() Removes a package from the current project using ni
require('nvim-npm').exitTerminal() Closes the selected terminal
require('nvim-npm').exitAllTerminal() Closes all the terminals

Default Mappings

Mode Key Action
Normal ;pi Installs a package in the current project
Normal ;pl Lists the available scripts
Normal ;po Opens one of the available terminals
Normal ;pr Refreshes the package.json cache

Configuration

You can configure the plugin by setting the following options:

require('nvim-npm').setup({
  mappings = { -- key mappings [optional]
    t = {
      ["<esc><esc>"] = "<C-\\><C-n>", -- exit terminal mode
    },
    n = {
      [";pl"] = "<cmd>ShowScriptsInTelescope<cr>", -- show scripts
      [";po"] = "<cmd>OpenTerminal<cr>",           -- open terminal
      [";pi"] = "<cmd>InstallPackage<cr>",        -- install package
      [";pr"] = "<cmd>RefreshPackageJsonCache<cr>", -- refresh cache
    }
  }
})

Configuration Options

Option Type Default Description
mappings table or false default mappings Key mappings configuration. Set to false to disable all default mappings
mappings.n table see above Normal mode key mappings
mappings.t table see above Terminal mode key mappings

Health Check

Run :checkhealth nvim-npm to verify your setup and check for any issues.

Package Manager Integration

This plugin uses @antfu/ni for universal package manager support. The plugin will automatically:

  • Detect your package manager (npm, yarn, pnpm, bun) based on lock files
  • Install @antfu/ni globally if not present
  • Use the appropriate commands (ni, nr, nun, nid) for each operation

Manual Installation

If you prefer to install ni manually:

npm install -g @antfu/ni

Supported Package Managers

  • npm - package-lock.json
  • yarn - yarn.lock
  • pnpm - pnpm-lock.yaml
  • bun - bun.lockb

The plugin automatically detects which package manager to use based on the lock files present in your project.

About

A Neovim plugin for JavaScript, TypeScript projects. It provides a way to execute npm scripts without leaving the editor.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages