Home

Awesome

🔠 sort.nvim

Sort is a sorting plugin for Neovim that provides a simple command to mimic :sort and supports both line-wise and delimiter sorting. This plugin intelligently selects a sorting strategy by using a configurable priority list, minimizing manual input and covering most sorting cases with just the :Sort command on a range.

❓ Why

📦 Installation

packer

-- Lua.

use({
  'sQVe/sort.nvim',

  -- Optional setup for overriding defaults.
  config = function()
    require("sort").setup({
      -- Input configuration here.
      -- Refer to the configuration section below for options.
    })
  end
})

vim-plug

" Vim Script.

Plug 'sQVe/sort.nvim'

" Optional setup for overriding defaults.
lua << EOF
  require("sort").setup({
    -- Input configuration here.
    -- Refer to the configuration section below for options.
  })
EOF

⚙ Configuration

Sort comes with the following defaults:

{
  -- List of delimiters, in descending order of priority, to automatically
  -- sort on.
  delimiters = {
    ',',
    '|',
    ';',
    ':',
    's', -- Space
    't'  -- Tab
   }
}

📗 Usage

https://user-images.githubusercontent.com/2284724/145567686-3b52978c-58fe-4f32-ad27-c2b1060870ba.mp4

Sorting with the Sort plugin is made easy through the provided :Sort command. The plugin utilizes two different strategies depending on the visual selection:

⌨️ Keybinding

By default, Sort does not set any keybindings. Here's an example of how you can set a keybinding to trigger :Sort. In this example, the keybinding go is used, but you can change it to whatever you prefer:

" Vim Script.

nnoremap <silent> go <Cmd>Sort<CR>
vnoremap <silent> go <Esc><Cmd>Sort<CR>
-- Lua.

vim.cmd([[
  nnoremap <silent> go <Cmd>Sort<CR>
  vnoremap <silent> go <Esc><Cmd>Sort<CR>
]])

A common workflow, before sorting, is to visually select inside a set of characters with vi<character>. Instead of doing that manually before running Sort you could add the keybindings like:

" Vim Script.

nnoremap <silent> go" vi"<Esc><Cmd>Sort<CR>
nnoremap <silent> go' vi'<Esc><Cmd>Sort<CR>
nnoremap <silent> go( vi(<Esc><Cmd>Sort<CR>
nnoremap <silent> go[ vi[<Esc><Cmd>Sort<CR>
nnoremap <silent> gop vip<Esc><Cmd>Sort<CR>
nnoremap <silent> go{ vi{<Esc><Cmd>Sort<CR>

🤝 Contributing

All contributions to Sort are greatly appreciated, whether it's a bug fix or a feature request. If you would like to contribute, please don't hesitate to reach out via the issue tracker.

Before making a pull request, please consider the following:

🏁 Roadmap