Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Requst: File picker based on current buffer's directory #3052

Closed
paholg opened this issue Jul 12, 2022 · 17 comments · Fixed by #4666
Closed

Feature Requst: File picker based on current buffer's directory #3052

paholg opened this issue Jul 12, 2022 · 17 comments · Fixed by #4666
Labels
A-helix-term Area: Helix term improvements C-enhancement Category: Improvements

Comments

@paholg
Copy link

paholg commented Jul 12, 2022

I will often "go to definition" for library code and then want to explore that library, but have no good way of doing that.

Being able to open a picker based on the current buffer's file location, and having a way to "go up a level" in the picker (like emacs' helm-mode's ctrl-l) would solve this.

I am also interested in if anyone has a workaround for exploring library code without re-opening helix in the library directory.

@paholg paholg added the C-enhancement Category: Improvements label Jul 12, 2022
@sudormrfbin
Copy link
Member

Related: #2481.

I am also interested in if anyone has a workaround for exploring library code without re-opening helix in the library directory.

You could :cd into the library directory, but there's no way currently to quickly enter the path of the current file into the command line (#2985).

@QiBaobin
Copy link
Contributor

I am adding a register % to match current file name, but I don't know how to use it in the config.toml.

If it's a OK, I would like to make a PR to let 2 + space + F open the file picker on current buffer's directory.

@the-mikedavis
Copy link
Member

I don't think we should use counts to modify behavior unless the behavior depends on the number (like repetitions). With this there would be quite a few file opening commands - maybe we should have a sub-map in space for file pickers? Or we could have a sub-map just for the specialized ones: leave <space>f and use <space>F as the leader for picking from the current directory, the current buffer's directory, etc.

@the-mikedavis
Copy link
Member

This picker would also be useful in languages with lots of directories in their namespaces like Ruby or Elixir: you tend to have a collection of somewhat short modules in a directory instead of larger more monolithic modules all combined into one directory (like with Erlang for example). Being able to jump to other modules in the namespace could be useful.

@the-mikedavis the-mikedavis added the A-helix-term Area: Helix term improvements label Jul 13, 2022
@QiBaobin
Copy link
Contributor

QiBaobin commented Jul 13, 2022

This

I don't think we should use counts to modify behavior unless the behavior depends on the number (like repetitions). With this there would be quite a few file opening commands - maybe we should have a sub-map in space for file pickers? Or we could have a sub-map just for the specialized ones: leave <space>f and use <space>F as the leader for picking from the current directory, the current buffer's directory, etc.

This does make a lot sense, would open a PR for it.

Added below mapping:

#### File mode

This layer is a kludge of mappings, mostly pickers.


| Key     | Description                                                             | Command                             |
| -----   | -----------                                                             | -------                             |
| `f`     | Open file picker                                                        | `file_picker`                       |
| `F`     | Open file picker at current working directory                           | `file_picker_in_current_directory`  |
| `d`     | Open file picker at current buffer's directory                          | `file_picker_in_buffer_directory`   |
| `c`     | Open the helix config.toml file                                         | `config_open`                       |
| `l`     | Open the helix log file                                                 | `log_open`                          |

@kee-oth
Copy link

kee-oth commented Sep 29, 2022

I just want to ping this thread as this functionality is something I'd really enjoy in my workflow. I do most of my work in projects where sibling files are highly relevant (frontend JS/TS work).

Is this something Helix is still interested in pursuing? Thanks!

@Elias-Graf
Copy link

Elias-Graf commented Nov 17, 2022

I find myself wanting this quite a lot when working with angular, or any other framework / language that has multiple strongly correlated files in the same folder.

My first thought was "a file picker in the current directory", but thinking about it, a file picker that just shows me the sibling files at the top of the list would do the trick. Not sure if you guys want to modify the sorting behaviour, but given the filtering still applies, it shouldn't be that big of an issue.

The file picker could also prioritise recently opened files, but I guess that's a different matter.

@cbclemmer
Copy link
Contributor

I was looking at this issue and had to click through a few different links but there is a PR open for this for future reference #2707

@the-mikedavis
Copy link
Member

#2707 is for #2558. This is covered by #4666

@the-mikedavis the-mikedavis linked a pull request Nov 18, 2022 that will close this issue
@tennix
Copy link
Contributor

tennix commented Nov 27, 2022

This

I don't think we should use counts to modify behavior unless the behavior depends on the number (like repetitions). With this there would be quite a few file opening commands - maybe we should have a sub-map in space for file pickers? Or we could have a sub-map just for the specialized ones: leave <space>f and use <space>F as the leader for picking from the current directory, the current buffer's directory, etc.

This does make a lot sense, would open a PR for it.

Added below mapping:

#### File mode

This layer is a kludge of mappings, mostly pickers.


| Key     | Description                                                             | Command                             |
| -----   | -----------                                                             | -------                             |
| `f`     | Open file picker                                                        | `file_picker`                       |
| `F`     | Open file picker at current working directory                           | `file_picker_in_current_directory`  |
| `d`     | Open file picker at current buffer's directory                          | `file_picker_in_buffer_directory`   |
| `c`     | Open the helix config.toml file                                         | `config_open`                       |
| `l`     | Open the helix log file                                                 | `log_open`                          |

#4666 adds a command for file picker, but does not have a keybinding for it. And the <space>d keybinding is already taken by diagnostic picker.

By reading helix-term/src/commands.rs, the file picker uses git root directory or fallback to current working directory, while the file picker at current working directory is the fallback mode for file picker. I think most people would just cd into the project root directory and run hx there. This makes the two keybindings have the same effects. So I would suggest making <space>f for open file picker at current buffer's directory and <space>F for open file picker. And just remove the open file picker at current working directory.

@the-mikedavis What do you think about this suggestion? Also a kind reminder, PR #4666 has changed a bit after your approval, so need an approval again :-)

@the-mikedavis
Copy link
Member

the file picker uses git root directory or fallback to current working directory

It's a bit different: it's the LSP workspace directory. So the file picker matches what the language server sees as the root directory for the project.

See the discussion in #3063. We don't want to remap the current <space>f.

@robclancy

This comment was marked as abuse.

@tennix
Copy link
Contributor

tennix commented Apr 15, 2023

The command file_picker_in_current_buffer_directory is used to open file picker in current buffer directory, however it's not bind to any key yet. For those who want to use this, it's easy to bind it space mode by adding following to your config file

[keys.normal."space"]
o = "file_picker_in_current_buffer_directory"

<space>o would open this file picker

@dbarnett
Copy link

dbarnett commented Oct 5, 2024

I am adding a register % to match current file name, but I don't know how to use it in the config.toml.

Was there any further discussion on adding a placeholder like % for current file name? In vim I'll often do stuff like :vsplit %:h<TAB>/otherfile, but for helix it looks like out of the box there's still nothing more ergonomic than typing out the whole CWD-relative filepath?

@dbarnett
Copy link

dbarnett commented Oct 5, 2024

With this there would be quite a few file opening commands - maybe we should have a sub-map in space for file pickers? Or we could have a sub-map just for the specialized ones: leave <space>f and use <space>F as the leader for picking from the current directory, the current buffer's directory, etc.

Would you ever consider, from the file picker itself, some shortcut to change the base directory? That way instead of relying on a profusion of separate "file_picker_in_X_directory" commands, I could just open the file picker and then have options from there to pivot the base directory I'm picking from.

@paholg
Copy link
Author

paholg commented Oct 6, 2024

With this there would be quite a few file opening commands - maybe we should have a sub-map in space for file pickers? Or we could have a sub-map just for the specialized ones: leave <space>f and use <space>F as the leader for picking from the current directory, the current buffer's directory, etc.

Would you ever consider, from the file picker itself, some shortcut to change the base directory? That way instead of relying on a profusion of separate "file_picker_in_X_directory" commands, I could just open the file picker and then have options from there to pivot the base directory I'm picking from.

I have a branch to add keybinds to navigate the picker to child or parent directories. It was not approved for merging, but I am using it and periodically rebase off master of you want to try it. I still find opening the picker in the current buffer's directory quite useful though. I often use them in conjunction -- I'll go-to definition, then open picker in buffer directory, then move the picker to parent directories to browse library code.

https://github.com/paholg/helix/tree/file-picker-navigation

@dbarnett
Copy link

dbarnett commented Oct 6, 2024

That's great! They were resistant to merging when you sent a PR for some reason?

I'd imagined some way to jump to buffer parent too… maybe just typing % into the picker and hitting ctrl-e from your mechanism, if they'd be willing to support that path placeholder?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-helix-term Area: Helix term improvements C-enhancement Category: Improvements
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants