Questions tagged [sort]

Vim command for sorting a set of lines.

Filter by
Sorted by
Tagged with
12
votes
1answer
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 ...
10
votes
1answer
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-...
9
votes
2answers
484 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....
7
votes
2answers
673 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?
6
votes
1answer
1k 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 ...
5
votes
3answers
757 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: \...
5
votes
1answer
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 ...
5
votes
1answer
236 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 \...
4
votes
2answers
659 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 ...
4
votes
1answer
868 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>...
4
votes
1answer
925 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 ...
3
votes
2answers
225 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:
3
votes
1answer
614 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?
3
votes
2answers
52 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\{/...
3
votes
1answer
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 : ...
2
votes
2answers
55 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 ...
2
votes
2answers
60 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 ...
2
votes
2answers
287 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 ...
2
votes
1answer
39 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) ...
2
votes
1answer
397 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 ...
2
votes
2answers
54 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 ...
1
vote
3answers
83 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 ...
1
vote
1answer
218 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/ | ...
1
vote
1answer
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: ...
1
vote
1answer
38 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 ...
1
vote
1answer
245 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 ...
1
vote
0answers
36 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', ...
1
vote
0answers
132 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": ...
0
votes
2answers
60 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?
0
votes
1answer
71 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 ...
0
votes
1answer
124 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&...
0
votes
0answers
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, ...