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

I'm trying to create a keys mapping that copy some file to a register and then open them with the text editor, I need that because I need to compare them. Adding what's under cursor %c is perfect, so I can choose files one by one from totally different system, within the same vifm istance, and that's something I suspect I can't achieve with custom view, right?

1 Answer

0 votes
by

As in Vim copying into an uppercase register is appending (e.g., "Ayy appends to a register). An inconvenience here is that you need to start first by yanking into lowercase register to clear it.

You can then use a register in an external command as %"a.

that's something I suspect I can't achieve with custom view, right?

Can't answer because I don't get how exactly the two relate.

by

custom view is created in a single command right? what I want to achieve is
- add a file to a sort of buffer
- continue to explore other paths in vifm
- add another file to the buffer
- [repeat steps]
- open files with nvim to compare them

the buffer could only be a register because custom view cannot be modified (add file) once creater, right?

by

In that sense yes, custom view can't be used as a temporary storage.

Apart from a register it could also be an external file, environment variable or an array of a Lua plugin.

by

can I ask you what you think it could be the cleanest and less "intrusive" way to do that?

by

Lua plugin is the most flexible way. You can add some :commands to add/reset/view files for diffing and then call them from mappings in vifmrc. Lua can also handle key bindings, but unless you want to handle text-object-like things (e.g. 10j in d10j), bindings can reside in vifmrc.

by

Where I can learn how to create and integrate those lua plugin in vifm? I'm starting from 0 with that but I'm curious about your suggestion

by

You can read this wiki page, which references Lua API documentation and where to find sample plugins (devicons manages a global list, although as a map rather than an array, but you can still use it as a base).

by

I took some time to read the :help vifm-lua.txt and, while is clear how that's the better way, I feel a bit overwhelmed. I would like to stick to something in the reach of my actual knowledge and maybe refactor it with lua in the future.
Speaking of which, I would like an alternative solution with the smallest footprint possible like the register one:

I would like to map yc to a command that appends the file under cursor to the a register, I'm trying to follow your initial suggestion but I can't make it works:

nnoremap yc :%c "Ayy

It miss the register clearing too, I'm not sure how what's the best workaround for that.

Then I would use yx to execute a command with the register content as argument, something like:

nnoremap yx :!nvim -O %"a
by
" yank the first file
nnoremap <silent> yC "ayy
" yank any other file
nnoremap <silent> yc "Ayy
" compare things
nnoremap <silent> yx :!nvim -O %ra<cr>
by

thank you, that's flawless. I was thinking, there's a way to use the default yy for the first file and then something like yY to add more files to that register? It's easy to memorize and more streamlined

by

Because default register is ", you can't append to it (no uppercase version). But given that updating a register clones its value to ", this should be quite close:

" yank the first file
nnoremap <silent> yy "ayy
" yank any other file
nnoremap <silent> yY "Ayy
" compare things
nnoremap <silent> yx :!nvim -O %r"<cr>
by

my god that's so satisfying! thank for the unwavering support and have a good christmas eve!

by

what if I want to avoid hardcoding this part

" compare things
nnoremap <silent> yx :!nvim -O %r"<cr>

and instead have two remapping where one open the register files with their default application and the other let me choose the application from :file menu? How I should compose the remap? I tried thinkering with :normal gl %ra for the first command but it's obviously wrong. Is that feasible at all?

by

one open the register files with their default application

Try (create custom view, select everything, hit l, leave custom view):

nnoremap <silent> yx :!printf '%%s\n' %r" %u<cr>:select *<cr>lh

the other let me choose the application from :file menu?

Similarly, but you'll have to close custom view afterward:

nnoremap <silent> yx :!printf '%%s\n' %r" %u<cr>:select * | file<cr>
by

maybe there's a cleaner way: a remap that execute :reg and then simulate the press of key b in that menu to create a custom view, is that possible? otherwise I could do manually those steps, not a big deal after all

by

:reg a followed by b is a valid way, but if current directory contains a file named "a", it will be included in the custom view as well.

by

you mean by mapping :reg a followed by b? because I tried to recreate that scenario and the file a was not included. Anyway I'll stick to that, it flows so satisfying! thank you for the support

by

I meant file named "a (with a leading double quote like in the menu).

...