Skip to content

Extending the use of Neovim's `gx`

License

Notifications You must be signed in to change notification settings

rmagatti/gx-extended.nvim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

69 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

⭐ gx-extended.nvim

Extend Neovim's gx to open anything under your cursor!

License Neovim Lua

Features β€’ Installation β€’ Configuration β€’ Documentation


🎯 What is this?

gx-extended.nvim supercharges Neovim's built-in gx command. Press gx on anything β€” package names, import statements, issue numbers, commit hashes, and more β€” and it opens the right URL in your browser.

Before: gx only worked on URLs
After: gx works on 20+ different patterns across all your files!

✨ Highlights

  • πŸš€ 19 built-in handlers β€” npm, cargo, docker, terraform, git, and more
  • 🎯 Deterministic ordering β€” Predictable priority system (first defined = first checked)
  • 🎁 4 optional power features β€” NPM imports, GitHub permalinks, Jira, Linear
  • πŸ”§ Zero config needed β€” Works out of the box
  • 🎨 Fully extensible β€” Add your own patterns easily
  • πŸ“š 900+ lines of docs β€” Examples for everything
  • ⚑ Lightweight β€” Heavy features are opt-in

🎬 Demo

Press gx on any of these:

import express from "express"        // β†’ Opens npmjs.com
serde = "1.0"                        // β†’ Opens crates.io
FROM nginx:alpine                    // β†’ Opens hub.docker.com
Fixed CVE-2024-1234                  // β†’ Opens nvd.nist.gov
See commit a1b2c3d                   // β†’ Opens GitHub commit
Visit docs.github.com                // β†’ Opens with https://

🌟 Features

πŸ“¦ Package Managers (7 supported)
Language File Example Opens
JavaScript/TypeScript package.json "express": "^4.18.2" npmjs.com
Rust Cargo.toml serde = "1.0" crates.io
Go go.mod github.com/gin-gonic/gin pkg.go.dev
Python requirements.txt django>=4.0 pypi.org
Ruby Gemfile gem "rails" rubygems.org
Homebrew Brewfile brew "neovim" formulae.brew.sh
Docker Dockerfile FROM nginx hub.docker.com
☁️ Infrastructure & DevOps
  • Terraform (*.tf) β€” AWS/GCP resource documentation
    • resource "aws_instance" β†’ Terraform Registry
  • Docker β€” Official images and user repositories
    • FROM nginx:alpine β†’ Docker Hub
    • FROM user/image:tag β†’ Docker Hub
πŸ”— Git & Version Control
  • Git Commits β€” Opens on GitHub/GitLab/Bitbucket
    • a1b2c3d β†’ commit page (auto-detects remote)
  • GitHub Permalinks ⭐ (optional) β€” Share exact code locations
    • Press gx on any line β†’ github.com/repo/file.ts#L42
πŸ“ Documentation & References
  • Markdown Links β€” [text](url) β†’ Opens URL
  • CVE References β€” CVE-2024-1234 β†’ NVD database
  • Python PEPs β€” PEP 8 β†’ Python Enhancement Proposals
  • URLs without protocol β€” google.com β†’ https://google.com
πŸ”Œ Neovim Plugins
  • Works with Packer, Lazy.nvim, vim-plug
  • 'user/plugin' β†’ Opens GitHub repository
🎁 Optional Power Features

Enable these for even more power:

Feature What it does Enable with
NPM Imports import axios from "axios" β†’ npm enable_npm_imports = true
GitHub Permalinks Any line β†’ GitHub link with line number enable_github_file_line = true
Jira Tickets PROJ-123 β†’ Your Jira vim.g.gx_jira_url
Linear Issues ENG-456 β†’ Your Linear vim.g.gx_linear_team

πŸ“š See ADVANCED.md for complete optional features guide β†’


πŸ“¦ Installation

lazy.nvim (recommended)

{
  'rmagatti/gx-extended.nvim',
  keys = { 'gx' },
  config = function()
    require('gx-extended').setup {}
  end
}
use {
  'rmagatti/gx-extended.nvim',
  config = function()
    require('gx-extended').setup {}
  end
}
Plug 'rmagatti/gx-extended.nvim'

Then in your init.lua:

require('gx-extended').setup {}

βš™οΈ Configuration

Quick Start (Zero Config)

require('gx-extended').setup {}

That's it! All built-in features work out of the box.

Enable Optional Features

require('gx-extended').setup {
  -- Optional: NPM imports in JS/TS files
  enable_npm_imports = true,
  
  -- Optional: GitHub file line permalinks
  enable_github_file_line = true,
  
  -- Optional: Custom browser
  open_fn = require('lazy.util').open,
}

Add Custom Extensions

require('gx-extended').setup {
  extensions = {
    {
      patterns = { "*" },
      name = "Jira Tickets",
      match_to_url = function(line_string)
        local ticket = string.match(line_string, "([A-Z]+-[0-9]+)")
        if ticket then
          return "https://yourcompany.atlassian.net/browse/" .. ticket
        end
      end,
    },
  },
}

πŸ“š See full configuration guide β†’


🎯 Usage

Basic Usage

  1. Move cursor over a pattern (package name, URL, commit hash, etc.)
  2. Press gx in normal mode
  3. Opens in your browser!

Also works in visual mode β€” Select text and press gx

Multiple Matches

When multiple handlers match, you get a menu:

Multiple patterns matched. Select one:
> Docker Hub
  Git Commit
  No-protocol URLs

Use ↑↓ to select, Enter to open.


πŸ§ͺ Testing

We've made testing easy! Try it out:

cd ~/.local/share/nvim/lazy/gx-extended.nvim/test-samples
./test-runner.sh

Or manually test any feature:

nvim package.json
# Move cursor to "express" and press gx

πŸ“š See complete testing guide β†’


πŸ“š Documentation

Document What's inside
ADVANCED.md Optional features, custom extensions, power-user configs (600+ lines)
EXAMPLES.md Real-world examples for every feature (400+ lines)
TESTING.md Complete testing guide with test files (540+ lines)

🀝 Contributing

Contributions are welcome!

  • πŸ’‘ Have an idea? Open an issue
  • πŸ› Found a bug? Report it
  • πŸ”§ Want to add a feature? Submit a PR!

Adding a New Extension

See ADVANCED.md for examples of custom extensions. We're always open to adding more built-in handlers!


πŸŽ“ How It Works

Priority System

Extensions are checked in registration order:

  1. File-specific handlers (package.json, Cargo.toml, etc.)
  2. Markdown handlers
  3. Git handlers
  4. Reference handlers (CVE, PEP)
  5. Fallback handlers (no-protocol URLs)
  6. Your custom extensions

First match wins! If multiple match, you get a menu.

Deterministic Ordering ⭐

Key improvement: Extensions are checked in the exact order they're registered. No more random behavior!

This means:

  • Predictable β€” Same pattern always wins
  • Configurable β€” Control priority by registration order
  • Debuggable β€” Easy to understand what's happening

Example: File-specific handlers are registered first, so they always take priority over generic patterns.


πŸ“Š Stats

  • 19 total extensions (15 built-in + 4 optional)
  • 7 package managers supported
  • 3 git platforms (GitHub, GitLab, Bitbucket)
  • 20+ file types covered
  • 900+ lines of documentation
  • Zero dependencies (besides Neovim 0.5+)

πŸ™ Credits & Inspiration


πŸ“„ License

MIT License - see LICENSE for details


⭐ Show Your Support

If you find this plugin useful, please star it on GitHub!

⬆ Back to Top

About

Extending the use of Neovim's `gx`

Topics

Resources

License

Stars

Watchers

Forks

Contributors 5