Skip to content

Instantly share code, notes, and snippets.

@appblue
Created October 13, 2025 07:39
Show Gist options
  • Select an option

  • Save appblue/11be219e961da8e7fa67b2d07bbb2df7 to your computer and use it in GitHub Desktop.

Select an option

Save appblue/11be219e961da8e7fa67b2d07bbb2df7 to your computer and use it in GitHub Desktop.
List old Nvim Files
#!/bin/bash
# Script to list recent files and open nvim using fzf
# set to an alias nlof in .zshrc
list_oldfiles() {
# Get the oldfiles list from Neovim
local oldfiles=($(nvim -u NONE --headless +'lua io.write(table.concat(vim.v.oldfiles, "\n") .. "\n")' +qa))
# Filter invalid paths or files not found
local valid_files=()
for file in "${oldfiles[@]}"; do
if [[ -f "$file" ]]; then
valid_files+=("$file")
fi
done
# Use fzf to select from valid files
local files=($(printf "%s\n" "${valid_files[@]}" |
grep -v '\[.*' |
fzf --multi \
--preview 'bat -n --color=always --line-range=:500 {} 2>/dev/null || echo "Error previewing file"' \
--height=70% \
--layout=default))
# Open selected files in Neovim
[[ ${#files[@]} -gt 0 ]] && nvim "${files[@]}"
}
# Call the function
list_oldfiles "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment