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

Say user has a window with opened in single-pane mode:

single_window

From UX standpoint, if user executes :view<cr>, it can be expected that window is split perpendicular to the longer side and the preview is shown.

However, currently, vifm shows an error message:

error

Is there a script or configuration property to achieve this?

I would imagine roughly the following logic. If preview is called in single-pane mode:

  1. Check that vifm window size is at least >= XX by XX.
  2. Determine the long side of the window, split in half.
  3. Show preview and move focus to it.
  4. Once focus moves back to the file listing - hide preview window.

1 Answer

+2 votes
by

Something along these lines...

nnoremap <silent> w : if &quickview && !layoutis('only')
                   \|     view
                   \| else
                   \|     if layoutis('only')
                   \|         if &lines + 50 < &columns | vsplit | else | split | endif
                   \|     endif
                   \|     view!
                   \|     execute 'qnoremap w q:view|only|qunmap w<lt>cr>'
                   \|     execute 'wincmd w'
                   \| endif
                   \| <cr>

Use w to enter and quit such a preview (adjust 50, which depends on font).

Or maybe just use e for only mode.

by
edited ago by

Edited, please read below.

Hey, it works! Added to the Tips & Tricks section in the Wiki.

There is one edge-case. If the file is empty, "nothing to explore" is shown and preview split is not destroyed automatically.

nothing_to_explore

Do you reckon it's reasonable to check that:

  1. File is either "regular file" or symlink to a regular file.
  2. File size is >0.

Another unfortunate bug is that with this re-mapping, if vifm is in the regular two-pane mode, going to preview and back switches it to the single-pane.

by

You can preview everything except for empty files, so that check shouldn't be necessary on its own. Checking size could help to avoid the message (unless viewer doesn't produce output), although size of directory might be zero and here type check might be useful.

Actually, I think it fails for empty files because I was too lazy to make it work properly (to display 0 total lines and don't fail on any movement or search). Need to get rid of the message as it's a cause of irregularity.

ago by

Another unfortunate bug is that with this re-mapping, if vifm is in the regular two-pane mode, going to preview and back switches it to the single-pane.

Looks like I opened the page before you made the edit, here's updated version:

nnoremap <silent> w : if &quickview && !layoutis('only')
                   \|     view
                   \| else
                   \|     if layoutis('only')
                   \|         if &lines + 50 < &columns | vsplit | else | split | endif
                   \|         execute 'qnoremap w q:view|only|qunmap w<lt>cr>'
                   \|     else
                   \|         execute 'qnoremap w q:view|qunmap w<lt>cr>'
                   \|     endif
                   \|     view!
                   \|     execute 'wincmd w'
                   \| endif
                   \| <cr>
ago by

The "Nothing to explore" message won't appear in future versions.

...