user8370684
user8370684

Reputation:

How to turn this Vim command into a function?

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

Answers (1)

Conner
Conner

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

Related Questions