Replies: 5 comments 12 replies
-
You can add this functionality yourself. See This might get you started: local sort_by = function(nodes)
table.sort(nodes, function(a, b)
local a_num = string.match(a.name, "^[0-9]+")
local b_num = string.match(b.name, "^[0-9]+")
if a_num and b_num then
return a_num < b_num
else
-- we need to do something here
return false
end
end)
end |
Beta Was this translation helpful? Give feedback.
-
I'm not even a beginner in Lua, but I made this: local compare = function(left, right)
left = left.name:lower()
right = right.name:lower()
for i = 1, string.len(left), 1 do
local l = string.sub(left, i, -1)
local r = string.sub(right, i, -1)
if l == r then
return false
elseif type(tonumber(string.sub(l, 1, 1))) == "number" and type(tonumber(string.sub(r, 1, 1))) == "number" then
return tonumber(string.match(l, "^[0-9]+")) < tonumber(string.match(r, "^[0-9]+"))
elseif l[1] == r[1] then
goto continue
else
return l < r
end
::continue::
end
end
-- nvim-tree.lua
require("nvim-tree").setup({
sort_by = function(nodes)
table.sort(nodes, compare)
end,
})
It seems to work fine. If any one have any optimizations or fail points please tell me. References: https://github.com/lifthrasiir/rust-natord/blob/93e5f0ace208e73ddfaaa77ec1605584c8f22a14/lib.rs#L142 https://github.com/lifthrasiir/rust-natord/blob/93e5f0ace208e73ddfaaa77ec1605584c8f22a14/lib.rs#L37 |
Beta Was this translation helpful? Give feedback.
-
Hi. I have a problem. |
Beta Was this translation helpful? Give feedback.
-
I need help again. I'm trying to merge two recipes:
But if I try to add a sorting function to the list for cycling from second reciept, it doesn't work. Cycling is working, but natural sort doesn't. It just sorting by "name".
|
Beta Was this translation helpful? Give feedback.
-
Thanks!
|
Beta Was this translation helpful? Give feedback.
-
Is your feature request related to a problem? Please describe.
I'm always frustrated when I have a directory that has number-named files.
For example NvimTree will display them like that:
But the normal order I want them to be in is like:
It's the same default behavior of the
ls
GUN utility in Linux, but thels
has an option-v
to treat filename numerically. https://unix.stackexchange.com/questions/33909/list-files-sorted-numericallyMost times I need numbered files sorted with the numerically normal order so I can walk between them easily.
Describe the solution you'd like
Maybe adding a new type to the
sort_by
option to do that type of sorting.Describe alternatives you've considered
Maybe I just can create a function to do that since
sort_by
option support passing a function.Beta Was this translation helpful? Give feedback.
All reactions