How to Sort (numbers) with Vim in VSCode
The aim of this pageš is to explain how to sort a list of integers in Vim for VSCODE using bash sort
command, something I need sometimes when working with small dataset/markdown tables.
1 min readFeb 5, 2024
- Select a range in Visual Mode
- Press
:
to enter Vim command line - Type
!sort -nr
to sort the selected range numerically in decreasing order - Done!
On Sorting a List of Integers in Bash
- Bash provides the
sort
command to sort a list of integers. - By default,
sort
performs a lexicographical sort, which does give the desired result for numbers. - To sort a list of integers numerically, use the
-n
flag with thesort
command. - The
-n
flag tellssort
to perform a numerical sort. - To sort the list in decreasing order, use the
-r
flag along with the-n
flag. - The
-r
flag reverses the order of the sorting. - Hereās an example of sorting a list of integers in bash: