Note #2026-08-31-001

Srijan Choudhary Srijan Choudhary

In reply to File-tree navigation from current buffer by Anjack

Is there a way to navigate the files in a treemacs or dired (or similar) buffer without switching to that buffer first? Ideally I'd like there to be something displaying the directory of the file in the currently-focused buffer, with the file itself indicated (perhaps highlighted) and I'd like to be able to hit a key combo (not multiple consecutive keys) to move that selection up or down and either another key to open it or it opens when I release the modifier keys. Actually, I'd love it if I could hit a key combo to advance the selection indicator and have the currently-focused buffer automatically update to that file's contents.

For me, treemacs with the default keybindings suggested by it works good enough.

From any file buffer, hit M-0 to open a treemacs sidebar - this has the file highlighted. To go back quickly, just press q - closes the treemacs sidebar. C-n/C-p to move up/down. and Enter to open the new highlighted file.

From what you described, the two additional things you want are:

  • keep the point in the original buffer when treemacs opens - I think this should be doable.
  • Some keybinding in the original buffer moves the highlight in the treemacs buffer up/down AND also changes the current buffer to the new file highlighted - this might also be possible, but probably not a 1-liner.

Building this on top of treemacs (or dired-sidebar or dired-preview) will be much easier than building something from scratch.

Best of luck.

Tagged: emacs
Syndicated to: