Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show lines before and after result in fzf

Using fzf I want to be able to see the lines before and after the matched result when making a search. By default only the matched line is displayed.

like image 658
Qwertie Avatar asked Oct 14 '25 20:10

Qwertie


1 Answers

It looks like this feature hasn't been implemented in fzf just yet, (although the author makes no suggestion that it will be in future) but does provide a work around using fzf --preview

I don't know if that suits your particular use case but I was trying to find a certain git sha from the git history of repo where I knew a portion of the commit message. I couldn't get it to work with git log directly so I sent the whole log to a file, git_log, and used that instead:

fzf --preview 'tail +$(( {n} - 3 )) git_log' < git_log

(augmented version of the command provided in the Github issue)

{n} - 3 is 3 lines before the line that's matched, {n} being the zero-based index of the matching line.

The preview window should show the previous 3 lines then the line that's matched and then the rest of the git_log file until the end of the preview window.

like image 172
ssjoleary Avatar answered Oct 19 '25 15:10

ssjoleary