Neovim plugin to conveniently sort PHP "use" statements within your codebase. The plugin offers the flexibility to sort them alphabetically and by length, both in ascending and descending order.
- Sorts PHP "use" statements in your Neovim environment.
- Sorts PHP class properties in your Neovim environment.
- Supports sorting alphabetically and by statement length.
- Allows sorting in both ascending and descending order.
- Allows removing unused "use" statements.
Execute the following command to sort your PHP "use" statements:
:PhpUseSort [alphabetical | length] [asc|desc]
- Neovim >= 0.5.0
- Treesitter >= 0.9.2
Install the plugin with your preferred package manager:
{
"ricardoramirezr/php-use-sort.nvim",
dependencies = {
"nvim-treesitter/nvim-treesitter",
},
ft = "php",
opts = {
order_by = "length",
order = "asc",
autocmd = true,
rm_unused = true,
},
config = function(opts)
require("php-use-sort").setup(opts)
vim.keymap.set("n", "<leader>su", ":PhpUseSort<CR>", {
desc = "Sort PHP use lines by length",
silent = true,
})
end,
}
php-use-sort.nvim comes with the following defaults:
{
order_by = "length", ---@type "length" | "alphabetical"
order = "asc", ---@type "asc" | "desc"
autocmd = false, -- create an autocmd group if true
rm_unused = false, -- remove lines that "is declared but not used."
includes = {
uses = true,
traits = true,
properties = {
enable = true,
space = "between types", --- "none", "between properties"
},
},
}