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.

Pavol Kutaj
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!
Sorting numerically with VIM plugin in VSCode by bash ā€˜sortā€™ command in Visual Line Mode.

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 the sort command.
  • The -n flag tells sort 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:

LINKS

--

--

Pavol Kutaj

Today I Learnt | Infrastructure Support Engineer at snowplow.io with a passion for cloud infrastructure/terraform/python/docs. More at https://pavol.kutaj.com