Edit Page
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 32: | Line 32: | ||
===Sort in reverse=== |
===Sort in reverse=== |
||
<pre>:%sort!</pre> |
<pre>:%sort!</pre> |
||
− | |||
===Sort, removing duplicate lines=== |
===Sort, removing duplicate lines=== |
||
<pre>:%sort u</pre> |
<pre>:%sort u</pre> |
||
− | |||
===Sort using the external Unix sort utility, respecting month-name order=== |
===Sort using the external Unix sort utility, respecting month-name order=== |
||
<pre>:%!sort -M</pre> |
<pre>:%!sort -M</pre> |
||
("respecting month-name order" means January < February < ... < December) |
("respecting month-name order" means January < February < ... < December) |
||
− | |||
===Numeric sort=== |
===Numeric sort=== |
||
<pre>:sort n</pre> |
<pre>:sort n</pre> |
||
(this way, 100 doesn't precede 20 in the sort) |
(this way, 100 doesn't precede 20 in the sort) |
||
− | |||
===Sort subsections independently, in this example sort numbers between "start" and "end" markers=== |
===Sort subsections independently, in this example sort numbers between "start" and "end" markers=== |
||
<pre>:g/start/+1,/end/-1 sort n</pre>It is very important that the strings "start" and "end" ONLY appear as markers! |
<pre>:g/start/+1,/end/-1 sort n</pre>It is very important that the strings "start" and "end" ONLY appear as markers! |
||
Line 89: | Line 85: | ||
You can also sort on text that *matches* the regex by including the 'r' flag, for example: <pre>:{range}sort /\/[A-z]/ r</pre> |
You can also sort on text that *matches* the regex by including the 'r' flag, for example: <pre>:{range}sort /\/[A-z]/ r</pre> |
||
+ | |||
⚫ | |||
+ | |||
⚫ | |||
⚫ | |||
==See also== |
==See also== |
||
Line 115: | Line 116: | ||
---- |
---- |
||
− | This misguided snippet was added recently: |
||
− | |||
⚫ | |||
− | |||
⚫ | |||
− | |||
⚫ | |||
− | |||
− | This is wrong and should never work. Here's what it is actually doing: |
||
− | |||
− | <code>/|.*|/</code>: jump to the next line that has two '|' characters in it, anywhere |
||
− | |||
− | <code>|</code>: command separator, this lets you start a new command on the current line |
||
− | |||
− | <code>sort</code>: do a default sort of the entire buffer |
||
− | |||
− | Basically this is the equivalent of typing <code>:%sort</code>. |
||
− | |||
− | Now, what you CAN do, is provide a pattern that the <code>:sort</code> command will skip over and ignore at the start of every line while sorting. For example, to sort based only on text after the last '|' character on the line (what I think was intended by the example), you'd do this: |
||
− | |||
− | <pre> |
||
− | :sort /^.*|/ |
||
− | </pre> |