A macOS URL handler for nvim:// URLs that intelligently opens files in
existing Neovim instances running in kitty terminal windows.
- Smart Instance Selection: Automatically finds the best Neovim instance to open files in, based on matching current working directories
- Fallback Strategy: If no matching Neovim instance exists, opens a new tab in an existing kitty terminal, or launches a new kitty instance as a last resort
- Line Number Support: Opens files at specific line numbers using the
nvim://file/path/to/file.txt:42syntax - URL Decoding: Properly handles URL-encoded paths
- Tilde Expansion: Supports
~for home directory paths
When you click a nvim:// link or open such a URL:
- The AppleScript handler receives the URL
- It extracts the file path and optional line number
- The bash script (
nvim_url.sh) analyzes all running kitty terminals and Neovim instances - It selects the best match based on:
- Neovim instances with matching working directories
- Kitty terminals with matching working directories
- Falls back to any existing kitty instance
- Creates a new kitty instance if none exist
- Opens the file at the specified line number and focuses the window
- Download the latest
.dmgfile from the Releases page - Open the DMG and drag
nvim_urlto your Applications folder - Right-click the app and select "Open" (required for first launch due to macOS Gatekeeper)
- The app will now handle all
nvim://URLs
-
Clone this repository:
git clone https://github.com/kelvinst/nvim_url.git cd nvim_url -
Build the app:
make install
-
Open a
nvim://URL to register the app as a handler:open 'nvim://file/~/.zshrc'
Once installed, you can open files in Neovim by clicking nvim:// URLs or
using them in other applications.
nvim://file/<path>:<line>
<path>: Absolute or relative file path (supports~for home directory)<line>: Optional line number to jump to
nvim://file/~/.zshrc
nvim://file/~/Developer/myproject/src/main.rs:42
nvim://file//Users/username/Documents/notes.md:10
You can test the handler from the command line:
open "nvim://file/~/.zshrc:1"- macOS 10.6 or later
- kitty terminal
- Neovim
jq(for JSON parsing) - install viabrew install jq
For the handler to connect to existing Neovim instances, you need to start Neovim listening to a socket:
nvim --listen /tmp/nvim-$(date +%s%N)Or configure your shell to always start Neovim with a listener. Add to your
.zshrc or .bashrc:
alias nvim='nvim --listen /tmp/nvim-$(date +%s%N)'The handler writes logs to /tmp/nvim_url.log. Check this file if URLs aren't
working as expected:
tail -f /tmp/nvim_url.logOn first run, macOS may ask for permissions to control other applications. This is required for the handler to focus kitty windows and communicate with Neovim.
If clicking nvim:// URLs doesn't work:
- Make sure the app is in your
/Applicationsfolder - Open the app manually once to register it as a URL handler
- Restart your browser or application
.
├── Contents/
│ ├── Info.plist # App metadata and URL scheme registration
│ ├── MacOS/
│ │ └── applet # AppleScript executable
│ ├── Resources/
│ │ ├── Scripts/
│ │ │ └── main.scpt # AppleScript URL handler
│ │ └── nvim_url.sh # Bash script for routing logic
│ └── _CodeSignature/
├── build.sh # Build script
├── package-dmg.sh # DMG packaging script
└── README.md
Run the build script to compile the app:
make buildTo create a distributable DMG:
make dmgTo create and publish a new release:
-
Update the version in
Contents/Info.plist:<!-- Edit CFBundleShortVersionString --> <key>CFBundleShortVersionString</key> <string>X.Y.Z</string>
-
Update the version in
Makefile:# Update the VERSION variable VERSION := X.Y.Z
-
Commit the version change:
git add . git commit -m "chore: bump version to X.Y.Z" git push origin main
-
Create and push a tag:
git tag vX.Y.Z git push origin main --tags
-
Build the DMG:
make dmg
-
Create a GitHub release in GitHub with the following format:
## [X.Y.Z] - YYYY-MM-DD <!-- Some short description of the release --> ### Changelog <!-- The commits you generated in the previous step --> **Full Changelog**: https://github.com/kelvinst/nvim_url/compare/vA.B.C...vX.Y.Z
P.S.: You can generate the Full Changelog using the
Generate release notesbutton on GitHub, you just have to select the current and previous tags. -
Upload the DMG from
dist/nvim_url-X.Y.Z.dmgto the release -
Publish the release
MIT License - See LICENSE file for details
Contributions are welcome! Please feel free to submit a Pull Request.
Thanks @nickgnd for heavily inspiring this project with his blog post doing the same for TMUX and Allactritty.