Trying to get a handle on fixing file preview during find-file

What happened?

Under :completion I’ve enabled (vertico +icons) and (company).

When I use find-file (SPC .) and start going through candidates, I want to preview the file under point, so I use the preview binding (CTRL SPC). The resulting window appears in the middle of the frame and is pretty short: Maybe 8 lines tall. It’s not enough to get as much context as I’d like sometimes, it’s sharing half of the non-Vertico parts of the frame with the window I invoked find-file from, and there’s a lot of visual clutter.

┌──────────────────────────┐
│                          │
│     Original window      │
│                          │
├──────────────────────────┤
│                          │
│      Preview window      │
│                          │
├──────────────────────────┤
│                          │
│      Vertico window      │
│                          │
└──────────────────────────┘

What did you expect to happen?

Well, let’s not use words like “expect” and “should happen” because I don’t know what to expect and it’s possible that the whole thing is working as intended by the people who get to say “should.”

What I’d like to happen would be to have the preview window take up the remainder of the frame that is not occupied by Vertico. That would let me see more of the file and it’d be a lot less visually cluttered.

┌──────────────────────────┐
│                          │
│                          │
│      Preview window      │
│                          │
│                          │
├──────────────────────────┤
│                          │
│                          │
│      Vertico window      │
│                          │
│                          │
└──────────────────────────┘

I spent a pretty healthy amount of time trying to run this down, but depending on how I searched a number of packages were implicated and I realized I’m just in over my head.

Steps to reproduce

  1. invoke find-file with SPC .
  2. Position the point over a candidate.
  3. invoke preview with CTRL SPC
  4. Observe preview window in middle of frame.

System information


Loading data dump...
1 Like

Hey, I am facing the exact same problem, this also happens when finding files with consult-find command. I want the previewing of files just like the previewing of grep command. Did you found any solutions?

I just tried and previewing files doesn’t create any new window for me. So if previewing in SPC , works for you, my guess would be that you have something in your display-buffer-alist that is causing this. Previewing uses switch-to-buffer-other-window under the hood which calls display-buffer. The newly created buffer for preview is named,

(format " Preview:%s" (file-name-nondirectory (directory-file-name name)))

so check if something in your display-buffer-alist can match such buffers.

1 Like

Hey, Can you help me with this same exact issue but with consult-find command, I checked what you said and found no list of preview buffer in alist function. But whenever I use consult-find, and press C-spc previews shows in multiple splits in my window, and Another problem is that it Does not close the preview buffers after the search is over, and also it always ask for lsp-mode import prompts in many files. I want the preview functionality to be just like consult-grep, it shows previews and also close all the previews buffers after search and also never actually asks for any lsp-import prompts. I don’t know if it is a bug or doom’s setting but I want help to configure it. If you want, I can share the my config file but please guide me.

Looking around this is because consult-find has no preview functionality. So instead doom provides a fallback for preview which is very rough. You can check this checking the binding for C-SPC while in minibuffer by using C-h k C-SPC. You will need to define your own consult-find or maybe file an issue on consult since I think adding previewer would be a one line change of passing (consult--file-preview) as the value for :state property in consult-find.

1 Like

Related upstream issue: Issues with displaying previews · minad/consult · Discussion #855 · GitHub

This topic was automatically closed after 360 days. New replies are no longer allowed.