Skip to content

Commit 998ade9

Browse files
committed
feat(nvim): add yL keymap to yank file path with line number
1 parent 7f4e800 commit 998ade9

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

plugin/keymaps/normal.lua

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,20 @@ end
190190

191191
k("y%", yank_current_path, { desc = "Yank filename (relative)" })
192192

193+
local function yank_current_path_and_line()
194+
local path = vim.fn.expand("%:.")
195+
if path == "" then
196+
vim.notify("No file name", vim.log.levels.WARN)
197+
return
198+
end
199+
local line = vim.fn.line(".")
200+
local result = ("%s:%d"):format(path, line)
201+
vim.fn.setreg("+", result)
202+
vim.notify(("Yanked %s"):format(result), vim.log.levels.INFO)
203+
end
204+
205+
k("yL", yank_current_path_and_line, { desc = "Yank filename + line" })
206+
193207
--
194208
-- }}}
195209

readme.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,11 @@ Random features added.
305305
- `%n` basename
306306
- `%p` path (absolute)
307307

308+
Custom keymaps (normal mode):
309+
310+
- `y%` path (relative)
311+
- `yL` path (relative) + line number
312+
308313
### Operators
309314

310315
- `ys{motion}{char}` add surrounding character

0 commit comments

Comments
 (0)