Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> For example, to reverse sort only the first 5 lines of in buffer, one can execute this ex[0] command:

> :1,5 !sort -r

Interestingly enough, you don't even need an external program for that. You can do the same thing with

    :1,5 g/^/ m 0
The g command allows for effectively looping over matching lines as opposed to operating on them all at once. The /^/ matches every line and since I'm using 1,5 for the address, it still only matches the first five lines. The m command moves a line (in this case, 0 which is the beginning of the buffer).

Since it executes it one line at a time, it moves the first line to the beginning of the buffer, then the second line (which places it above the first line), then the third line (placing it above the second line) and so on.



Your command doesn't sort, only inverses the initial order. It's equivalent to

  :1,5 !tac




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: