CSV validator, highlighter and formatter plugin for JetBrains Intellij IDEA, PyCharm, WebStorm, ...
Compatible with IntelliJ IDEA PhpStorm WebStorm PyCharm RubyMine AppCode CLion Gogland DataGrip Rider MPS Android Studio - 2017.3.1 and newer
This plugin introduces CSV (Comma-Separated Values) as a language to Jetbrains IDE with a syntax definition, structured language elements and associated file types (.csv/.tsv/.psv). This enables default editor features like syntax validation, highlighting and inspections for CSV-alike files.
(see full changelog)
Starting with CSV Plugin 2.10.0, new features will only be developed for IntelliJ IDE 2019.3 and higher. I will still release patches for major/critical bugs for previous IDE versions 2017.3.1 - 2019.2.*, but no additional features or cosmetic fixes.
Starting with CSV Plugin 2.11.0, Java 9 (53) or higher is required. Previous versions can be downloaded and installed manually from the following locations: GitHub Releases, Plugin Repository (see also section Installation).
Starting with CSV Plugin 2.14.0, Java 11 (55) or higher is required. Previous versions can be downloaded and installed manually from the following locations: GitHub Releases, Plugin Repository (see also section Installation).
The CSV syntax parser follows the standard defined in IETF 4180 but tolerates leading and trailing whitespaces of escaped text and accepts basically every literal as text data. This results in a less restrictive checks and contributes to the flexibility of this format. The goal of the plugin is to support editing files in CSV format, not introducing new hurdles.
Being strict, the following CSV snippet is actually incorrect cause of the leading whitespaces. However, it is accepted by the plugins syntax parser implementation:
"firstName", "lastName", "birthday"
Besides the mentioned diversion from the standard definition, syntax errors will be detected and can be inspected. Please note that if a document is syntactically incorrect, other features like code formatting or the structure view can not function properly.
CSV files provide a high degree of flexibility and can be used universally for all kind of data. This led to a variety of CSV derivatives like semicolon or pipe separated values, which share the common format but make use of a different separator.
The plugin supports file-specific separator settings. Predefined separators, like Comma (,), semicolon (;), colon (:), tab (↹) and pipe (|), come with a precompiled lexer providing the best performance for working with CSV.
Since version 2.11.0, this plugin additionally comes with a runtime lexer implementation to support freely chosen separator.
A different separator can be chosen for each CSV file.
Additionally, the file types TSV (Tab-Separated-Values) and PSV (Pipe-Separated-Values) were introduced as a kind of CSV language. For TSV and PSV files the same formatter and code style settings are applied as for CSV itself, but the separator is considered to be a tab or a pipe respectively. All functionality that is available for plain CSV files (inspections, intentions, structure view, etc.) can be used for TSV and PSV as well.
The plugin provides editing of CSV files via a table editor since version 2.0.0. This editor is NOT related to the Edit as table... functionality of IntelliJ IDEA Ultimate/PhpStorm/DataGrip/etc. and does not share any implementation or settings. It is a an alternative to the CSV text editor and not meant to replace or mirror the capabilities of the Jetbrains "Data" tab.
!!! IMPORTANT !!!
The table editor requires a syntactically correct formatted CSV file. If the file can't be parsed, the table editor will be not available. The file needs to be fixed first via a text editor before it can be viewed and edited in the table editor.
Using the table editor might change the format of the CSV file: Until version 2.1.0 all fields were surrounded by double quotes and any spaces that are not part of the content was removed! Since version 2.1.0 the default changed but the described behavior can still be enabled (see Editor Settings -> Enforce value quoting).
The table editor comes with a custom undo/redo feature (the arrows in the upper right corner) to keep general track of changes to the table (add, remove, edit rows/columns). For text changes within a single cell, the default undo/redo functionality can be used.
A right-click within the table provides a context menu to add/remove rows, right-click on the table header to add/remove columns.
Please note that the actions within the context menu are meant for the current selection of row(s) and column(s), not necessarily for the cell or header where the context menu appears! A right-click does not trigger a selection change by default.
To support working with the table editor fluently, a set of key bindings are available for manipulating and navigating the table view:
The plugin introduces an enhanced text editor supporting custom settings - and a table editor. The settings for those can be adjusted in the corresponding CSV/TSV editor settings menu.
The preferred editor usage can be switched between "Text Editor first", "Table Editor first" or "Text Editor only", which has an effect on the editor tab order (or whether the table editor is shown at all). A "Table Editor only" option is not available (mainly due to the table editor restrictions when handling erroneous CSV files).
The following separators are currently supported: , (Comma), ; (Semicolon), : (Colon), | (Pipe) and ↹ (Tab)
Default Value Separator defines which separator is used as standard for each newly opened CSV file. The separator character can be changed for each file individually in its editors context menu.
This option has no effect on TSV/PSV files, the separator is pre-defined by their file- and language-type.
The following escape characters are currently supported: " (Double Quote), *\* (Backslash)
Within quoted values (fields starting and ending with a double quote), the double quote character must be escaped to be parsed as part of its value and not to be treated as the closing quote.
Default Escape Character defines which escape character is used as standard for each newly opened CSV/TSV/PSV file. The escape character can be changed for each file individually in its editors context menu.
Define the character(s) that should be used to mark a line as a comment within a CSV document.
Enable zero-based column numbering. This affects the tooltip info of the text editor as well as column numbering of the table editor.
Choose the coloring method of values. Possible options are:
All colors can be adjusted via CSV Color Scheme settings.
The highlighting of the current caret row might interfere with custom background color settings and can be enabled/disabled for CSV/TSV/PSV files here.
Enable/disable highlighting (and choose the highlight color) of tab characters (↹) in their role as value separator (TSV). Tabs as part of a value are therefore not highlighted on purpose.
Enable/disable the info balloon that appears at the caret position in the text editor.
Set whether soft wrapping should be activated for CSV/TSV/PSV. It still can be changed file specific with right-click on the editors left outer margin.
If enabled, it overrides the default editor settings for trailing whitespace handling to always keep them when editing CSV/TSV/PSV.
Note: This setting has no effect on the table editor. Unquoted values will always be trimmed when opening the table editor. When edited in the table editor, values ending or starting with whitespace will be quoted.
Defines how many lines of text are shown in one editor cell by default. Auto does recalculate the height on the fly that can cause some flickering while editing. This setting can be changed in the table editor itself per file.
The default and initial width of a single table column in px.
The maximum width of a single table column in px, which is used when adjusting the column widths automatically. 0 deactivates the limitation. This value has no effect when sizing the columns manually in the table editor.
If selected, the table column widths are adjusted based on the column contents automatically when the table editor is opened. This setting can be changed in the table editor itself per file.
If selected, the first record of CSV files will be considered the header per default, which affects the column names in the table editor. This setting can be changed in the table editor itself per file.
If the file ends with a completely empty line (no spaces or tabs either), the table editor will not show this line as empty values but ignore it. When table data is serialized, an existing empty line is kept at the end of the file.
Enables/disables the info panel at the bottom of the table editor.
Always quotes a single value on save - even if not required.
The different symbols of a CSV document, namely the separator (e.g. comma, pipe, semicolon), the quote character, the escaped literals and the text elements itself, are colored based on the CSV color scheme settings:
Preset colors are based on Jetbrains IDE defaults and support the different UI themes.
Besides the colors and font-style variants for the different CSV symbols, additionally up to 10 different column colors can be defined. Those colors are applied to the columns round robin. Column colors are taken into account when Rainbow is selected as Value Coloring option in the Editor Settings.
Formatting CSV is tricky: On one hand it is easy cause the language has only four different symbols and is generally easy to handle. On the other hand, formatting elements like whitespaces and tabs do have a meaning in CSV. However, in reality when parsing CSV, the leading and trailing whitespaces are quite often ignored or trimmed. Formatting can be completely disabled if no option is selected at all at the settings screen.
The formatting is applied to CSV documents as normal code formatting:
The formatting examples are based on the following CSV snippet as input:
"name", "city", "position" Annasusanna,Amsterdam,1 Ben , Berlin , 2
Adjust spacing around the separator.
Space before separator
"name" , "city" , "position" Annasusanna ,Amsterdam ,1 Ben , Berlin , 2
Space after separator
"name", "city", "position" Annasusanna, Amsterdam, 1 Ben , Berlin , 2
Trimming can be combined with Space before/after separator.
Trim leading whitespaces
"name","city","position" Annasusanna,Amsterdam,1 Ben ,Berlin ,2
Trim trailing whitespaces
"name", "city", "position" Annasusanna,Amsterdam,1 Ben, Berlin, 2
Separator settings can be used in combination with Tabularize enabled, while trimming options are ignored completely.
"name ","city ","position" Annasusanna,Amsterdam,1 Ben ,Berlin ,2
Trimming/spacing outside quotes
"name" ,"city" ,"position" Annasusanna,Amsterdam,1 Ben ,Berlin ,2
" name"," city","position" Annasusanna,Amsterdam, 1 Ben, Berlin, 2
Trimming/spacing outside quotes & Leading whitespaces
"name", "city","position" Annasusanna,Amsterdam, 1 Ben, Berlin, 2
The action to switch the value separator (or escape character) - which is used for CSV syntax validation of a specific file - is part of its editors context menu. Since version 2.11.0, also custom separator setting is available via this action.
Please note: This action defines how the parser/validator/highlighter/etc. behaves. It does intentionally not change the file content. To be more precise: It does not replace previous separator/escape characters by new ones or adjust the escaped texts.
Calculates and sets the maximum width for all table columns based on their content. The maximum table column width can be changed via Editor Settings.
Set the width of all table columns back to default. The default table column width can be changed via Editor Settings.
Inspections are an IDE feature that can be used to fix syntax errors. They are accessed via Alt+Enter when the cursor is at an erroneous position. The plugin provides three types of inspections:
Intentions are similar to inspections and provide a quick way to automatically adjust the document. They are accessed via Alt+Enter at any time. The shown intentions can vary depending on the cursor position within the document. The plugin provides six types of intentions:
The structure view shows the first line of the currently opened CSV file as header. Expanding a header entry shows all entries in this column.
Install it from the Jetbrains plugin repository within your IDE (recommended):
Since version 2.14.0, the plugins requires the IntelliJ platform to be executed on JRE11 or higher. If this is not the case, the following error log can be noticed:
com.intellij.diagnostic.PluginException: While loading class net.seesharpsoft.intellij.plugins.csv.CsvFileTypeOverrider: net/seesharpsoft/intellij/plugins/csv/CsvFileTypeOverrider has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0 [Plugin: net.seesharpsoft.intellij.plugins.csv]
In some cases the error log doesn't seem to point this out in a noticeable manner, but the IDE doesn't work correctly after enabling the plugin. Always disable the plugin first before continuing with the following steps.
If another plugin for CSV files like Rainbow CSV is enabled, this plugin might not be taken into account for parsing and presenting CSV file content.
Contributions are welcome. Please check CONTRIBUTING.md for more information.
Besides source code contributions, feel free to open bug reports or just suggest new features here.
JetBrains Plugin Repository Link: https://plugins.jetbrains.com/plugin/10037-csv-plugin