fzf icon indicating copy to clipboard operation
fzf copied to clipboard

--keep-right not keeping right on long lines with search term present

Open ulope opened this issue 1 month ago • 3 comments

Checklist

  • [x] I have read through the manual page (man fzf)
  • [x] I have searched through the existing issues
  • [x] For bug reports, I have checked if the bug is reproducible in the latest version of fzf

Output of fzf --version

0.66.1 (brew)

OS

  • [ ] Linux
  • [x] macOS
  • [ ] Windows
  • [ ] Etc.

Shell

  • [ ] bash
  • [x] zsh
  • [ ] fish

Problem / Steps to reproduce

When long lines are present the --keep-right option seems to lose effect as soon as a search term is entered and results are being highlighted.

Here's an example:

(cat <<EOF
/short/path/file.bla
/A/very/long/path/that/is/shomewhere/deep/on/the/users/hard/disk/and/really/shouldnt/be/this/deeply/nested/somefile.txt
/A/very/long/path/that/is/shomewhere/deep/on/the/users/hard/disk/and/really/shouldnt/be/this/deeply/nested/otherfile.txt
/A/very/long/path/that/is/shomewhere/deep/on/the/users/hard/disk/and/really/shouldnt/be/this/deeply/nested/foobar.txt
EOF
) | fzf --keep-right --preview 'echo "{}"' -q this

Output in an 80x15 terminal:

                                        ╭──────────────────────────────────────╮
                                        │ '/A/very/long/path/that/is/shomewher │
                                        │                                      │
                                        │                                      │
                                        │                                      │
                                        │                                      │
                                        │                                      │
                                        │                                      │
                                        │                                      │
                                        │                                      │
▌ ··really/shouldnt/be/this/deeply/ne·· │                                      │
▌ ··really/shouldnt/be/this/deeply/ne·· │                                      │
▌ ··really/shouldnt/be/this/deeply/ne·· │                                      │
  3/4 ───────────────────────────────── │                                      │
> this                                  ╰──────────────────────────────────────╯

As you can see the search term this has moved to the middle of the line, violating the --keep-right option, even though there would be enough room to show the entire rightmost part of the line while still keeping this in view.

(Of course ignoring keep-right is fine when the search term occurs so far on the left that it's not possible to keep the right edge in view.)

ulope avatar Nov 05 '25 15:11 ulope

violating the --keep-right option

man page state this:

https://github.com/junegunn/fzf/blob/4d563c6dfaf854260314cb5cdc9df577ec512805/man/man1/fzf.1#L632-L634

Related comment by the maintainer: https://github.com/junegunn/fzf/issues/1652#issuecomment-597641573


I assume you just want to see the path ending to see if its the right folder you will select?

Did you try using the --wrap flag (and optionally the --gap flag, to better distinguish the elements)?

LangLangBart avatar Nov 07 '25 18:11 LangLangBart

As @LangLangBart mentioned, it is the limitation of the current implementation.

even though there would be enough room to show the entire rightmost part of the line while still keeping this in view.

Yeah, that would be an improvement.

junegunn avatar Nov 08 '25 01:11 junegunn

even though there would be enough room to show the entire rightmost part of the line while still keeping this in view.

One workaround would be to use a very large hscroll-off value, e.g. --hscroll-off=999 .

That said, I'm working on a stronger version of it called --freeze-right N in #4581. You can try replacing --keep-right with --freeze-right 1 (or any value), and the rightend will always be visible.

junegunn avatar Nov 10 '25 10:11 junegunn