# Show A File Preview When Searching With FZF

[FZF](https://github.com/junegunn/fzf) by itself is a great way to fuzzy find files. It gets even better when you can view a preview of a file before opening it up. The `--preview` flag lets you do just this.

Add a basic file preview with `cat`:

```bash
$ fzf --preview 'cat {}'
```

The `{}` will get replaced a single-quoted string of the highlighted file.

You can spice up the preview a bit with color and line numbers using [`bat`](https://github.com/sharkdp/bat):

```bash
$ fzf --preview 'bat --color "always" {}'
```

The `--color` flag tells `bat` to produce syntax highlighted output even though it isn't in interactive mode.

Lastly, you can keep it performant by only showing the first 100 lines:

```bash
$ fzf --preview 'bat --color "always" --line-range 0:100 {}'
```

See `man fzf` for more details.

[source](https://github.com/dkarter/dotfiles/blob/master/vimrc#L362)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ploegert.gitbook.io/til/os/unix/search-query/show-a-file-preview-when-searching-with-fzf.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
