summaryrefslogtreecommitdiffstats
path: root/nvim/after/plugin/netrw_tree_fix.lua
diff options
context:
space:
mode:
authorcoast <coasteen@proton.me>2026-10-15 04:35:38 +0330
committercoast <coasteen@proton.me>2026-10-15 04:35:38 +0330
commit57331238c20775916068580aff7d46968c45d575 (patch)
tree7450c990e796de8402f648a6cf1f3423e0469fca /nvim/after/plugin/netrw_tree_fix.lua
parent8c5c2d270fd0f3bbc276e3b1cc28fc1dfae3fa59 (diff)
downloadcoast-newdot-master.tar.gz
coast-newdot-master.tar.bz2
coast-newdot-master.tar.xz
coast-newdot-master.tar.zst
new nvim changesHEADmaster
Diffstat (limited to 'nvim/after/plugin/netrw_tree_fix.lua')
-rw-r--r--nvim/after/plugin/netrw_tree_fix.lua58
1 files changed, 58 insertions, 0 deletions
diff --git a/nvim/after/plugin/netrw_tree_fix.lua b/nvim/after/plugin/netrw_tree_fix.lua
new file mode 100644
index 0000000..af2030e
--- /dev/null
+++ b/nvim/after/plugin/netrw_tree_fix.lua
@@ -0,0 +1,58 @@
+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('<CR>', 'n', false, true)
+ if m.callback then return end
+ orig[buf] = m
+ vim.keymap.set('n', '<CR>', 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,
+})