0

I'm using a plugin called startscreen to customize my start screen. The problem is that whenever I enter vim the startscreen will be added to the oldfiles list. How can I avoid this. Is there any command to remove the current buffer or a certain buffer from the oldfiles?

For the startscreen buffer: echo &buftype gives nofile

EDIT:

It appears that the vim's oldfiles is different with the telescope plugin. As B Layer mentioned in the comments, telescope adds some buffers (whether from :buffer or the current buffer) to its oldfile built-in function.

I managed to fix this by defining a custom oldfile function, named old_files, which passes certain arguments to the built-in oldfile function.

local M = {}

function M.old_files()
  local fileopts = {}
  fileopts.file_ignore_patterns = {
    "splash.txt",
  }
  require("telescope.builtin").oldfiles(fileopts)
end

As argument, I simply told telescope to ignore a file name pattern when listing the oldfiles by passing fileopt object as argument to built-in oldfiles. From there, I can use this function in a binding.

neovim 0.5 -- linux

1 Answer 1

2

There's no way to really avoid the file getting in the list, AFAIK, but you can remove files after the fact.

:oldfiles is fed from the Vim variable v:oldfiles. This is just a standard Vim list so you can edit it.

Let's say the file you want to remove has file path/name /foo/bar/startscreen. Then do this...

:call filter(v:oldfiles, 'v:val !=# "/foo/bar/startscreen"')

The way filter works is it goes through each element of the list provided in the first param and does the test provided in the second param. If that evaluates to 0 (false) that element is removed from the list.

11
  • Sorry, I made a mistake in my question. I ran the command :oldfiles and the files I was talking about wasn't there at all. Strangely, the telescope plugin adds that file to its oldfiles. I thought telescope's oldfile is the same as the neovim's. So my problem is not actually this question. However, I think this question could be useful to someone. Regarding your answer, I tested it, and it appears that it does not remove the file. I gave it the absolute path to the file, but then I run :oldfiles the file is not removed. Not sure why this didn't work.
    – Ali
    Aug 9, 2021 at 15:56
  • Have you tested this on your machine? I know about the filter procedure and your command is very obvious and clean. However, not sure why this doesn't work on my machine.
    – Ali
    Aug 9, 2021 at 16:00
  • 1
    Telescope's oldfiles is made from Vim's oldfiles but it also adds file(s) from :buffers (possibly just the current buffer...I just looked at the code quickly).
    – B Layer
    Aug 9, 2021 at 16:50
  • 1
    If you can find an option named something like include_current_session that should allow you to control whether anything from :buffers is included. I don't know whether that's a user facing thing but it's definitely part of some configuration. Okay, that's my last unsolicited comment...I've spent too much time on this.
    – B Layer
    Aug 9, 2021 at 17:04
  • 1
    I appreciate your taking time and checking the plugin.
    – Ali
    Aug 9, 2021 at 19:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.