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:
To Run RBQL query press F5 or select "Rainbow CSV" -> "Run RBQL query" option from the file context menu.
|Key | Action | |--------------------------|----------------------------------------------------| |F5 | Start query editing for the current CSV file |
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
Same as the Enable Simple command, but separators can be escaped in double quoted fields.
The linter checks the following:
consistency of double quotes usage in CSV rows
consistency of number of fields per CSV row
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.
Align CSV columns with spaces in the current file
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.
To configure the extension, click "Preferences" -> "Package Settings" -> "Rainbow CSV" -> "Settings"
Allow quoted multiline fields as defined in RFC-4180
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. When you enable this option, "auto_adjust_rainbow_colors" also gets enabled by default.
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
, you can use the following RainbowCSV.sublime-color-scheme file as a starting point for your customizations.
Do NOT manually customize Packages/User/RainbowCSV.sublime-color-scheme without disabling this setting, the plugin will just rewrite it in that case.
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.
Default: false
RBQL will treat first records in all input and join files as headers.
You can set this value to true if most of the CSV files you deal with have headers.
You can override this setting on the query level by either adding WITH (header)
or WITH (noheader)
to the end of the query.
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"
RBQL is an eval-based SQL-like query engine for (not only) CSV file processing. It provides SQL-like language that supports SELECT queries with Python or JavaScript expressions.
RBQL is best suited for data transformation, data cleaning, and analytical queries.
RBQL is distributed with CLI apps, text editor plugins, Python and JS libraries.
All keywords have the same meaning as in SQL queries. You can check them online
RBQL for CSV files provides the following variables which you can use in your queries:
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.
RBQL supports the following aggregate functions, which can also be used with GROUP BY keyword:
COUNT, ARRAY_AGG, MIN, MAX, SUM, AVG, VARIANCE, MEDIAN
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 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 the left table "A" doesn't have exactly one matching key in the right table "B".
Table B path can be either relative to the working dir, relative to the main table or absolute.
Limitation: JOIN statements can't contain Python/JS expressions and must have the following form:
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(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(';'))
RBQL does not support LIKE operator, instead it provides "like()" function which can be used like this:
SELECT * where like(a1, 'foo%bar')
You can set whether the input (and join) CSV file has a header or not using the environment configuration parameters which could be --with_headers
CLI flag or GUI checkbox or something else.
But it is also possible to override this selection directly in the query by adding either WITH (header)
or WITH (noheader)
statement at the end of the query.
Example: select top 5 NR, * with (header)
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
SELECT TOP 100 a1, int(a2) * 10, len(a4) WHERE a1 == "Buy" ORDER BY int(a2) DESC
SELECT a.id, a.weight / 1000 AS weight_kg
SELECT * ORDER BY random.random()
- random sortSELECT len(a.vehicle_price) / 10, a2 WHERE int(a.vehicle_price) < 500 and a['Vehicle type'] in ["car", "plane", "boat"] limit 20
- referencing columns by names from 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-basedSELECT * WHERE re.match(".*ab.*", a1) is not None
- select entries where first column has "ab" patternSELECT a1, b1, b2 INNER JOIN ./countries.txt ON a2 == b1 ORDER BY a1, a3
- example of join querySELECT MAX(a1), MIN(a1) WHERE a.Name != 'John' GROUP BY a2, a3
- example of aggregate querySELECT *a1.split(':')
- Using Python3 unpack operator to split one column into many. Do not try this with other SQL engines!SELECT TOP 100 a1, a2 * 10, a4.length WHERE a1 == "Buy" ORDER BY parseInt(a2) DESC
SELECT a.id, a.weight / 1000 AS weight_kg
SELECT * ORDER BY Math.random()
- random sortSELECT TOP 20 a.vehicle_price.length / 10, a2 WHERE parseInt(a.vehicle_price) < 500 && ["car", "plane", "boat"].indexOf(a['Vehicle type']) > -1 limit 20
- referencing columns by names from headerUPDATE SET a3 = 'NPC' WHERE a3.indexOf('Non-playable character') != -1
SELECT NR, *
- enumerate records, NR is 1-basedSELECT a1, b1, b2 INNER JOIN ./countries.txt ON a2 == b1 ORDER BY a1, a3
- example of join querySELECT MAX(a1), MIN(a1) WHERE a.Name != 'John' GROUP BY a2, a3
- example of aggregate querySELECT ...a1.split(':')
- Using JS "destructuring assignment" syntax to split one column into many. Do not try this with other SQL engines!$ npm install -g rbql
$ pip install rbql
Trying to change the colors manually inside RainbowCSV.sublime-color-scheme after setting use_custom_rainbow_colors
to true but it does not seem to have any effect, am i missing something?
Currently, multiline fields are only supported with commas and semicolons, see #20 for context.
https://github.com/mechatroner/sublime_rainbow_csv/blob/2da337da01cf472d85ccbfa91387915cda8d5a43/auto_syntax.py#L33
https://github.com/mechatroner/sublime_rainbow_csv/blob/2da337da01cf472d85ccbfa91387915cda8d5a43/auto_syntax.py#L47
Can these lines add a csv.
so that the format of the root scope
property in the generated .sublime-syntax
is text.csv.XXXX
? Then text.csv
will match all variants, and specific variants can still be targeted with text.csv.XXXX
.
I believe this would allow the package I use for sidebar icons to recognize the variants as text.csv
and apply the correct icon to them.
Sublime maps F5 to sort. But so does this plugin, and somehow now both are happening.
.../Sublime Text 3/Packages/Default/Default (OSX).sublime-keymap
{ "keys": ["f5"], "command": "sort_lines", "args": {"case_sensitive": false} },
{ "keys": ["ctrl+f5"], "command": "sort_lines", "args": {"case_sensitive": true} },
Can you pick a different key?
East Asian languages (such as Chinese, Japanese, and Korean) usually take up the size of two English characters. If you don’t deal with it specially, when you use the ‘align’ function, you may not be able to align it. The look and feel is bad. It is recommended to optimize it.
It would be nice to make query like:
SELECT a[2:4], a[6:8]
UPD if it possible to make query lile:
SELECT a['id':'name']
it will be great!
AS
keyword.RBQL can now parse and preserve CSV header names in the output table.
Fix separator colors and make them stick to the previous column instead of the next column see issue #31
sublime-text-plugin csv tsv syntax-highlighting sql sql-like