Skip to main content
Account for leading whitespace
Source Link
Rich
  • 32.6k
  • 4
  • 74
  • 141

You can do this with the following command:

:sort /^\^\s*\(# \)\?/

This skips the # if it exists, and then sorts on the remainder of the line. However, the pattern matches every line, so all lines are sorted into a single group.

You will want to add a range to the start of the command to apply this to the appropriate lines in your file.

The following command also works, coming at it from the opposite direction:

:sort r /\\s*\(# \)\?\zs.*/

Instead of skipping the matched part of the line, this sorts on the matched part, but we use \zs to exclude the # from the match, if it exists.

You can do this with the following command:

:sort /^\(# \)\?/

This skips the # if it exists, and then sorts on the remainder of the line. However, the pattern matches every line, so all lines are sorted into a single group.

You will want to add a range to the start of the command to apply this to the appropriate lines in your file.

The following command also works, coming at it from the opposite direction:

:sort r /\(# \)\?\zs.*/

Instead of skipping the matched part of the line, this sorts on the matched part, but we use \zs to exclude the # from the match, if it exists.

You can do this with the following command:

:sort /^\s*\(# \)\?/

This skips the # if it exists, and then sorts on the remainder of the line. However, the pattern matches every line, so all lines are sorted into a single group.

You will want to add a range to the start of the command to apply this to the appropriate lines in your file.

The following command also works, coming at it from the opposite direction:

:sort r /\s*\(# \)\?\zs.*/

Instead of skipping the matched part of the line, this sorts on the matched part, but we use \zs to exclude the # from the match, if it exists.

Didn’t need to use \ze
Source Link
Rich
  • 32.6k
  • 4
  • 74
  • 141

You can do this with the following command:

:sort /\^\(# \)\?\ze/

This skips the # if it exists, and then sorts on the remainder of the line. However, the pattern matches every line, so they are all lines are sorted ininto a single group.

You will want to add a range to the start of the command to apply this to the appropriate lines in your file.

The following command also works, coming at it from the opposite direction:

:sort r /\(# \)\?\zs.*/

Instead of skipping the matched part of the line, this sorts on the matched part, but we use \zs to exclude the # from the match, if it exists.

You can do this with the following command:

:sort /\(# \)\?\ze/

This skips the # if it exists, and then sorts on the remainder of the line. However, the pattern matches every line, so they are all sorted in a single group.

You will want to add a range to the start of the command to apply this to the appropriate lines in your file.

The following command also works, coming at it from the opposite direction:

:sort r /\(# \)\?\zs.*/

You can do this with the following command:

:sort /^\(# \)\?/

This skips the # if it exists, and then sorts on the remainder of the line. However, the pattern matches every line, so all lines are sorted into a single group.

You will want to add a range to the start of the command to apply this to the appropriate lines in your file.

The following command also works, coming at it from the opposite direction:

:sort r /\(# \)\?\zs.*/

Instead of skipping the matched part of the line, this sorts on the matched part, but we use \zs to exclude the # from the match, if it exists.

added 113 characters in body
Source Link
Rich
  • 32.6k
  • 4
  • 74
  • 141

You can do this with the following command:

:sort /\(# \)\?\ze.*/

This skips the # if it exists, and then sorts on the remainder of the line. TheHowever, the pattern matches every line, so they are all sorted in a single group.

You will want to add a range to the start of the command to apply this to the appropriate lines in your file.

The following command also works, coming at it from the opposite direction:

:sort r /\(# \)\?\zs.*/

You can do this with the following command:

:sort /\(# \)\?\ze.*/

This skips the # if it exists, and then sorts on the remainder of the line. The pattern matches every line, so they are all sorted in a single group.

You will want to add a range to the start of the command to apply this to the appropriate lines in your file.

The following command also works, coming at it from the opposite direction:

:sort r /\(# \)\?\zs.*/

You can do this with the following command:

:sort /\(# \)\?\ze/

This skips the # if it exists, and then sorts on the remainder of the line. However, the pattern matches every line, so they are all sorted in a single group.

You will want to add a range to the start of the command to apply this to the appropriate lines in your file.

The following command also works, coming at it from the opposite direction:

:sort r /\(# \)\?\zs.*/
added 113 characters in body
Source Link
Rich
  • 32.6k
  • 4
  • 74
  • 141
Loading
Source Link
Rich
  • 32.6k
  • 4
  • 74
  • 141
Loading