Text editor

Code formatting

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!

Adjust code style in Settings → Editor → Code Style → SQL where you can define if you capitalize keywords or not for example.

Multiple cursors

Multiple cursors are often the most efficient way to modify SQL code. To do this in DataGrip, press Ctrl twice and hold it, then place new cursors with the arrow keys. Or, hold Shift+Alt and 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.

Live templates

Use built-in live templates to generate repetitive parts of SQL code, and create custom templates for even greater efficiency. Press Ctrl+J to see all the Live Templates.

Every live template has its own abbreviate — just type it and press Tab to paste the whole part of the code.

For example, selw can be used for SELECT * FROM with WHERE

Local history

Each console or file has Local History so you will never lose your code. DataGrip tracks the changes made to your source files, protecting you from any accidental losses or modifications, even if they were made by other applications. Whenever you want to, you can inspect the history of a particular file or directory. Compare changes in the Diff Viewer and revert to the version you need.

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.

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.

Spell checking

In every editor, whether it is a data editor or query console, DataGrip checks the spelling of words: for the green wavy underlines, view the dictionary suggestions using Alt+EnterTypo: change to.... It even works for words written in camelCase!

Managing code pieces

Instead of doing all this copy-paste stuff for moving the blocks of code about, use the features of the editor.

Duplicate the line by pressing Ctrl+D.

Delete the line with Ctrl+Y.

Move the line with Ctrl+Shift+Arrow Keys.

All these hotkeys can be used for managing selected blocks of code as well.

The IntelliJ-based text editor offers rich functionality for navigating through source code. The most important features:

Navigate forward and back with Ctrl+Alt+Left/Right.

Navigate to the last edit location: Ctrl+Shift+Backspace.

Language injections

This feature lets you treat string literals as live code written in other languages (like XML, JSON, any 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 as such.
By default, there are only two predefined injection types: JSON and XML. However, it’s really simple to create your own injections: just press Alt+Enter and then select Inject By Type.

Dynamic SQL

If you want to have the injection whenever you edit a particular piece of code, comment it with “language=” like in the screenshot. In it is another important example of language injection — the use of Dynamic SQL that provides coding assistance for the injected fragment.

Toggling comments

Manage your code by toggling comments. Choose what type of comments you want to use—block or line-by-line (if it's supported by your SQL dialect).