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 am trying to keep the selection after file open. I always want to open only the file under cursor (not the selected files/folders) and I want to just keep the selection.

First I though maybe I can modify all filextype to retrieve selection after opening:

 filextype *.pdf zathura %c %i & | normal gs

But, this doesn't seem to work. Do you have any hints? Is something like this even possible with filextype?

Then, I tried changing the enter command:

nnoremap <cr> :file &<cr>lgs

This keeps the selection, but it only opens the first selected file regardless of location of the cursor. It also makes enter useless when cursor is at the dot (very first item on top). Adding %c like this:

nnoremap <cr> :file %c &<cr>lgs

will make enter to open the item under cursor regardless of the selection (which is what I want), but does not retrieve the selection.

I also tried these:

nnoremap <cr> :file %c &<cr>l | normal gs
nnoremap <cr> :file %c &<cr>l | :execute "norm gs"

which also do not keep the selection and also switch the pane.

Can you think of any workaround for me to keep the selection with file open? I never open all selected files and only want to open the item under cursor.

Thank you.

1 Answer

0 votes
edited by
Best answer

:filextype executes a shell command, you can't run Vifm's :commands there. This might work:

nnoremap X :file &<cr>l
nmap <cr> "xysX"xgs 

Initial version was:

nnoremap <cr> "xys:file &<cr>l"xgs 

but it causes the assertion you've seen already:

event_loop.c:253: event_loop: Assertion `counter <= input_buf_pos' failed.

UPDATE. That assertion is fixed by this commit.


could you explain the "xysX"xgs part?
I tried it and it seems to work if the selected files are pdf. However, It doesn't work on txt files. Also, it does not enter the top dot folder anymore.


Yanking into register x, opening a file, then restoring selection from register x. :file doesn't open for files without associations, I thought you're using :file knowing that. You can replace X with l and drop the first mapping.


wow. got it, thank you