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.
+1 vote
in vifm by

I'm embarrassed to show my ignorance here and hate asking folks to spend their time educating me, but at my current level of understanding this isn't solvable …

I'd like to duplicate the functionality of al but have it create hard links rather than soft links. It's easy enough to make a custom command that will ln between panes, but with al it is possible to make a selection, yank it, navigate to a new directory and use al Which immediately makes new links to each file in the selection (more properly the yank register, I guess) in the current directory. Since I generally use vifm with the preview up, this is much more useful to me.

Unfortunately using %f in a custom command just expands to what's under the cursor, since "selection" is lost when location changes. Is there some way to refer to the yank register in custom commands/remaps? Am I going about this all wrong? Please advise.

1 Answer

+1 vote
by
selected by
 
Best answer

Given the size of documentation, there is nothing to be embarrass about. Even I don't remember everything by now.

Yanking populates unnamed register ("). You can expand its contents by using %r" macro in place of %f (docs).

by

Thanks very much! Super simple & worked exactly as expected.

Though I should have checked the documentation more carefully, it would be great if this was added to the included comments in vifmrc, would have saved us both a bit of time.

Thanks again!

J

by

I'd like to duplicate the functionality of al but have it create hard links rather than soft links

Hi there, would you, or anyone else, be so kind to explain in "vifm noob style" how to create the custom command ?

I'll get there eventually, but the Docs are overwhelming for new users.... any tips appreciated :-) Thank you!

by

Hello,

The mapping like this (on ah) should work similar to al, but create hard links:

nnoremap <silent> ah :!ln %r" . %i<cr>

It switches to command-line mode to execute !ln %r" . %i (%i docs) which gets expanded to something like

ln /tmp/a /tmp/b .

asumming those are the files yanked previously. <silent> (docs) is just to have fewer UI updates, otherwise you might see command on the status line as the mapping is executed.

by

Happy to (try to) help. I'm on mobile atm so forgive the ssh screenshot. You just need to edit your vifmrc config file. Which you can likely find in your home directory; something like ~/.config/vifm/vifmrc

somewhere in that file (probably near the included command entries for organization's sake) you can add the line:

command! hardlink ln %r ./

Then save the file. Here's the relevant bit of my vifmrc as an example:

In all subsequent instances of vifm you'll be able to type :hardlink to place hardlinks for each item in your current selection into the current directory.

If this is something you do often you could also map some keys to this command to avoid the typing. Just add

nnoremap ah :hardlink<cr>

to vifmrc as previously discussed.

by

Thank you so much for your replies @xaizek and @J.Reis , it worked perfectly.

(vifm is great, wish i found it earlier. Slowly getting through the learning curve...)

If you would like to make a bug report or feature request consider using GitHub, SourceForge or e-mail. Posting such things here is acceptable, but this is not a perfect place for them.
...