zed
zed copied to clipboard
Key Binding for "Organize Imports"
Check for existing issues
- [X] Completed
Describe the feature
I don't know if this is already possible, but it looks like we can not bind a key to the code action "Organize Imports".
In my TS files I would like to have a key binding to quickly organize the imports without opening the code action menu. Currently I have a key binding to format the code ("alt-shift-f": "editor::Format") and in this style would it be possible to have "alt-shift-o": "editor::OrganizeImports" or something like that?
This feature request is similiar to zed-industries/zed#5232 but refers to a action on save.
If applicable, add mockups / screenshots to help present your vision of the feature
No response
This is a very useful feature
I'd also love this feature.
Good want. Hope to have this feature in the near future
need! For now: is there at least an automation to to this at save?
After https://github.com/zed-industries/zed/pull/7860 we now have code_actions_on_format, which landed in 0.124.0. With that you should be able to add the following to your settings:
{
"languages": {
"TSX": {
"code_actions_on_format": {
"source.organizeImports": true
}
}
}
}
And it then runs that code action whenever you trigger format:
https://github.com/zed-industries/zed/assets/1185253/2c802df6-8ca9-4c1f-b645-8c100bf247cd
I'm closing this ticket, because I'm pretty sure that this fixes the problem, even though it didn't add a new keybind. (You can just run format and it'll trigger the code actions, and format you can bind to keys). Let's create new issues if this still doesn't solve your problem :)
Hi, is this not supported for Python? I already add this settings in:
- Global settings
- Project settings
Like this:
{ "languages": { "Python": { "code_actions_on_format": { "source.organizeImports": true } } } }
Or, like this:
{ "language_overrides": { "Python": { "code_actions_on_format": { "source.organizeImports": true } } } }
Still doesn't sort my imports. I use it alongside format_on_save config with external command (black formatter).