local orig = {} local function parse(line) local prefix, name = line:match('^([| ]*)(.-)%s*$') local _, depth = prefix:gsub('|', '') return depth, name end local function open_entry() local buf = vim.api.nvim_get_current_buf() local lnum = vim.fn.line('.') local depth, name = parse(vim.fn.getline(lnum)) local function fallback() local rhs = orig[buf] and orig[buf].rhs if rhs and rhs ~= '' then vim.api.nvim_feedkeys(vim.keycode(rhs), 'n', false) end end if name == '' or name:sub(-1) == '/' or depth == 0 then return fallback() end local parts, cur, top = {}, depth, nil for l = lnum - 1, 1, -1 do local d, n = parse(vim.fn.getline(l)) if n ~= '' and d < cur and n:sub(-1) == '/' then if d == 0 then top = n break end table.insert(parts, 1, n) cur = d end end if not top or not top:match('^%a+://') then return fallback() end vim.cmd('edit ' .. vim.fn.fnameescape(top .. table.concat(parts) .. name)) end local function install(buf) local m = vim.fn.maparg('', 'n', false, true) if m.callback then return end orig[buf] = m vim.keymap.set('n', '', open_entry, { buffer = buf, silent = true }) end vim.api.nvim_create_autocmd({ 'BufEnter', 'CursorMoved' }, { callback = function(a) if vim.bo[a.buf].filetype == 'netrw' and vim.g.netrw_liststyle == 3 then install(a.buf) end end, })