Welcome to Vifm Q&A, where you can ask questions about using Vifm. Registration is optional, anonymous posts are moderated. E-mail and GitHub logins are enabled.
0 votes
in vifm by

In VIFM, when you have the "set relativenumber" option in vifmrc, you get numbers displayed in front of files and folders, relative to the cursor's position.

Until now, when I wanted to enter a folder located 10 lines above the cursor, I would type 10, then the up arrow key, and then the Enter key. I was wondering if it's possible to create a shortcut by typing the number and then the 'u' key (for up) – which would have the effect of directly entering the folder or opening the file. For example, 10u would replace 10 + up arrow + Enter. The same for 10d which would have the effect of entering the folder located below the cursor.

Thanks for your advice and keep up the good work in developing this "terrible" program.

1 Answer

0 votes
by

That's possible. Key's count is available in v:count and v:count1, which together with :execute and :open can do what you want using a relative position to go to a specific line (see):

nnoremap <silent> u :<c-u>execute '.-'.v:count '| open'<cr>

Ctrl-U is there to get rid of the range inserted if doing something like 10:
. Change - to + to move down:

nnoremap <silent> U :<c-u>execute '.+'.v:count '| open'<cr>
by

@xaizek It's working very well

I changed

nnoremap <silent> u :<c-u>execute '.-'.v:count '| open'<cr>

to

nnoremap <silent>  - :<c-u>execute '.-'.v:count '| open'<cr>

and

I changed

nnoremap <silent> U :<c-u>execute '.+'.v:count '| open'<cr>

to

nnoremap <silent> + :<c-u>execute '.+'.v:count '| open'<cr>

for those reasons:

1) need the u key for undo
2) the keys minus and plus are unused in VIFM
3) the key - and + are near the number pad on the right side of the laptop I use - find it intuitive

I found an other behavior with the use of those commands on links...it is not following the link - if I find a workaround I will post it here

Thanks a lot

by

I found an other behavior with the use of those commands on links...it is not following the link - if I find a workaround I will post it here

Not sure if I understand it, but try replacing open with normal gf.

by

@xaizek your last advice normal gf works much better, thanks a lot

For example, if I yank a directory with yy and create a symbolic link in another location with al, then with these mappings:

nnoremap <silent> - :<c-u>execute '.-'.v:count '| normal gf'<cr>

and

nnoremap <silent> + :<c-u>execute '.+'.v:count '| normal gf'<cr>

if I try to open the link—let's say on the fifth line below the cursor position — I press 5+, which will jump to the target directory, and then I can open it with enter.

...