ctrl+shift+p filters: :st2 :st3 :win :osx :linux


by mechatroner ST3

🌈CSV - Sublime Text Package: Highlight columns in CSV and TSV files and run queries in SQL-like language

Labels csv, tsv, highlight



  • Total 15K
  • Win 7K
  • Mac 6K
  • Linux 3K
Aug 3 Aug 2 Aug 1 Jul 31 Jul 30 Jul 29 Jul 28 Jul 27 Jul 26 Jul 25 Jul 24 Jul 23 Jul 22 Jul 21 Jul 20 Jul 19 Jul 18 Jul 17 Jul 16 Jul 15 Jul 14 Jul 13 Jul 12 Jul 11 Jul 10 Jul 9 Jul 8 Jul 7 Jul 6 Jul 5 Jul 4 Jul 3 Jul 2 Jul 1 Jun 30 Jun 29 Jun 28 Jun 27 Jun 26 Jun 25 Jun 24 Jun 23 Jun 22 Jun 21 Jun 20 Jun 19
Windows 12 3 7 10 14 14 17 18 3 3 10 17 10 19 20 7 6 12 24 22 20 25 12 5 16 15 24 19 23 13 4 9 19 16 10 12 5 8 10 11 9 13 16 6 6 15
Mac 8 4 5 9 17 10 15 13 2 6 10 12 14 13 12 7 2 16 11 9 9 17 2 4 10 18 11 9 15 11 2 9 8 10 14 13 1 7 9 13 8 9 19 2 2 14
Linux 4 3 3 4 9 6 2 7 2 2 4 8 10 5 6 11 7 5 7 7 15 5 3 5 3 1 11 3 6 3 4 4 4 3 6 7 3 1 4 5 5 9 3 3 1 8




Rainbow CSV

Main features

  • Highlight columns in *.csv, *.tsv and other separated files in different rainbow colors.
  • Provide info about columns on mouse hover.
  • Check consistency of CSV files (CSVLint)
  • Align columns with spaces and Shrink (trim spaces from fields)
  • Execute SQL-like RBQL queries.



Rainbow CSV has content-based csv/tsv autodetection mechanism. This means that the package will analyze plain text files even if they do not have “.csv” or “.tsv” extension.

Rainbow highlighting can also be manually enabled from Sublime context menu (see the demo gif below):
1. Select a character (or sequence of characters) that you want to use as a delimiter with the cursor 2. Right mouse click: context menu -> Rainbow CSV -> Enable …

You can also disable rainbow highlighting and go back to the original file highlighting using the same context menu.
This feature can be used to temporarily rainbow-highlight even non-table files.

Manual Rainbow Enabling/Disabling demo gif:

Rainbow CSV also lets you execute SQL-like queries in RBQL language, see the demo gif below:
demo gif

To Run RBQL query press F5 or select “Rainbow CSV” -> “Run RBQL query” option from the file context menu.

Key mappings

Key Action
F5 Start query editing for the current CSV file


Rainbow CSV: Enable Simple

Before running the command you need to select the separator (single or multiple characters) with your cursor Set the selected character as the separator and enables syntax highlighting. Sublime will generate the syntax file if it doesn't exist. Simple dialect completely ignores double quotes: i.e. separators can not be escaped in double quoted fields

Rainbow CSV: Enable Standard

Same as the Enable Simple command, but separators can be escaped in double quoted fields.

Rainbow CSV: CSVLint

The linter checks the following:
* consistency of double quotes usage in CSV rows
* consistency of number of fields per CSV row

Rainbow CSV: Run RBQL query

Run RBQL query for the current file.
Unlike F5 button it will work even if the current file is not a CSV table: in this case only 2 variables “a1” and “NR” will be available.

Rainbow CSV: Align CSV columns with spaces

Align CSV columns with spaces in the current file

Rainbow CSV: Shrink CSV table

Remove leading and trailing spaces from all fields in the current file


To adjust plugin configuration:
1. Go to “Preferences” -> “Package Settings” -> “Rainbow CSV” -> “Settings”.
2. On the right side change the settings like you'd like.

Configuration parameters

To configure the extension, click “Preferences” -> “Package Settings” -> “Rainbow CSV” -> “Settings”


Enable content-based separator autodetection. Files with “.csv” and “.tsv” extensions are always highlighted no matter what is the value of this option.


List of CSV dialects to autodetect.
If “enable_rainbow_csv_autodetect” is set to false this setting is ignored


Disable Rainbow CSV for files bigger than the specified size. This can be helpful to prevent poor performance and crashes with very large files.
Manual separator selection will override this setting for the current file.
E.g. to disable on files larger than 100 MB, set "rainbow_csv_max_file_size_bytes": 100000000


Use custom high-contrast rainbow colors instead of colors provided by your current color scheme


Auto adjust rainbow colors for Packages/User/RainbowCSV.sublime-color-scheme
Rainbow CSV will auto-generate color theme with high-contrast colors to make CSV columns more distinguishable.
You can disable this setting and manually customize Rainbow CSV color scheme at Packages/User/RainbowCSV.sublime-color-scheme
Do not customize Packages/User/RainbowCSV.sublime-color-scheme without disabling the setting, it will be rewritten by the plugin
This option has effect only if “use_custom_rainbow_colors” is set to true


RBQL backend language.
Supported values: “Python”, “JS”
To use RBQL with JavaScript (JS) you need to have Node JS installed and added to your system path.


Format of RBQL result set tables.
Supported values: “tsv”, “csv”, “input”
* input: same format as the input table * tsv: tab separated values. * csv: is Excel-compatible and allows quoted commas.

Example: to always use “tsv” as output format add this line to your settings file: "rbql_output_format": "tsv",


RBQL encoding for files and queries.
Supported values: “latin-1”, “utf-8”


  • This Sublime Text plugin is an adaptation of Vim's rainbow_csv plugin

RBQL (Rainbow Query Language) Description

RBQL is a technology for (not only) CSV file processing. It provides SQL-like language that supports SELECT queries with Python or JavaScript expressions.
RBQL is distributed with CLI apps, text editor plugins, Python and JS libraries and can work in web browsers.
RBQL core module is very generic and can process all kinds of objects and record formats, but the most popular RBQL implementation works with CSV files.

Official Site

Main Features

  • Use Python or JavaScript expressions inside SELECT, UPDATE, WHERE and ORDER BY statements
  • Result set of any query immediately becomes a first-class table on its own
  • Supports input tables with an inconsistent number of fields per record
  • Output records appear in the same order as in input unless ORDER BY is provided
  • Each record has a unique NR (record number) identifier
  • Supports all main SQL keywords
  • Supports aggregate functions and GROUP BY queries
  • Provides some new useful query modes which traditional SQL engines do not have
  • Supports both TOP and LIMIT keywords
  • Supports user-defined functions (UDF)
  • Works out of the box, no external dependencies


  • RBQL doesn't support nested queries, but they can be emulated with consecutive queries
  • Number of tables in all JOIN queries is always 2 (input table and join table), use consecutive queries to join 3 or more tables

Supported SQL Keywords (Keywords are case insensitive)

  • ORDER BY … [ DESC | ASC ]
  • TOP N

All keywords have the same meaning as in SQL queries. You can check them online

RBQL variables

RBQL for CSV files provides the following variables which you can use in your queries:

  • a1, a2,…, a{N}
    Variable type: string
    Description: value of i-th field in the current record in input table
  • b1, b2,…, b{N}
    Variable type: string
    Description: value of i-th field in the current record in join table B
  • NR
    Variable type: integer
    Description: Record number (1-based)
  • NF
    Variable type: integer
    Description: Number of fields in the current record
  • a.name, b.Person_age, … a.{Good_alphanumeric_column_name}
    Variable type: string
    Description: Value of the field referenced by its “name”. You can use this notation if the field in the first (header) CSV line has a “good” alphanumeric name
  • a[“object id”], a['9.12341234'], b[“%$ !! 10 20”]a[“Arbitrary column name!”]
    Variable type: string
    Description: Value of the field referenced by its “name”. You can use this notation to reference fields by arbitrary values in the first (header) CSV line, even when there is no header at all


  • You can mix all variable types in a single query, example:

select a1, b2 JOIN /path/to/b.csv ON a['Item Id'] == b.Identifier WHERE NR > 1 and int(a.Weight) * 100 > int(b["weight of the item"]) * Referencing fields by header names does not automatically skip the header line (you can use where NR > 1 trick to skip it) * If you want to use RBQL as a library for your own app you can define your own custom variables and do not have to support the above mentioned CSV-related variables.

UPDATE statement

UPDATE query produces a new table where original values are replaced according to the UPDATE expression, so it can also be considered a special type of SELECT query. This prevents accidental data loss from poorly written queries.
UPDATE SET is synonym to UPDATE, because in RBQL there is no need to specify the source table.

Aggregate functions and queries

RBQL supports the following aggregate functions, which can also be used with GROUP BY keyword:

Limitation: aggregate functions inside Python (or JS) expressions are not supported. Although you can use expressions inside aggregate functions.
E.g. MAX(float(a1) / 1000) - valid; MAX(a1) / 1000 - invalid.
There is a workaround for the limitation above for ARRAY_AGG function which supports an optional parameter - a callback function that can do something with the aggregated array. Example:
select a2, ARRAY_AGG(a1, lambda v: sorted(v)[:5]) group by a2 - Python; select a2, ARRAY_AGG(a1, v => v.sort().slice(0, 5)) group by a2 - JS

JOIN statements

Join table B can be referenced either by its file path or by its name - an arbitrary string which the user should provide before executing the JOIN query.
RBQL supports STRICT LEFT JOIN which is like LEFT JOIN, but generates an error if any key in left table “A” doesn't have exactly one matching key in the right table “B”.
Limitation: JOIN statements can't contain Python/JS expressions and must have the following form: (/path/to/table.tsv | table_name ) ON a… == b… [AND a… == b… [AND … ]]


SELECT EXCEPT can be used to select everything except specific columns. E.g. to select everything but columns 2 and 4, run: SELECT * EXCEPT a2, a4
Traditional SQL engines do not support this query mode.

UNNEST() operator

UNNEST(list) takes a list/array as an argument and repeats the output record multiple times - one time for each value from the list argument.
Example: SELECT a1, UNNEST(a2.split(';'))

LIKE() function

RBQL does not support LIKE operator, instead it provides “like()” function which can be used like this: SELECT * where like(a1, 'foo%bar')

User Defined Functions (UDF)

RBQL supports User Defined Functions
You can define custom functions and/or import libraries in two special files:
* ~/.rbql_init_source.py - for Python * ~/.rbql_init_source.js - for JavaScript

Examples of RBQL queries

With Python expressions

  • select top 100 a1, int(a2) * 10, len(a4) where a1 == "Buy" order by int(a2) desc
  • select * order by random.random() where NR > 1 - skip header record and random sort
  • select len(a.vehicle_price) / 10, a2 where NR > 1 and a['Vehicle type'] in ["car", "plane", "boat"] limit 20 - referencing columns by names from header record, skipping the header and using Python's “in” to emulate SQL's “in”
  • update set a3 = 'NPC' where a3.find('Non-playable character') != -1
  • select NR, * - enumerate records, NR is 1-based
  • select * where re.match(".*ab.*", a1) is not None - select entries where first column has “ab” pattern
  • select a1, b1, b2 inner join ./countries.txt on a2 == b1 order by a1, a3 - example of join query
  • select MAX(a1), MIN(a1) where a.Name != 'John' group by a2, a3 - example of aggregate query
  • select *a1.split(':') - Using Python3 unpack operator to split one column into many. Do not try this with other SQL engines!

With JavaScript expressions

  • select top 100 a1, a2 * 10, a4.length where a1 == "Buy" order by parseInt(a2) desc
  • select * order by Math.random() where NR > 1 - skip header record and random sort
  • select top 20 a.vehicle_price.length / 10, a2 where NR > 1 and ["car", "plane", "boat"].indexOf(a['Vehicle type']) > -1 limit 20 - referencing columns by names from header record and skipping the header
  • update set a3 = 'NPC' where a3.indexOf('Non-playable character') != -1
  • select NR, * - enumerate records, NR is 1-based
  • select a1, b1, b2 inner join ./countries.txt on a2 == b1 order by a1, a3 - example of join query
  • select MAX(a1), MIN(a1) where a.Name != 'John' group by a2, a3 - example of aggregate query
  • select ...a1.split(':') - Using JS “destructuring assignment” syntax to split one column into many. Do not try this with other SQL engines!


How do I skip the header record in a CSV file?

You can use the following trick: add ... where NR > 1 ... to your query

And if you are doing math operation you can modify your query like this, example:
select int(a3) * 1000, a2 -> select int(a3) * 1000 if NR > 1 else a3, a2

How does RBQL work?

RBQL parses SQL-like user query, generates new Python or JavaScript code and executes it.

Explanation of simplified Python version of RBQL algorithm by example:

  1. The user enters the following query, which is stored as a string Q
    “ SELECT a3, int(a4) + 100, len(a2) WHERE a1 != 'SELL'
2. RBQL replaces all `a{i}` substrings in the query string _Q_ with `a[{i - 1}]` substrings. The result is the following string:
Q = "SELECT a[2], int(a[3]) + 100, len(a[1]) WHERE a[0] != 'SELL'"
3. RBQL searches for "SELECT" and "WHERE" keywords in the query string _Q_, throws the keywords away, and puts everything after these keywords into two variables _S_ - select part and _W_ - where part, so we will get:
S = "a[2], int(a[3]) + 100, len(a[1])"
W = "a[0] != 'SELL'"
4. RBQL has static template script which looks like this:
for line in sys.stdin:
    a = line.rstrip('\n').split(',')
    if %%%W_Expression%%%:
        out_fields = [%%%S_Expression%%%]
        print ','.join([str(v) for v in out_fields])
5. RBQL replaces `%%%W_Expression%%%` with _W_ and `%%%S_Expression%%%` with _S_ so we get the following script:
for line in sys.stdin:
    a = line.rstrip('\n').split(',')
    if a[0] != 'SELL':
        out_fields = [a[2], int(a[3]) + 100, len(a[1])]
        print ','.join([str(v) for v in out_fields])
6. RBQL runs the patched script against user's data file (real RBQL implementation calls "exec" in Python or "eval" in JS):
./tmp_script.py < data.tsv > result.tsv
Result set of the original query (`SELECT a3, int(a4) + 100, len(a2) WHERE a1 != 'SELL'`) is in the "result.tsv" file.  
Adding support of TOP/LIMIT keywords is trivial and to support "ORDER BY" we can introduce an intermediate array.  

### References

#### Rainbow CSV and similar plugins in other editors:

* Rainbow CSV extension in [Vim](https://github.com/mechatroner/rainbow_csv)
* Rainbow CSV extension in [Visual Studio Code](https://marketplace.visualstudio.com/items?itemName=mechatroner.rainbow-csv)
* rainbow-csv package in [Atom](https://atom.io/packages/rainbow-csv)
* rainbow_csv plugin in [gedit](https://github.com/mechatroner/gtk_gedit_rainbow_csv) - doesn't support quoted commas in csv
* rainbow_csv_4_nedit in [NEdit](https://github.com/DmitTrix/rainbow_csv_4_nedit)
* CSV highlighting in [Nano](https://github.com/scopatz/nanorc)
* Rainbow CSV in [IntelliJ IDEA](https://plugins.jetbrains.com/plugin/12896-rainbow-csv/)

#### RBQL:

* [RBQL: Official Site](https://rbql.org/)
* RBQL is integrated with Rainbow CSV extensions in [Vim](https://github.com/mechatroner/rainbow_csv), [VSCode](https://marketplace.visualstudio.com/items?itemName=mechatroner.rainbow-csv), [Sublime Text](https://packagecontrol.io/packages/rainbow_csv) and [Atom](https://atom.io/packages/rainbow-csv) editors.
* [RBQL in npm](https://www.npmjs.com/package/rbql): `$ npm install -g rbql`
* [RBQL in PyPI](https://pypi.org/project/rbql/): `$ pip install rbql`