Initial commit

main
Micke Nordin 2 weeks ago
parent b9dd99f811
commit 9fa41a423f

@ -1,3 +1,28 @@
# url.nvim
A smol neovim plugin to open a url you are standing on in your browser
A smol neovim plugin to open the url under the cursor, in your browser.
## Installation
With Lazy:
```lua
{ "https://code.smolnet.org/micke/url.nvim" }
```
## Usage
```
:UrlOpen
```
## Keybindings
Add a keybinding:
```
nnoremap <leader>u :UrlOpen<CR>
```
or with lua
```lua
vim.api.nvim_set_keymap("n", "<leader>u", "<cmd>UrlOpen<CR>", {})
```
or using which-key.nvim
```lua
require("which-key").add({
{"<leader>u", "<CMD>UrlOpen<CR>", desc = "Open URL"}
}
```

@ -0,0 +1,24 @@
local get_url = function()
local line = vim.api.nvim_get_current_line()
local window = vim.api.nvim_get_current_win()
local _,col = unpack(vim.api.nvim_win_get_cursor(window))
local urls = line:gmatch("%w+://[%w_%.%-]+[%w_.@~%-%/%?&#=]*")
for url in urls do
if col >= string.find(line, url) and col <= string.find(line, url) + #url then
return url
end
end
end
local M = {}
M.open_url = function()
local url = get_url()
if url then vim.ui.open(url) end
end
return M

@ -0,0 +1,13 @@
local callback = function()
local url = require('.url')
url.open_url()
end
vim.api.nvim_create_user_command(
"UrlOpen",
callback,
{
nargs = 0,
desc = "Open a URL in the default browser",
}
)
Loading…
Cancel
Save