5

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
    Afaik there is no mapping that sorts given lines. (at least :helpgrep sort didn't turn up anything in the change.txt file) – EvergreenTree Feb 2 '16 at 23:12
9

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, privacy policy and cookie policy

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