9

You can reflow a paragraph with gqip (or gqap).

Is the fastest way to sort a paragraph vip:sort<cr>? Or is there some shorter keystroke for sorting?

1
  • 2
    Afaik there is no mapping that sorts given lines. (at least :helpgrep sort didn't turn up anything in the change.txt file) Feb 2, 2016 at 23:12

2 Answers 2

12

You could define a "sort lines" operator like this:

function! s:SortLinesOpFunc(...)
    '[,']sort
endfunction

nnoremap <silent> \s :<C-u>set operatorfunc=<SID>SortLinesOpFunc<CR>g@

\sip will sort the paragraph under the cursor and, in general, \s{motion} will sort the lines moved over by {motion}, inclusively.

See :help :map-operator.

5

You can create a simple normal mode mapping:

nnoremap <key> :'{,'}sort<CR>

usage from normal mode: <key>

or a more flexible visual mode mapping:

xnoremap <key> :sort<CR>

usage from normal mode: vip<key>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.