Use the Databricks notebook and file editor

This page describes some of the functions available with the Databricks notebook and file editor, including code suggestions and autocomplete, variable inspection, code folding, and side-by-side diffs.

Autocomplete

Autocomplete automatically completes code segments as you type them. Completable objects include types, classes, and objects, as well as SQL database and table names.

  • For Python cells, the notebook must be attached to a cluster for autocomplete to work, and you must run all cells that define completable objects.

  • For SQL cells, autocomplete suggests keywords and basic syntax even if the notebook is not attached to any compute resource.

    • If the workspace is enabled for Unity Catalog, autocomplete also suggests catalog, schema, table, and column names for tables in Unity Catalog.

    • If the workspace is not enabled for Unity Catalog, the notebook must be attached to a cluster or a SQL warehouse to suggest table or column names.

Autocomplete suggestions automatically appear you type in a cell. Use the up and down arrow keys or your mouse to select a suggestion, and press Tab or Enter to insert the selection into the cell.

Note

Server autocomplete in R notebooks is blocked during command execution.

There are two user settings to be aware of:

  • To turn off autocomplete suggestions, toggle Autocomplete as you type. When autocomplete is off, you can display autocomplete suggestions by pressing Ctrl + Space.

  • To prevent Enter from inserting autocomplete suggestions, toggle Enter key accepts autocomplete suggestions.

Variable inspection

To display information about a variable defined in a SQL or Python notebook, hover your cursor over the variable name. Python variable inspection requires Databricks Runtime 12.0 or above.

how to inspect a variable

Go to definition

In Databricks Runtime 12.2 LTS and above, when a Python notebook is attached to a cluster, you can automatically navigate to the definition of a variable or function that is defined in that notebook. To do so, hold down the Cmd key on macOS or Ctrl key on Windows and hover the cursor over the name of the variable or function. The name turns into a hyperlink and changes to underlined blue text if the definition is found. When you click the link, the cursor moves to the code that defines the variable or function.

You can also use the keyboard shortcuts Cmd+F12 on macOS or Ctrl+F12 on Windows.

Code folding

Code folding lets you temporarily hide sections of code. This can be helpful when working with long code blocks because it lets you focus on specific sections of code you are working on.

To hide code, place your cursor at the far left of a cell. Downward-pointing arrows appear at logical points where you can hide a section of code. Click the arrow to hide a code section. Click the arrow again (now pointing to the right) to show the code.

how to fold code

For more details, including keyboard shortcuts, see the VS Code documentation.

Multicursor support

You can create multiple cursors to make simultaneous edits easier, as shown in the video:

how to use multiple cursors

To create multiple cursors in a cell:

  • On macOS, hold down the Option key and click in each location to add a cursor.

  • On Windows, hold down the Alt key and click in each location to add a cursor.

  • You also have the option to change the shortcut. See Change shortcut for multicursor and column selection.

On macOS, you can create multiple cursors that are vertically aligned by using the keyboard shortcut Option+Command+ up or down arrow key.

Column (box) selection

To select multiple items in a column, click at the upper left of the area you want to capture. Then:

  • On macOS, press Shift + Option and drag to the lower right to capture one or more columns.

  • On Windows, press Shift + Alt and drag to the lower right to capture one or more columns.

  • You also have the option to change the shortcut. See Change shortcut for multicursor and column selection.

how to select columns

Change shortcut for multicursor and column selection

An alternate shortcut is available for multicursor and column (box) selection. With the alternate selection, the shortcuts change as follows:

  • To create multiple cursors in a cell:

    • On macOS, hold down the Cmd key and click in each location to add a cursor.

    • On Windows, hold down the Ctrl key and click in each location to add a cursor.

  • To select multiple items in a column, click at the upper left of the area you want to capture. Then:

    • On macOS, press Option and drag to the lower right to capture one or more columns.

    • On Windows, press Alt and drag to the lower right to capture one or more columns.

To enable the alternate shortcuts, do the following:

  1. Click your username at the upper-right of the workspace, then click User settings in the dropdown list.

  2. In the Settings sidebar, select Developer.

  3. In the Code editor section, change the Key modifier for multi-cursor click setting to Cmd for macOS or Ctrl for Windows.

When you enable alternate shortcuts, the keyboard shortcut for creating multiple cursors that are vertically aligned does not change.

Bracket matching

When you click near a parenthesis, square bracket, or curly brace, the editor highlights that character and its matching bracket.

show the corresponding bracket

Side-by-side diff in version history

When you display previous notebook versions, the editor displays side-by-side diffs with color highlighting.

show the code diffs

Syntax error highlighting

When a notebook is connected to a cluster, syntax errors are highlighted by a squiggly red line. For Python, the cluster must be running Databricks Runtime 12.1 or above.

example of syntax error higlighting

To enable or disable syntax error highlighting, do the following:

  1. Click your username at the upper-right of the workspace, then click User settings in the dropdown list.

  2. In the Settings sidebar, select Developer.

  3. In the Code editor section, toggle the setting for SQL syntax error highlighting or Python syntax error highlighting.