A personal Neovim plugin to highlight & open links that match my criteria of a valid link.
For a while now, I have been placing external URLs in any documentation I write
in the form of <https://...> as a stylistic choice, and as a mental reminder
that I can visit this page. This is a Neovim plugin that complements this choice
by highlighting and providing and open function for any links that contain valid
protocol prefixes (or scheme identifiers if you want to be pedantic) such as
http:// or https:// that are also surrounded in < >.
You probably don't need this plugin, but if you do end up using it I appreciate your feedback.
Call :lua require('nodus').open_link_under_cursor() manually or with a keybind
to open the link under your cursor with your preferred link opener. This
defaults to xdg-open, but it can be changed in the setup table.
In short, links that start with a valid protocol prefix (http://, https://,
etc.) that are also inside < > will match.
# This should match.
# <https://sample.com>
# This should not match.
# https://sample.com-- Call the setup function. Follow your own package manager's instructions
-- if you use something like Lazy for loading plugins.
require("nodus").setup(){
protocols = { "http://", "https://" }, -- default protocols to match, you can add your protocols here (e.g. "gemini://")
highlight_group = "NodusLinkHighlight", -- highlight group for matching links
ft = { "text", "md", "markdown" } -- file types for which matching will be enabled
}Tip
Nodus now uses vim.ui.open to use your system's file opener. You will be
able to open links as long as Neovim has access to your file opener. Hurray
for platform support!
Nodus attempts to highlight matching links to help you identify valid links that
can be opened. By default, it will use the highlights for the
NodusLinkHighlight group and underline any matching links. You can modify the
group name or the highlights as per your preferences.
-- Underline and red text.
vim.api.nvim_command("highlight NodusLinkHighlight gui=underline guifg=#ff0000")Nodus does not register any keybinds, and expects the user to do so by themselves. Below is an example of how you may choose to register your own keybind to open matching links under the cursor:
vim.api.nvim_set_keymap("n", "<leader>ol", ":lua require('nodus').open_link_under_cursor()<CR>", {
noremap = true, silent = true
})You can call open_link_under_cursor() function however you want to open the
link.
Always welcome.
This repository is licensed under the MIT license.