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

Sometimes I need to delete all folders? Is there any way to jump to the last folder? } jumps to the first file, so d} will include the first file as well.

Thank you

1 Answer

+1 vote
by
selected by
 
Best answer

Looks like visual mode needs to be used in this case (v}kd).

by

This also works without visual mode G{dgg.

by

None of the followings can delete all directories if there are no files:

nnoremap Da ggv}kd
nnoremap Da G{dgg

Is it possible to define conditional hotkeys depending on whether there are any files present in the current directory?

thank you

by
edited by

I am trying to make a command for this and am using :norm!:

command! mSelAllDir : set noquickview 
                   \| if system('[[ -z $(fd --type f) ]] && echo 1') == '1'
				   \|	execute 'norm! ggvG'
				   \| endif

It doesn't work I think because of v that is not in normal mode. Is there any better approach? or workaround?

by

Is it possible to define conditional hotkeys depending on whether there are any files present in the current directory?

There is no builtin checks like that.

execute 'norm! ggvG' works, you probably just need to add double quotes around $(fd --type f).

by

It still does not work. Can it be because of v that changes to visual mode but we are using it with :norm? When I run the command, the command-line says -- VISUAL --, but nothing is selected. Also, if I move up, it does not select anything, but If I mode down, it selects. Is this expected?

by

I thought this isn't complete command and you'll add some action. Looks like leaving command-line mode after visual mode messes things up. Try this instead:

command! mSelAllDir : set noquickview 
                   \| if system('[[ -z "$(fd --type f)" ]] && echo 1') == '1'
                   \|     execute "norm! ggvG\r"
                   \| endif
                   \| normal gs
by
edited by

This works. Thank you, but I have two questions please:

Why is gs needed? In normal mode when we do ggvG followed by enter, we have everything selected and we do not need to press gs to retrieve the selection.

Is there any difference between using execute "norm gg" and normal gg? So, can we do this instead of using execute?

command! mSelAllDirA : set noquickview 
                   \| if system('[[ -z "$(fd --type f)" ]] && echo 1') == '1'
                   \|     normal ggvG<cr>
                   \| endif
by

Need to leave visual mode and restore selection in normal mode, hence gs. :normal needs to be wrapped if it's not the last command and also to pass Enter to it, otherwise it will be interpreted by command-line mode.

by

Visual mode issue fixed in this commit.

...