Skip to content

Add a keybinding for collapsing the directory the cursor is in - #6066

Open
shunsuke44 wants to merge 2 commits into
jesseduffield:masterfrom
shunsuke44:collapse-parent-directory
Open

shunsuke44 wants to merge 2 commits into
jesseduffield:masterfrom
shunsuke44:collapse-parent-directory

Conversation

@shunsuke44

Copy link
Copy Markdown

I've read CONTRIBUTING.md, and I know this project doesn't accept pull requests.
I'm opening this one anyway, so let me be upfront about why.

I wanted this feature badly enough to build it for my own daily use.

If it isn't to your taste, please just close it — no explanation needed, and no hard feelings. I'll keep using it in my fork either way. But I do hope that something like this makes it into lazygit one day.

PR Description

Working in a deeply nested directory and wanting to fold it away means first walking the cursor up to the directory's own line and only then collapsing it. This binds that to a single key, leaving the cursor on the directory that was just collapsed so it can be repeated to fold up the tree one level at a time.

The containing directory is found by scanning upwards for the first item rendered at a smaller visual depth, rather than by taking the parent of the selected item's path. Paths don't survive either of the tree's display transformations: a chain of single-child directories is compressed into one node whose path names the deepest of them, so the path's parent is often a node that doesn't exist, and with showRootItemInFileTree disabled the internal paths carry no "./" prefix. Visual depth is exactly what's on screen, so both fall out for free.

Please check if the PR fulfills these requirements

  • Cheatsheets are up-to-date (run go generate ./...)
  • Code has been formatted (see here)
  • Tests have been added/updated (see here for the integration test guide)
  • Text is internationalised (see here)
  • If a new UserConfig entry was added, make sure it can be hot-reloaded (see here)
  • Docs have been updated if necessary
  • You've read through your own file changes for silly mistakes etc

Working in a deeply nested directory and wanting to fold it away means
first walking the cursor up to the directory's own line and only then
collapsing it. This binds that to a single key, leaving the cursor on
the directory that was just collapsed so it can be repeated to fold up
the tree one level at a time.

The containing directory is found by scanning upwards for the first
item rendered at a smaller visual depth, rather than by taking the
parent of the selected item's path. Paths don't survive either of the
tree's display transformations: a chain of single-child directories is
compressed into one node whose path names the deepest of them, so the
path's parent is often a node that doesn't exist, and with
showRootItemInFileTree disabled the internal paths carry no "./"
prefix. Visual depth is exactly what's on screen, so both fall out for
free.
The panel renders the same tree with the same collapse/expand keys, so
folding a deep directory away there meant walking the cursor up by hand
in exactly the way the files panel no longer requires.
@shunsuke44
shunsuke44 force-pushed the collapse-parent-directory branch from 17ede5e to fe54929 Compare October 1, 2026 00:20

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant