1- *nvim-various-textobjs.txt* For Neovim Last change: 2025 April 20
1+ *nvim-various-textobjs.txt* For Neovim Last change: 2025 April 21
22
33==============================================================================
44Table of Contents *nvim-various-textobjs-table-of-contents*
@@ -32,7 +32,7 @@ TABLE OF CONTENTS*nvim-various-textobjs-nvim-various-textobjs--table-of-contents
3232 - | nvim-various-textobjs-go-to-next-occurrence-of-a-text-object |
3333 - | nvim-various-textobjs-dynamically-switch-text-object-settings |
3434 - | nvim-various-textobjs-`ii`-on-unindented-line-should-select-entire-buffer |
35- - | nvim-various-textobjs-smarter-`gx` |
35+ - | nvim-various-textobjs-smarter-`gx`-&-`gf` |
3636 - | nvim-various-textobjs-delete-surrounding-indentation |
3737 - | nvim-various-textobjs-yank-surrounding-indentation |
3838 - | nvim-various-textobjs-indent-last-paste |
@@ -135,10 +135,14 @@ LIST OF TEXT OBJECTS*nvim-various-textobjs-nvim-various-textobjs--list-of-text-o
135135 emoji single emoji (or Nerdfont - small .
136136 glyph)
137137
138- argument comma-separated argument (not includes one . (or :) small i,/a,
138+ argument comma-separated argument (not outer includes the , small i,/a,
139139 as accurate as the
140140 treesitter-textobjects, use as
141141 fallback)
142+
143+ filepath unix-filepath; supports ~ or inner is only the big iF/aF
144+ $HOME, but not spaces in the filename
145+ filepath.
142146 -----------------------------------------------------------------------------------------------------------
143147
144148 [!TIP] For some text objects, you can also use `caW` or `cl ` if your cursor is
@@ -427,7 +431,7 @@ behavior:
427431<
428432
429433
430- SMARTER GX ~
434+ SMARTER GX & GF ~
431435
432436The code below retrieves the next URL (within the amount of lines configured in
433437the `setup` call), and opens it in your browser. As opposed to vim’s built-in
@@ -436,22 +440,39 @@ on the URL.
436440
437441>lua
438442 vim.keymap.set("n", "gx", function()
439- -- select URL
440- require("various-textobjs").url()
443+ require("various-textobjs").url() -- select URL
441444
442- -- plugin only switches to visual mode when textobj is found
443- local foundURL = vim.fn.mode() == "v"
445+ local foundURL = vim.fn.mode() == "v" -- only switches to visual mode when textobj found
444446 if not foundURL then return end
445447
446- -- retrieve URL with the z-register as intermediary
447- vim.cmd.normal { '"zy', bang = true }
448- local url = vim.fn.getreg("z")
448+ local url = vim.fn.getregion(vim.fn.getpos("."), vim.fn.getpos("v"), { type = "v" })[1]
449449 vim.ui.open(url) -- requires nvim 0.10
450+ vim.cmd.normal { "v", bang = true } -- leave visual mode
451+ end, { desc = "URL Opener" })
452+ <
453+
454+ Similarly, we can also create a forward-looking version of `gf`
455+
456+ >lua
457+ vim.keymap.set("n", "gf", function()
458+ require("various-textobjs").filepath() -- select filepath
459+
460+ local foundPath = vim.fn.mode() == "v" -- only switches to visual mode when textobj found
461+ if not foundPath then return end
462+
463+ local path = vim.fn.getregion(vim.fn.getpos("."), vim.fn.getpos("v"), { type = "v" })[1]
464+
465+ local exists = vim.uv.fs_stat(vim.fs.normalize(path)) ~= nil
466+ if exists then
467+ vim.ui.open(path)
468+ else
469+ vim.notify("Path does not exist.", vim.log.levels.WARN)
470+ end
450471 end, { desc = "URL Opener" })
451472<
452473
453474
454- DELETE SURROUNDING INDENTATION ~
475+ DELETESURROUNDING INDENTATION ~
455476
456477Using the indentation text object, you can also create custom
457478indentation-related utilities. A common operation is to remove the line before
0 commit comments