Is it possible to "preprocess" the oldfiles list so that it's easier to navigate visually?

As far as I can tell, the contents of the oldfiles list are presented as ordinary absolute paths, but with the user's home directory replaced with ~. This works well for most cases, but sometimes I'm navigating deep in a directory that's outside of my home directory and it's hard to read the file names.

For example, if I'm editing files in /tmp/some/deeply/nested/hierarchy and visit a bunch of files there, they show up as

1: /tmp/some/deeply/nested/hierarchy/h
2: /tmp/some/deeply/nested/hierarchy/g
3: /tmp/some/deeply/nested/hierarchy/f
4: /tmp/some/deeply/nested/hierarchy/e
5: /tmp/some/deeply/nested/hierarchy/d
6: /tmp/some/deeply/nested/hierarchy/c
7: /tmp/some/deeply/nested/hierarchy/b
8: /tmp/some/deeply/nested/hierarchy/a

Using a probably-way-longer-than-necessary perl script I can extract just the filename

perl -ne 'chomp; @w = split /\s+/; $b = ""; $w[-1] =~ m{/([^/]*)\z} and $b = $1; printf "%s %s %s\n", $w[0], $b, "@w[1..$#w]";'

When run against the contents of oldfiles list it produces the following:

1: h /tmp/some/deeply/nested/hierarchy/h
2: g /tmp/some/deeply/nested/hierarchy/g
3: f /tmp/some/deeply/nested/hierarchy/f
4: e /tmp/some/deeply/nested/hierarchy/e
5: d /tmp/some/deeply/nested/hierarchy/d
6: c /tmp/some/deeply/nested/hierarchy/c
7: b /tmp/some/deeply/nested/hierarchy/b
8: a /tmp/some/deeply/nested/hierarchy/a

Is there a way I can either use my script as a filter ... or define a filter in VimL to change how the oldfiles list is displayed?

Or, ideally, just change some format string somewhere that vim uses.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.