telescope.nvim icon indicating copy to clipboard operation
telescope.nvim copied to clipboard

Improve oldfiles

Open kaiphat opened this issue 1 year ago • 4 comments

Is your feature request related to a problem? Please describe. When i open oldfiles i see image For example i want select second file and type d image But i lose my file in this case, because recently files sorting doesn't work

Describe the solution you'd like Show always 100 recently files for example sorted by last usage time. When i type in prompt, i FILTER this list and save previous order.

kaiphat avatar May 25 '23 07:05 kaiphat

latest master now can do

require("telescope.builtin").oldfiles {
  tiebreak = function(current_entry, existing_entry, _)
    return current_entry.index < existing_entry.index
  end
}

which should resolve your issue, we just need to integrate it better. better defaults and all, so i'd prefer if we keep that issue open

Conni2461 avatar May 25 '23 08:05 Conni2461

Yes, it works! Thank you! But it wasn't documented.

kaiphat avatar May 25 '23 09:05 kaiphat

tiebreak is documented (help telescope.tiebreak), the actual function is not, its more a configuration option.

i am currently thinking about doing a tiebreak abstraction where tiebreak can either be a custom function of a identifier to a already provided function, like index. so then people can do tiebreak = "index" to achieve that, and that will then be better documented.

but i havent decided anything yet so, until then i would like to keep that issue open :)

Conni2461 avatar May 25 '23 10:05 Conni2461

Nice! Just for documentation sake: I'm using this keybinding in my NvChad setup to find my most recently opened files in current working directory, ordered by most recent opened time, and also when filtering. That last part was so solved by @Conni2461's suggestion. Thanks :).

~/.nvchad/lua/custom/mappings.lua

telescope = {
  plugin = true,
  n = {
    ["<leader>fp"] = {
      function()
        require("telescope.builtin").oldfiles({
          cwd_only = true,
          tiebreak = function(current_entry, existing_entry, _)
            -- This ensures that when you are filtering, it's also sorted by last opened time.
            -- https://github.com/nvim-telescope/telescope.nvim/issues/2539#issuecomment-1562510095
            return current_entry.index < existing_entry.index
          end,
        })
      end,
      "Find recent files in CWD",
    },
  },
},

gitaarik avatar Dec 09 '23 17:12 gitaarik