[[Neovim]]で[[Python]]のコードを保存したとき、[[Ruff]]の機能でインポート文の最適化(並び替え、不要インポート削除)を行う方法。[[conform.nvim]]に設定を追加する。 ```lua opts = { formatters_by_ft = { python = { "ruff_organize_imports", "ruff_fix" }, }, format_on_save = { timeout_ms = 1500, -- fallbackはしなくてもいい(ruff_fixが優先される) lsp_format = "fallback", }, } ``` ## 参考 - [Enable import autosort on save · Issue \#387 · astral\-sh/ruff\-lsp](https://github.com/astral-sh/ruff-lsp/issues/387) - [stevearc/conform\.nvim: Lightweight yet powerful formatter plugin for Neovim](https://github.com/stevearc/conform.nvim?tab=readme-ov-file)