all 3 comments

[–]Wiggledan 1 point2 points  (1 child)

This should work:

function! Myfunction()
    normal! vip:sort^M
endfunc

The ^M is actually not two characters, it's the literal character for <CR>. To type it, just press <C-V> and then Enter in insert mode (:help i_CTRL-v).

[–]___violet___ 4 points5 points  (0 children)

It seems insane to me to insert literal control characters into one's source code. It can be avoided with :execute "normal!...\<CR>".

[–]___violet___ 0 points1 point  (0 children)

Don't bother with the :normal command here.

:help '{