-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Parameter or flag to scroll to certain line number #388
Comments
"Scroll to a certain line number" is something that the pager (e.g. I think there are multiple ways to solve this:
|
Oh I didn't know about |
Hi @sharkdp! I'm trying to use less to scroll to the line returned by rg through bat as preview for fzf. However I cannot seem to make the following work:
any pointers? |
Thanks for the quick reply @sharkdp! Mmm I think I'm clearly doing something wrong since using a non-existent pager on master:
|
I think the problem is that the If the pager in |
So basically the suggested |
It works just fine with
How would that work? We are not controlling scrolling in |
Oh ok. Thanks for the explanation. |
Hi. I am also looking for such a feature. Currently I am using a script which does a best effort centering for the preview inside fzf. But it would be much easier and better if bat could do it itself.
"Scrolling" is a misleading term in this context. No pager involved either. It's basically a special handling for a line range we are after. Let me explain... The preview of fzf is a fixed size area where the output of bat is rendered. That just requires to compute the start and end offsets for the For example, when the preview area is 20 lines, and we want to preview line 50 of a large file, then bat should skip to line 40 and render 20 lines (+/- header if enabled plus taking line wrapping into account). That way line 50 of the file would be centered in the preview area of fzf. Something like this: What do you think @sharkdp ? |
Using I tend to think that this is actually better solved with a script. This would be similar to https://github.com/junegunn/fzf.vim/blob/master/bin/preview.sh but use One thing that complicates everything is Another cool thing that could be added to such a script would be |
Did this ever go anywhere? |
I am using this little script: #!/usr/bin/env bash
set -eEuCo pipefail
declare -r file=$1
declare -i -r line=$2
declare -i -r lines=$LINES
# subtract 3 for the header
declare -i center=$(( (lines - 3) / 2 ))
if [ $line -lt $center ]; then
center=$line
fi
declare -i -r start=$(( line - center ))
declare -i -r end=$(( lines + start ))
exec bat --color always --highlight-line $line --line-range $start:$end --paging never "$file" with |
@avdv Thanks for this script. Tried using the Your script is simpler and works. Just wanna add that the complete command is: fzf --delimiter=: --preview "fzf-bat-preview {1} {2}" since other users might be confused and encounter errors. Cheers |
Here is a wrapper script around
Usage is as follows:
|
I want to use
bat
as part of the preview for myfzf
setup in vim withripgrep
.One of the shortcuts I am working on is search, which might get a hit somewhere in the middle of the file.
Currently, I can not find a way to tell
bat
which line to center on. So I might get a hit in a bunch of files, scroll through them, and then have to scroll in the preview pane to gage whether its worth opening the file. It would be awesome if I could use the line number that ripgrep finds to drive bat.Is that a feature you would consider merging?
The text was updated successfully, but these errors were encountered: