Fzf: Long commands aren't horizontally scrollable

Created on 23 May 2016  ·  7Comments  ·  Source: junegunn/fzf

  • Category

    • [x] fzf binary

    • [ ] fzf-tmux script

    • [ ] Key bindings

    • [x] Completion

    • [ ] Vim

    • [ ] Neovim

    • [ ] Etc.

  • OS

    • [ ] Linux

    • [x] Mac OS X

    • [ ] Windows

    • [ ] Etc.

  • Shell

    • [x] bash

    • [ ] zsh

    • [ ] fish

Long commands aren't horizontally scrollable

I can't seem to be able to scroll horizontally along any results that are longer that my terminal screen. The example image above shows many different curl requests that _look_ the same, but in fact point to different URLs so it's impossible to know which one I want.

Most helpful comment

Thanks for sharing @junegunn.

When I tried those options, the command was truncated to the window width, so it didn't provide much value. From some searching it looks like behaviour has changed since you posted your tip.

For anyone looking to do this now, I updated my CTRL_R_OPTS to look like this:

export FZF_CTRL_R_OPTS="--preview 'echo {} |sed -e \"s/^ *\([0-9]*\) *//\" -e \"s/.\\{\$COLUMNS\\}/&\\n/g\"' --preview-window down:3:hidden --bind ?:toggle-preview"

It's the preview window example given above, but it will wrap the command.

If you want some fancy looking line wrap indicator, try this one:

bash export FZF_CTRL_R_OPTS="--preview 'echo {} |sed -e \"s/^ *\([0-9]*\) *//\" -e \"s/^\\(.\\{,\$COLUMNS\\}\\).*$/\\1/\"; echo {} |sed -e \"s/^ *[0-9]* *//\" -e \"s/^.\\{,\$COLUMNS\\}//g\" -e \"s/.\\{1,\$((COLUMNS-2))\\}/⏎ &\\n/g\"' --preview-window down:5 --bind ?:toggle-preview"

All 7 comments

If you start matching on the right, (in your example, by typing "component"), you can view more (but there is no way to bind a key to scroll to the right for you)

@edi9999 Thanks for chiming in.

If you start matching on the right, (in your example, by typing "component"), you can view more

Yes that's what I would do. A large --hscroll-off value in $FZF_CTRL_R_OPTS can definitely help (the default is 10).

But anyway I don't have a great answer to this. Adding support for manual horizontal scrolling is the last thing I want to do as getting it right and implementing a clean, straightforward interface is not going to be trivial (manual scroll vs. auto scroll, short item vs. long item)

When the above trick doesn't work you, you might want to fall back to the original "reverse-search-history" that can display the command in multiple lines by binding it to a different key sequence (e.g. bind '"\C-x\C-r": reverse-search-history'), or simply use CTRL-P or CTRL-N to browse the recent entries on bash.

Closing as "wontfix" (at least for the moment). Thanks.

No problem. Thanks for the feedback everyone :-)

With the latest fzf, we have these options:

# always-visible preview window that shows full command
export FZF_CTRL_R_OPTS="--preview 'echo {}' --preview-window down:2"

# hidden by default, made visible on `?`
export FZF_CTRL_R_OPTS="--preview 'echo {}' --preview-window down:3:hidden --bind ?:toggle-preview"

Thanks for sharing @junegunn.

When I tried those options, the command was truncated to the window width, so it didn't provide much value. From some searching it looks like behaviour has changed since you posted your tip.

For anyone looking to do this now, I updated my CTRL_R_OPTS to look like this:

export FZF_CTRL_R_OPTS="--preview 'echo {} |sed -e \"s/^ *\([0-9]*\) *//\" -e \"s/.\\{\$COLUMNS\\}/&\\n/g\"' --preview-window down:3:hidden --bind ?:toggle-preview"

It's the preview window example given above, but it will wrap the command.

If you want some fancy looking line wrap indicator, try this one:

bash export FZF_CTRL_R_OPTS="--preview 'echo {} |sed -e \"s/^ *\([0-9]*\) *//\" -e \"s/^\\(.\\{,\$COLUMNS\\}\\).*$/\\1/\"; echo {} |sed -e \"s/^ *[0-9]* *//\" -e \"s/^.\\{,\$COLUMNS\\}//g\" -e \"s/.\\{1,\$((COLUMNS-2))\\}/⏎ &\\n/g\"' --preview-window down:5 --bind ?:toggle-preview"

Hmm I would like to understand how fzf --hscroll-off 10 vs fzf --hscroll-off 80 is working in this case. I don't see any difference? Thanks (ref: https://github.com/junegunn/fzf/issues/513)

The following example result the same

yes $({ printf '=%.0s' {1..400} ;  echo "foobar" ; printf '<%.0s' {1..400}; }) | head -n 20 | FZF_DEFAULT_OPTS="" fzf --hscroll-off 10
yes $({ printf '=%.0s' {1..400} ;  echo "foobar" ; printf '<%.0s' {1..400}; }) | head -n 20 | FZF_DEFAULT_OPTS="" fzf --hscroll-off 80

image

turns out there was a new line after foobar in example above

yes $({ printf '.%.0s' {1..400}; printf 'foobar'; printf '+%.0s' {1..400}; }) | head -n 20 | FZF_DEFAULT_OPTS="" fzf --hscroll-off=800

works

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jan-warchol picture jan-warchol  ·  3Comments

alistaircolling picture alistaircolling  ·  3Comments

sandric picture sandric  ·  3Comments

ahmedelgabri picture ahmedelgabri  ·  3Comments

sassanh picture sassanh  ·  3Comments