Last call to make your voice heard! Our 2022 Developer Survey closes in less than a week. Take survey.

Questions tagged [sort]

Vim command for sorting a set of lines.

Filter by
Sorted by
Tagged with
1 vote
1 answer
25 views

How can I remove duplicates in comma-separated text, ignoring the first column, keeping only unique lines?

I have a sparse CSV file with data shaped like in this simplified example. I am omitting the header, Age,Fruit,Color,Count, but I can include it in my file if needed. You can see that the sparse rows ...
user avatar
2 votes
2 answers
57 views

Sort by frequency without deleting lines?

How can I sort by frequency without deleting any? one two one to one one two The output of the standard sort-by-frequency :%!sort | uniq -c | sort -nr is 2 one 1 two It has deleted all the ...
user avatar
  • 1,689
2 votes
2 answers
63 views

Sorting superscript numbers

I have the following text in a buffer: ² b ³ c ¹ a ⁰ ⁴ d The issue is that this is the text after running :sort (and :sort n ). My question is: why doesn't the superscripted numbers sort in the ...
user avatar
  • 267
0 votes
2 answers
67 views

How do I sort lines based on a text property?

I would like to tag lines with a certain text property and then sort all lines with that text property to come to the top. How can I sort based on having a text property rather than a pattern match?
user avatar
0 votes
1 answer
131 views

How do I sort lines after a prefix?

I would like to sort all lines in a file based on where the text of the line starts, after a line index which is printed into the file, like this: 126. This is the start of the line. It was ...
user avatar
1 vote
1 answer
237 views

Why does this vim command fail?

I'm trying to process large error logs and part of that is filtering out lines I don't need to see. Here's what I'm running in vim: :g/.*rsync: stat.*/d | %s/\(.*mkstemp "\)\(.* \/\)\(.*$\)/\2/ | ...
user avatar
  • 199
1 vote
1 answer
48 views

Case insensitive sorting doesn't work for non ascii characters

Make a list of these words: Če Čeprav Človeški čaka čakal čakalne čakati časih časovni času če Select all: ggVG and sort them with case insensitive: :sort i Če Čeprav Človeški čaka čakal čakalne ...
user avatar
  • 113
0 votes
0 answers
16 views

Sorting numbers, but according to forth column [duplicate]

What do you want to achieve? I have a 2 dimensional arrays of numbers like this: [8, 18, 2, 20, 0] [13, 18, 3, 15, 1] [8, 18, 3, 30, 2] [8, 13, 3, 15, 3] [8, 13, 2, 10, 4] [8, 15, 1, 7, 5] [13, ...
user avatar
  • 388
2 votes
2 answers
64 views

Sorting by the first Uppercase letter doesn't seem to work

I need to sort a list like this one, by the first uppercase letter: {alan turing Smith's Prize 1936} {werner heisenberg Matteucci Medal 1929} {albert einstein Barnard Medal 1920} From the manual ...
user avatar
2 votes
1 answer
40 views

How to sort lines while preserving comment association [duplicate]

Let's say I have a bunch of vim mappings (although it could be code in any language), each of which with a comment line or lines above them: (using # not " so the comments get highlighted nicely) ...
user avatar
  • 260
5 votes
3 answers
866 views

How can I sort multiline blocks in vim?

The task I have in mind is I have grown files containing multiline definitions. Currently I'm working on a file containing acronyms for latex - many entries like this, but most much more complex: \...
user avatar
  • 259
1 vote
1 answer
33 views

Retrograde sorting

I am looking for a way how to transfer this (and similar) block of text: dollar_value: str = field(init=False) dollar_symbol: str = field(init=False) dollar_unit: str = field(init=False) euro_value: ...
user avatar
  • 113
3 votes
2 answers
57 views

Syntax clarification on a global sort command

I was looking at a global command that I saved from long time ago. I did not understand how it was a valid syntax, but apparently the syntax was valid because the command worked. The command: :g/\v\{/...
user avatar
  • 165
6 votes
1 answer
2k views

How to sort case-insensitive?

Vim has :sort command, which sorts using case-sensitive by default. I would like to sort several lines using case-insensitive. I tried using :isort, however this command is not defined. Edit: I have ...
user avatar
  • 1,073
1 vote
0 answers
45 views

How to force glob() to make result in numerical order?

I have next files in the directory: ls -1 file_* file_1 file_101 file_2 file_202 file_3 file_4 file_5 In Vim I want to have these files in a numerically ordered list, like so: ['file_1', 'file_2', ...
user avatar
  • 197
3 votes
2 answers
244 views

Sort output of let or set

How to sort the output of let or get? E.g., I want to sort all global variables containing "python": :filter python let g:
user avatar
  • 211
3 votes
1 answer
161 views

Cannot sort my bash functions correctly

I'm trying to sort my bash functions inside my .bash_functions file. Here is what I type : :g/^function /,/^}$/ s/\n/@@@ :sort /^function / :%s/@@@/\r/g EDIT0 : Here is some of the input : ...
user avatar
  • 1,878
1 vote
0 answers
152 views

sort json content in terraform file

I'm trying to sort following json that is inside of terraform file. I'd like to sort it alphabetically by "name" value (ENV->PORT->USERNAME): { "name": "PORT", "value": ...
user avatar
  • 11
1 vote
3 answers
92 views

reset sequence of numbers

I have 50 lines of code private const CODE = 0; private const DESC = 1; // ... private const TRIM = 19; // instead of 24 private const SMURF = 35; // instead of 25 private const DOG = 31; // instead ...
user avatar
  • 191
1 vote
1 answer
264 views

function: sort output alphabetically

This function outputs data between braces as joined lines in a quickfix window. The output is sorted based on line numbers. I'm searching for a method to sort the data alphabetically. I tried to ...
user avatar
  • 11
4 votes
2 answers
710 views

Is there an efficient way to sort a selection of comma separated values in a single line?

I come about this regularly and still do it manually. Consider this example - say it's inside a text. first 3,2,17,198,232,1,999 and some other text second 1,2,3,71,98,4,5 and some more text I ...
user avatar
  • 259
2 votes
2 answers
294 views

Sorted TODO list with :sort n and letters

Let's say I have ordered TODO list with priorities, sorted already with :sort n similar to : 1. shopping 3. cooking. D 5. car repair. D 11. tap fix. 12. project start D means done. I am using :sort ...
user avatar
  • 209
5 votes
1 answer
1k views

How to sort lines by the right most characters?

When I enter visual mode, :'<,'>sort allows me to sort alphabetically the lines I have selected, obviously starting from the left most characters on a line going to the right. Is it possible to ...
user avatar
  • 825
0 votes
1 answer
126 views

How do you sort lines by longest substring to shortest substring?

Here are some sample strings, sorted by longest string to shortest sting: "Bi(NO<sub>3</sub>)<sub>3</sub>·5H<sub>2</sub>O","bismuth nitrate pentahydrate"); "Be(C&...
user avatar
  • 825
4 votes
1 answer
915 views

How to avoid 'Backwards range given' warning when invoking search range?

I've got the following sample HTML code: <html><body> <table class="foo"> <tr><td>1</td></tr> <tr><td>2</td></tr> <tr><td>...
user avatar
  • 16.5k
2 votes
1 answer
419 views

How can I sort a file by word frequency?

I have a file containing a list of words, e.g. list.txt contains: carrot apple pen ukulele pen cinnamon carrot carrot How do I sort this file so that the words which appear the most in it go to the ...
user avatar
  • 1,689
10 votes
1 answer
1k views

Sorting a column without altering other columns

I was recently aware of the filtering ! technique, and I love it. Unfortunately, I am not able to use it in a visual-block mode. Hope some experts here would help me out. Basically, I want to in-...
user avatar
9 votes
2 answers
501 views

Sort every few lines

I want to sort the following based on their keys case IndexError: PyErr_SetString(PyExc_IndexError, exc.str.c_str()); break; case ValueError: PyErr_SetString(PyExc_ValueError, exc.str....
user avatar
5 votes
1 answer
254 views

In Vim, how can you delete following identical rows in a visual selection, without sorting?

So Lets say I have a list \Summit \SummitSign \sun \ProgrammingOnABoat \SunCloud \SunshineOpenCircled \sup \supdsub \supdsub \supedot \suphsol \suphsub \Summit \SummitSign \sun \Summit \...
user avatar
  • 825
8 votes
2 answers
705 views

What is the fastest way to sort a paragraph?

You can reflow a paragraph with gqip (or gqap). Is the fastest way to sort a paragraph vip:sort<cr>? Or is there some shorter keystroke for sorting?
user avatar
3 votes
1 answer
656 views

Sorting a list in the buffer?

Is there a way to sort a list (single column, each item separated by \r) in the buffer using just vim?
user avatar
  • 3,081
12 votes
1 answer
3k views

Sort based on comma separated words

Normal command :sort can sort lines based on column or virtual column (\%c or \%v), could the higher level logical column be used as sorting key? Using regular expression looks a little complex for ...
user avatar
  • 812
4 votes
1 answer
957 views

User-defined sorting precedence

Is there a way to define a sorting precedence regarding the line's pattern and then use it with :sort? For example, if I have these lines: 1 some text (foo) some other text 2 some text (bar) some ...
user avatar
  • 382