Skip to content

shadowfax92/recent-files

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

📂 recent-files

Cross-session recent file tracker for Neovim.

Every file you open, remembered across all sessions.

Neovim's built-in oldfiles (shada) breaks when multiple sessions run concurrently — the last session to exit overwrites everyone else's history. recent-files fixes this with a simple append-only log that survives any number of parallel sessions.

  • 🔄 Cross-session — files opened in any nvim session are tracked globally
  • Fast — Go binary, 3ms to list, non-blocking writes from nvim
  • 🔍 Fuzzy pick<leader>fr opens fzf-lua with file preview
  • 📅 90-day window — configurable, auto-filters stale entries
  • 🛡️ Graceful fallback — if the binary isn't installed, nvim falls back to Snacks.picker.recent()

🚀 Install

Requires Go 1.22+.

git clone <repo>
cd recent-files
make install

Installs to $(go env GOPATH)/bin/recent-files.

⚙️ Neovim Setup

Two pieces in your nvim config:

1. Autocmd — track file opens

In lua/config/autocmds.lua:

if vim.fn.executable("recent-files") == 1 then
  vim.api.nvim_create_autocmd("BufReadPost", {
    callback = function()
      local path = vim.api.nvim_buf_get_name(0)
      if path ~= "" and vim.fn.filereadable(path) == 1 then
        vim.system({ "recent-files", "add", path }, { detach = true })
      end
    end,
  })
end

2. Keymap — fuzzy pick recent files

In lua/config/keymaps.lua:

vim.keymap.set("n", "<leader>fr", function()
  if vim.fn.executable("recent-files") == 1 then
    require("fzf-lua").fzf_exec("recent-files list --days 90", {
      prompt = "Recent Files> ",
      previewer = "builtin",
      actions = require("fzf-lua").defaults.actions.files,
    })
  else
    vim.notify("recent-files not found, falling back to oldfiles", vim.log.levels.WARN)
    Snacks.picker.recent()
  end
end, { desc = "Recent files (all dirs, cross-session)" })

📖 Commands

Core

recent-files add <filepath>       # track a file open (called by nvim autocmd)
recent-files list                 # list recent files, most recent first
recent-files list --days 30       # last 30 days only
recent-files                      # bare command = list

Maintenance

recent-files compact              # deduplicate & prune old entries
recent-files compact --days 60    # keep only last 60 days
recent-files stats                # show log size, unique files, data path

🗂️ How It Works

nvim BufReadPost
    ↓
recent-files add /path/to/file    (append-only, non-blocking)
    ↓
~/.local/share/recent-files/history.tsv
    ↓
<leader>fr → fzf-lua with preview

The history file is a simple TSV: unix_timestamp\tfilepath. One line per open event. The list command deduplicates by path, keeps the most recent timestamp, filters by date, and sorts by recency.

Multiple nvim sessions append concurrently without conflict — no locking needed since each write is a single line append.

🧹 Maintenance

The log grows by ~1 line per file open. Run compact periodically to deduplicate:

recent-files stats     # check size
recent-files compact   # prune to unique entries within 90 days

📊 Stats Example

Log entries:  1247
Unique files: 312
File size:    48.2 KB
Data file:    ~/.local/share/recent-files/history.tsv

🛠️ Built to scratch my own itch — nvim oldfiles kept losing files across tmux sessions.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors