3

Suppose I have the following text:

int z; int a; int c; int g; 

or the following text:

z, a, c, g

How can I sort them to:

int a; int c; int g; int z; 

and

a, c, g, z 

respectively?

1 Answer 1

5

Use M-x sort-lines for the first example. For the second example, change it into

z, a, c, g, 

then use M-x sort-regexp-fields <RET> ., <RET> \& <RET>.

1
  • 2
    Note that ., is specific to this example, if you need more generic patterns for coma separated words, you can use \s-?\w+,? Commented Mar 6, 2023 at 15:56

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.