Skip to content

mjacobs/mru-nav.nvim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mru-nav.nvim

A small Neovim plugin for quick MRU navigation:

  • MRU file history nav: shows previously edited files in MRU order, including across restarts
  • MRU buffer nav: shows open buffers in MRU order for the current session
  • Works with vim.ui.select() out of the box
  • Uses Telescope automatically when installed, unless disabled
  • Friendly lazy.nvim setup

Features

  • :MruFile opens a picker for persisted MRU file history
  • :MruBuffer opens a picker for currently open buffers in MRU order
  • command-line aliases so :mruFile and :mruBuffer also work
  • default keymaps for quick access
  • persisted file history stored under Neovim's state directory

Requirements

  • Neovim >= 0.9
  • Optional: Telescope for a nicer picker UI

Installation (lazy.nvim)

{
  "mjacobs/mru-nav.nvim",
  cmd = { "MruFile", "MruBuffer", "MruClearFiles" },
  keys = {
    { "<leader>mf", function() require("mru_nav").mru_files() end, desc = "MRU file picker" },
    { "<leader>mb", function() require("mru_nav").mru_buffers() end, desc = "MRU buffer picker" },
  },
  opts = {
    keymaps = {
      files = "<leader>mf",
      buffers = "<leader>mb",
    },
  },
  config = function(_, opts)
    require("mru_nav").setup(opts)
  end,
}

Commands

  • :MruFile — pick a file from persisted MRU history
  • :MruBuffer — pick an open buffer from current-session MRU order
  • :MruClearFiles — clear persisted file history

Because Neovim user commands should start with an uppercase letter, the plugin defines :MruFile and :MruBuffer as the real commands. It also adds command-line abbreviations so typing :mruFile and :mruBuffer still works.

Default keymaps

  • <leader>mf — MRU files
  • <leader>mb — MRU buffers

Set either value to false or "" to skip creating that keymap.

Configuration

require("mru_nav").setup({
  max_files = 200,
  max_buffers = 100,
  persist = true,
  history_file = nil, -- defaults to stdpath("state") .. "/mru-nav.json"
  use_telescope_if_available = true,
  file_picker_title = "MRU Files",
  buffer_picker_title = "MRU Buffers",
  keymaps = {
    files = "<leader>mf",
    buffers = "<leader>mb",
  },
})

Options

Option Default Meaning
max_files 200 Max number of persisted files to keep
max_buffers 100 Max number of in-memory MRU buffers to keep
persist true Whether file MRU history is saved across restarts
history_file stdpath("state") .. "/mru-nav.json" Storage path for file history
use_telescope_if_available true Prefer Telescope over vim.ui.select() when available
file_picker_title "MRU Files" Prompt title for file picker
buffer_picker_title "MRU Buffers" Prompt title for buffer picker
keymaps.files "<leader>mf" Normal-mode keymap for files
keymaps.buffers "<leader>mb" Normal-mode keymap for buffers

Persistence details

Persisted file history is stored in JSON at:

vim.fs.joinpath(vim.fn.stdpath("state"), "mru-nav.json")

The plugin writes updates atomically using a temp file + rename, and prunes missing files when opening the file picker or exiting Neovim.

Notes

  • File history is cross-session
  • Buffer history is session-local by design
  • Special buffers such as help, quickfix, terminal, and other non-file buffers are excluded from file history
  • Buffer picker includes listed buffers, even if they do not yet have a file on disk

Minimal manual smoke test

  1. Open a few files in sequence
  2. Run :MruFile
  3. Confirm they appear newest-first
  4. Restart Neovim
  5. Run :MruFile again and confirm the order persisted
  6. Run :MruBuffer and confirm open buffers are shown newest-first

Repo structure

mru-nav.nvim/
├── lua/mru_nav/init.lua
├── plugin/mru_nav.lua
├── tests/minimal_init.lua
├── tests/smoke.lua
└── README.md

About

Neovim plugin for quick MRU navigation

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages