sQVe / sort.nvim

Sorting plugin for Neovim that supports line-wise and delimiter sorting.
MIT License
137 stars 0 forks source link

Provide operator-pending keybindings #3

Open andrewferrier opened 2 years ago

andrewferrier commented 2 years ago

Thanks for your hard work on this great plugin...

I notice that in the README you list out some normal-mode remaps that "cheat" by pre-selecting a visual area and then running :Sort on them.

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>

This is great, but I think what would be even more fantastic is if sort.nvim provided a Vim/NeoVim-native operator-pending mode so that the user could type (following the example above) go<any text object> and have it commented out. Theoretically, they can type v<any text object><Esc><Cmd>Sort<CR> today, but that's a bit clumsy. The keybindings as listed above are a bit restrictive, as they limit the user to only those text objects that a binding already exists for.

Compare this with the vimscript-based https://github.com/christoomey/vim-sort-motion, which I've used for a long time, which provides this capability as its "default" approach (although it does also provide a keybinding in visual mode).

(More information on how this works/how to implement it here: https://www.vikasraj.dev/blog/vim-dot-repeat).

sQVe commented 2 years ago

Hey 👋🏼,

I totally agree and it would be a killer feature, which is why it is added to the roadmap. Before creating this script I used vim-sort-motion for many years but created this since I wanted better delimiter support.

With that said I will be honest and note that this very likely isn't something I will have time to work on, especially since I see little need for it in my day to day. I would be more than happy to look at a PR though!

andrewferrier commented 2 years ago

Fair enough. Suggest if you are willing you keep this issue open, if I find some free time to do some NeoVim hacking I might have a go at it myself :)