Fix - mapping sometimes landing on wrong filename
Instead of using Lua to search through all buffer lines and match the file line containing the filename, instead use `search()` and wrap the filename in word boundry delimiters `\<\>` to always match the whole filename not a subscript. This also moves the cursor to that position in the file.
This commit is contained in:
parent
c235fb88e1
commit
b9be6fba5a
@ -18,17 +18,8 @@ vim.keymap.set('n', '-', function()
|
|||||||
|
|
||||||
-- Invoke netrw on the directory containing the current file
|
-- Invoke netrw on the directory containing the current file
|
||||||
vim.fn.execute(string.format("edit %s", directory))
|
vim.fn.execute(string.format("edit %s", directory))
|
||||||
|
|
||||||
if filename ~= '' then
|
if filename ~= '' then
|
||||||
-- In the netrw buffer, move the cursor to the first character of filename
|
-- In the netrw buffer, move the cursor to the first character of filename
|
||||||
local buffer = vim.api.nvim_get_current_buf()
|
vim.fn.search('\\<' .. filename .. '\\>')
|
||||||
local lines = vim.api.nvim_buf_get_lines(buffer, 0, -1, true)
|
|
||||||
for row, content in ipairs(lines) do
|
|
||||||
local column = string.find(content, filename)
|
|
||||||
if column then
|
|
||||||
vim.api.nvim_win_set_cursor(0, { row, column - 1 })
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user