Simplify netrw code that moves cursor to filename
This commit is contained in:
parent
2d22ea836f
commit
68d50081ff
@ -14,22 +14,14 @@ 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", vim.fn.expand('%:hp')))
|
vim.fn.execute(string.format("edit %s", vim.fn.expand('%:hp')))
|
||||||
|
|
||||||
-- Move the cursor to the line matching file
|
-- In the netrw buffer, move the cursor to the first character of filename
|
||||||
local netrw_liststyle = vim.api.nvim_buf_get_var(
|
local buffer = vim.api.nvim_get_current_buf()
|
||||||
vim.api.nvim_get_current_buf(), 'netrw_liststyle')
|
local lines = vim.api.nvim_buf_get_lines(buffer, 0, -1, true)
|
||||||
local pattern = nil
|
for row, content in ipairs(lines) do
|
||||||
-- TODO: Replace this with something simpler, perhaps a loop over the netrw
|
local column = string.find(content, filename)
|
||||||
-- buffer lines to get the line number containing the filename string.
|
if column then
|
||||||
if netrw_liststyle and netrw_liststyle == 2 then
|
vim.api.nvim_win_set_cursor(0, { row, column - 1 })
|
||||||
-- tpope's magic pattern for list style with multiple files in columns
|
break
|
||||||
pattern = '\\%(^\\|\\s\\+\\)\zs'
|
end
|
||||||
.. vim.fn.escape(filename .. '.*[]~\\')
|
|
||||||
.. '[/*|@=]\\=\\%($\\|\\s\\+\\)'
|
|
||||||
else
|
|
||||||
-- tpope's magic pattern for all other list styles
|
|
||||||
pattern = '^\\%(| \\)*'
|
|
||||||
.. vim.fn.escape(filename, '.*[]~\\')
|
|
||||||
.. '[/*|@=]\\=\\%($\\|\\t\\)'
|
|
||||||
end
|
end
|
||||||
vim.fn.search(pattern, 'wc')
|
|
||||||
end)
|
end)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user