The editor that comes with the IDE makes you highly productive when editing SQL or any other code.
The editor highlights your code automatically. You will always find the matching braces, find all usages of a symbol and never get confused by lots of subqueries and expressions. The statement which will be executed is highlighted as well, depending on the cursor position and console settings.
Multiple cursors are often the most efficient way to modify SQL code. To do this in DataGrip, press Alt twice and hold it, then place new cursors with the arrow keys. Or, hold Shift+Altand click to do the same. Or, use text search first and then place multiple cursors in all the places where matches have been found by choosing Select All Occurrences to the right of the search text field.
Smart code selection
Press Ctrl+W to run syntax-aware selection. First it will select the word under the caret. Press it again, and the selection will expand in a smart way as DataGrip analyzes the code being edited. This is the quickest way to select a particular clause or sub-query. To go in reverse, press Ctrl+Shift+W and the current selection will shrink.
Have your SQL code formatted automatically, based on flexible user-defined code styles. Don’t spend time formatting legacy code—let DataGrip do it for you with a single shortcut (Ctrl+Alt+L)!
This feature lets you treat string literals as live code written in other languages (like
SQL dialect or regular expressions), including formatting, highlighting,
usage search, completion, and even refactoring.
Language is auto-injected into a literal when DataGrip understands the type of the string
inside. For example, if you are working with values from
JSON columns, they will be treated
By default, there are only two predefined injection types:
XML. However, it’s
really simple to create your own injections: just press Alt+Enter and then select Inject By Type.
If you want to have the injection whenever you edit a particular piece of code, comment it
“language=” like on the screenshot. In it is another important example of language injection — the
use of DynamicSQL that provides coding assistance for the injected fragment.
Pasting from clipboard history
With DataGrip you can access your clipboard history and quickly paste any of the recent items copied to the clipboard. DataGrip starts recording copied items to its clipboard history as soon as you start the application and clears the history when you close it. To invoke this, press Ctrl+Shift+V
Managing code pieces
Instead of doing all this copy-paste stuff while moving the blocks of code, use the features of the editor. Duplicate the line pressing Ctrl+D, delete the line by Ctrl+Y and move the line by Shift+Ctrl+Arrow Keys. All these hotkeys can be used for managing selected blocks of code as well.
In every editor, whether it is a table editor or query console, DataGrip checks spelling of words — for green wavy underlines view the dictionary suggestions using Alt+Enter → Typo: change to...
Swap words around comma
Alt+Enter → Flip ',' to swap words around comma.
Manage your code by toggling comments. Choose what type of comments you want to use—block or line-by-line (if supported by your SQL dialect).
Column selection mode
Another type to select code. Column selection mode can be especially useful in SQL where repeating lines are rather common. It is available when you select with mouse and Alt pressed, or can be turned on by the Shift+Alt+Ins. Notice, that in column selection mode you also place multiple cursors.