Skip to content

Commit 7503d84

Browse files
committed
docs: improve gx example to not use register
1 parent dcf0cd9 commit 7503d84

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

README.md

+4-7
Original file line numberDiff line numberDiff line change
@@ -309,17 +309,14 @@ the URL.
309309

310310
```lua
311311
vim.keymap.set("n", "gx", function()
312-
-- select URL
313-
require("various-textobjs").url()
312+
require("various-textobjs").url() -- select URL
314313

315-
-- plugin only switches to visual mode when textobj is found
316-
local foundURL = vim.fn.mode() == "v"
314+
local foundURL = vim.fn.mode() == "v" -- only switches to visual mode when textobj found
317315
if not foundURL then return end
318316

319-
-- retrieve URL with the z-register as intermediary
320-
vim.cmd.normal { '"zy', bang = true }
321-
local url = vim.fn.getreg("z")
317+
local url = vim.fn.getregion(vim.fn.getpos("."), vim.fn.getpos("v"), { type = "v" })[1]
322318
vim.ui.open(url) -- requires nvim 0.10
319+
vim.cmd.normal { "v", bang = true } -- leave visual mode
323320
end, { desc = "URL Opener" })
324321
```
325322

0 commit comments

Comments
 (0)