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

I would like, by default, to sort in ascending order when sorting by name but descending when sorting by size and mtime (I've never ever wanted to find the smallest or oldest file, only the biggest and newest). Can this be set separately for each sort method?

1 Answer

0 votes
by

You can specify sorting order in 'sort' option with + or -. In sorting dialog you can press h to toggle ordering.

by

Yes, but that only affects the initial sorting, right? What I'm after is a setting by which I wouldn't have to change the order every time.
To be more concrete: I mainly/only use three different sort orders:
- iname, ascending
- mtime, descending
- size, also descending.
If I switch from name to time, I will have to change the order every time, would I not?

by

Yes, correct. Maybe you want a command to toggle sorting instead. Based on this question:

" toggle between sorting: by name <--> by size <--> by mtime
command! togglesort
         \ :if &sort == '-size,+name'
         \ |    set sort=-mtime
         \ |    echo 'Sorted by modification date'
         \ |elseif &sort == '+name'
         \ |    set sort=-size
         \ |    echo 'Sorted by size'
         \ |else
         \ |    set sort=+name
         \ |    echo 'Sorted by name'
         \ |endif
nnoremap <silent> ,S :togglesort<cr>

Or you could have several mappings for each sorting that you want to use, the examples of set sort are above.

by

thank you, this helped me to get the default behaviour of mc. i now have three separate shortcuts configured and every other shortcut activation toggles the order.

command! sortnametoggle
         \ :if &sort == '-name'
         \ |    set sort=+name
         \ |    echo 'Sorted by name (A-Z)'
         \ |elseif &sort == '+name'
         \ |    set sort=-name
         \ |    echo 'Sorted by name (Z-A)'
         \ |else
         \ |    set sort=+name
         \ |    echo 'Sorted by name (A-Z)'
         \ |endif

command! sortsizetoggle
         \ :if &sort == '-size'
         \ |    set sort=+size
         \ |    echo 'Sorted by size (small-BIG)'
         \ |elseif &sort == '+size,+name'
         \ |    set sort=-size
         \ |    echo 'Sorted by size (BIG-small)'
         \ |else
         \ |    set sort=+size
         \ |    echo 'Sorted by size (small-BIG)'
         \ |endif

command! sorttimetoggle
         \ :if &sort == '-mtime'
         \ |    set sort=+mtime
         \ |    echo 'Sorted by mtime (old-new)'
         \ |elseif &sort == '+mtime,+name'
         \ |    set sort=-mtime
         \ |    echo 'Sorted by mtime (new-old)'
         \ |else
         \ |    set sort=+mtime
         \ |    echo 'Sorted by mtime (old-new)'
         \ |endif

nnoremap <silent> <c-a-n> :sortnametoggle<cr>
nnoremap <silent> <c-a-s> :sortsizetoggle<cr>
nnoremap <silent> <c-a-t> :sorttimetoggle<cr>

...