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
edited by

What is a good way to execute “:file” (“display menu of programs set for the file type of the current file.”)? Any idea on a standard keyboard shortcut?

I have a directory tree with some files with which I do two things:
1. (on a single file) gvim -O ../known/%c ../unknown/%c ../unneeded/%c
2. (on one, several, or — by default — all files) cd .. && ./do.sh %f:p %m

  • For the first action, I gave the files an extension and made a filextype definition.
  • For the second action, I made a “command!”.

I hope to avoid having to add an extension or type an Ex command.

I added the second action to the filextype definition and added “nnoremap <cr> :file<cr>”. It’s usable, because I usually use l to switch between directories, but is obviously confusing.

by

The problem with <cr> for the shortcut is that it affects directories, including “..”.

by

Something is going to interfere:

I have this user vifmrc (after removing the comments):


`filetype *.wdk

\ {find commons with known}
\ cd .. && ./do.sh %f:p %m`

autocmd DirEnter ~/Documents/wikidata/*/ nnoremap o :!gvim -O ../known/%c ../unknown/%c ../unneeded/%c<cr>
autocmd DirEnter !~/Documents/wikidata/*/ execute 'nnoremap o :!gvim --remote-tab-silent %f<cr>'

command! wd cd .. && ./do.sh %f:p %m


The current file is Q6942@1727-год-ru-en-es.txt.wdk

:filetype Q6942@1727-год-ru-en-es.txt.wdk says “[find commons with known] cd .. && ./do.sh %f:p %m
:file lists that association and it works (a menu with the script output appears).
<cr>, l and open the file in Vim.

by

The problem with for the shortcut is that it affects directories, including “..”.

I'd probably just do something like

if filetype('.') != 'dir'
    " do it
endif

Something is going to interfere

I don't really see where actual behaviour doesn't match the expected one.

by

I'd probably just do something like

if filetype('.') != 'dir'

`" do it`

endif

Ah, I noticed that feature too late. The interference affects it, too.

>> Something is going to interfere

I don't really see where actual behaviour doesn't match the expected
one.

It’s in “<cr>, l and open the file in Vim.” I think when pressing any of those, the filetype should start my script and show a menu. Instead,

  1. The file is opened in Vim.
  2. After exiting Vim, there is sometimes a “press return” message.
  3. If I press return, there is a red “Another type of file viewing is activated” message (WTF?).
by

If I press return, there is a red “Another type of file viewing is activated” message (WTF?).

Oh, I guess one of the "execute"s was interpreted as normal mode commands, and I had preview mode on, so it complained.

Doesn't clarify anything else though.

by

Ah, it's because of cd being shell builtin. There is a check for availability of a command to skip over non-existing ones and builtins can't be checked this way as there are no corresponding executable files in $PATH. Need something to suppress the check or make it pass. One way to do this is to prepend echo -n && to the command. But more generic solution would be better.

by

Thanks.

So far, IIRC, it works only on a single file when using filetype, and for multiple files I use command!.

by
filetype *.wdk {find commons with known} echo -n && cd .. && ./do.sh %f:p %m

Works if multiple files are selected, so unless you added %c, removed %f or added & at the end, it should work.

by

Hm…

The "echo -n &&" workaround works only with a single file; with multiple files, Vim is started with the files open.

by

Maybe there are non-*.wdk files in selection?

by

.wdk is not used any more.

`
filetype ///home/user/Documents/wikidata/(known|unknown|unneeded)/.*//

\ {my Wikidata knowledge tool}
\ echo -n && cd .. && ./do.sh %f:p %m,

`

by

That was a bug with handling path regexps, fixed on latest master (d681808), thanks!

by

Thanks, it works in 0.8.1a.

1 Answer

0 votes
by

Solved for the first action:

autocmd DirEnter ~/Documents/wikidata/*/ nnoremap o :!gvim -O ../known/%c ../unknown/%c ../unneeded/%c<cr>

autocmd DirEnter !~/Documents/wikidata/*/ execute 'nnoremap o :!gvim --remote-tab-silent %f<cr>'

For the second action, I found “//path-regular-expression//[iI]”, so I could define a filetype for all files in those directories. But I can’t find out how to use that or path globs.

by

For the second action, I found “//path-regular-expression//[iI]”, so I could define a filetype for all files in those directories. But I can’t find out how to use that or path globs.

It's the same, just wrap the pattern with //, a couple of examples:

filextype ///home/xaizek/archive/articles/.*\.pdf// vim
execute 'filextype //'.$HOME.'/archive/articles/.*\.pdf// vim'
by

Thanks. So I tried it correctly at first, but couldn't notice because my command with "cd .. &&" (unlike nano %c) is affected by that Vim-running "interference" above.

...