Reputation:
In Vim, I run the following to sort selected lines by length:
%!perl -e 'print sort { length($a) <=> length($b) } <>'
How do I go about turning this into a function so that I don't have to type this all out?
Upvotes: 0
Views: 53
Reputation: 31040
It might be simpler to define a command in your .vimrc that takes this action. For example:
command SortByLength %!perl -e 'print sort { length($a) <=> length($b) } <>'
Then you can execute :SortByLength
as you please, or map a keystroke to execute this command. See :help 40.2
for more information.
Upvotes: 5