Questions tagged [sort]

Vim command for sorting a set of lines.

Filter by
Sorted by
Tagged with
2
votes
1answer
29 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) ...
4
votes
3answers
252 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: \...
1
vote
1answer
26 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: ...
3
votes
1answer
14 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\{/...
0
votes
1answer
144 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 ...
1
vote
0answers
25 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', ...
3
votes
2answers
179 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
154 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 : ...
1
vote
0answers
61 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": ...
1
vote
3answers
54 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
188 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 ...
3
votes
2answers
356 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 ...
2
votes
2answers
247 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 ...
4
votes
1answer
784 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 ...
0
votes
1answer
113 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&...
3
votes
1answer
676 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>...
2
votes
1answer
312 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 ...
10
votes
1answer
799 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
465 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....
5
votes
1answer
145 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 \...
5
votes
2answers
549 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?
3
votes
1answer
399 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?
11
votes
1answer
2k 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 ...
4
votes
1answer
586 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 ...