Welcome to Vifm Q&A, where you can ask questions about Vifm usage. Registration is optional, anonymous posts are moderated. GitHub or Google logins are enabled.
0 votes
in vifm by

Hi friends,

I have something like this in my vifmrc:

...
" Auto commands
autocmd DirEnter ~/Downloads setlocal sort=-ctime
.
.
.

" Remove ../ from column unless there's nothing else to show
set dotdirs=
...

My trouble is that when I access ~/Downloads (and other directories with non-default sorting enabled) the file selected is one that ought to be selected if I had sorting by name (or whichever global sorting is set by pressing s key). I would prefer to have the file at the top of the column selected (in this case that would be the file with newest metadata). I am aware that simple gg would help, but I'd like to fix this so that vifm complies to sorting preference.

To make it clear:
(1) I would like to have vifm select the topmost file in the directory even when non-default sorting is enabled.
(2) When I leave such a directory with some other file selected, I would like to return to that file when I re-enter this directory again.

It seems to me that vifm selects ../ by default, but since I have disabled it - it selects first file according to global sorting settings, as a fallback.

Any help would be appreciated, but an en elegant solution which would make me achieve the desired behaviour without adding settings per directory would be greatly appreciated.

Further reading:
https://q2a.vifm.info/469/can-i-specify-sorting-per-directory
https://q2a.vifm.info/17/screen-real-estate-minimizing-the-waste?show=19#a19

Thank you for your time.

1 Answer

0 votes
by

Hello,

since what you describe happens because file list is loaded with global sorting and is then resorted on entering a directory, solving this would require knowing whether the directory is visited for the first time. And there is no way of querying that.

../ happens to help because it's always the first element when present, so it acts as an anchor for the cursor keeping it at the top. When it's gone, the first element can change its position, which is what you observe.

You want an elegant solution, but I don't see any solution that would work. There is simply no way of knowing if gg should be done (well, unless you'll keep track of it by some external means).

I'm not sure why this would bother you if number of directories is known beforehand. The wrong cursor position should be set only the first time you visit them and be preserved on future runs of Vifm.

by

First of all, I want to express sincere gratitude to you for writing this great program.

People who are not programmers (like myself) have a hard time when judging whether something is simple or even possible, regarding software engineering. It seemed to me simple enough that when accessing some directory for the first time vifm tries to move cursor to ../ and since I've decided to disable it, it will select the file beneath it and once this is done mark this file as one beneath cursor for the purpose of remembering cursor position when leaving and returning to the directory.

As for your explanation, well now that I've just read your answer the issue here doesn't look that bad. It seems to me that workaround for this is really complex and is not worth it. To put it bluntly, you are right - it shouldn't bother me. I simply wanted to know if I can do something about this minor inconsistency.

Finally, I'd like to bring to your attention that contact mail on this site (xaizek@openmailbox.org) doesn't work anymore (I used to be openmailbox.org user myself).

Once again, thank you for your time and satisfying answer. I wish you well.

by

There might be a way to make this work in the future. I don't really like that file list is sorted twice. With a different mechanism of customizing settings per directories the issue should be gone. Access to history might also be provided some day, although it's trickier in this scenario and would be a less clean solution.

Finally, I'd like to bring to your attention that contact mail on this site (xaizek@openmailbox.org) doesn't work anymore (I used to be openmailbox.org user myself).

Thanks, forgot to update this place.

...