From b9be6fba5a624c04878b9ff70b67a699e7710c6d Mon Sep 17 00:00:00 2001 From: "Kenneth Benzie (Benie)" Date: Sun, 17 Mar 2024 14:16:34 +0000 Subject: [PATCH] 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. --- lua/netrw.lua | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/lua/netrw.lua b/lua/netrw.lua index 8b8b243..5df5ffa 100644 --- a/lua/netrw.lua +++ b/lua/netrw.lua @@ -18,17 +18,8 @@ vim.keymap.set('n', '-', function() -- Invoke netrw on the directory containing the current file vim.fn.execute(string.format("edit %s", directory)) - if filename ~= '' then -- In the netrw buffer, move the cursor to the first character of filename - local buffer = vim.api.nvim_get_current_buf() - 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 + vim.fn.search('\\<' .. filename .. '\\>') end end)