[mini.files] custom side-scrolling layout #2173
Replies: 3 comments 15 replies
-
|
Thanks for sharing. As I said earlier, this looks awesome. And if I'd thought about this during 'mini.files' creation, this might have been the default look. I'll copy my relevant Reddit comment:
|
Beta Was this translation helpful? Give feedback.
-
|
Finally got around to try this, and loving it. I am hitting one error though: This seems to happen specifically when I'm on a smaller window such as here. if I'm full screen it doesn't happen |
Beta Was this translation helpful? Give feedback.
-
|
Here is my rendition based on the above comments, fixes a few bugs with empty folders which would cause some errors: -- stylua: ignore
vim.api.nvim_create_autocmd("User", { pattern = "MiniFilesWindowUpdate", callback = function(ev)
local widths = { 60, 20, 20, 10, 5 } -- center layout https://github.com/nvim-mini/mini.nvim/discussions/2173
local state = require("mini.files").get_explorer_state()
if not state or #state.branch == 0 then return end
local ok, r = pcall(require("mini.files").get_explorer_state)
if ok then state = r end
if not state then vim.wait(50, function()
local ok2, r2 = pcall(require("mini.files").get_explorer_state)
if ok2 then state = r2 return true end return false end, 10, false) end
local path_this = vim.api.nvim_buf_get_name(ev.data.buf_id):match("^minifiles://%d+/(.*)$")
local depth_this = 0
for i, path in ipairs(state.branch) do if path == path_this then depth_this = i break end end
if depth_this == 0 then return end
local depth_offset = depth_this - state.depth_focus
local i = math.abs(depth_offset) + 1
local win_config = vim.api.nvim_win_get_config(ev.data.win_id)
win_config.width = i <= #widths and widths[i] or widths[#widths]
win_config.zindex = 99
win_config.col = math.floor(0.5 * (vim.o.columns - widths[1]))
local sign = depth_offset == 0 and 0 or (depth_offset > 0 and 1 or -1)
for j = 1, math.abs(depth_offset) do
local prev_win_width = (sign == -1 and widths[j + 1]) or widths[j] or widths[#widths]
local new_col = win_config.col + sign * (prev_win_width + 2)
if new_col < 0 or new_col + win_config.width > vim.o.columns then
win_config.zindex = win_config.zindex - 1 break end win_config.col = new_col end
win_config.height = depth_offset == 0 and 44 or 40
win_config.row = math.floor(0.5 * (vim.o.lines - win_config.height))
win_config.footer = { { tostring(depth_offset), "Normal" } }
vim.api.nvim_win_set_config(ev.data.win_id, win_config) end }) |
Beta Was this translation helpful? Give feedback.

Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Following up on my reddit post https://www.reddit.com/r/neovim/comments/1pm2m6i/cool_minifiles_sidescrolling_layout/
I wanted to edit the mini.files window in the center of the screen, but I also wanted to retain the extra Miller-column windows. With the help of @echasnovski I improved my original version and landed on this:
minifiles_demo.mp4
If you want the same thing, use the code below :) (or share something you come up with cause I'd love to see that as well...)
For anyone that wants to play around with it and create their own layout, the above is pretty simple, imagine we have a window arrangement like this -
The number in the middle is the
depth_offsetfor each window (each window triggers its own'MiniFilesWindowUpdate'event). TheOin the topleft of the central window is the origin that every window begins at (see the line withwin_config.col = math.floor(0.5 * (vim.o.columns - widths[1]))). The*'s in the upper left are the default 'NW' anchor of each window, so imagining that all anchors are initially stacked on pointO, the goal is to offset each window'swin_config.colbased on theirdepth_offset. For windows to the right, you can see their anchors need to be shifted right by the previous window's width (plus all other windows to the origin), and for windows to the left, they need to be shifted left by their own width (plus all other windows to the origin).Hope that helps someone
Beta Was this translation helpful? Give feedback.
All reactions