diff options
| author | coast <coasteen@proton.me> | 2026-10-15 04:35:51 +0330 |
|---|---|---|
| committer | coast <coasteen@proton.me> | 2026-10-15 04:35:51 +0330 |
| commit | 4c20a256c370a65ecd34100a540ad9760e67f51d (patch) | |
| tree | b855be16d3b5cf7d1de15ae93f6a163e75194683 /home-configuration/config/nvim/after/plugin | |
| parent | 30ffc7cf394a9503771ea32b0a9e1fe41b155198 (diff) | |
| download | nix-4c20a256c370a65ecd34100a540ad9760e67f51d.tar.gz nix-4c20a256c370a65ecd34100a540ad9760e67f51d.tar.bz2 nix-4c20a256c370a65ecd34100a540ad9760e67f51d.tar.xz nix-4c20a256c370a65ecd34100a540ad9760e67f51d.tar.zst | |
new nvim changes
Diffstat (limited to 'home-configuration/config/nvim/after/plugin')
| -rw-r--r-- | home-configuration/config/nvim/after/plugin/netrw_tree_fix.lua | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/home-configuration/config/nvim/after/plugin/netrw_tree_fix.lua b/home-configuration/config/nvim/after/plugin/netrw_tree_fix.lua new file mode 100644 index 0000000..af2030e --- /dev/null +++ b/home-configuration/config/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, +}) |
