Jaa


Use the Databricks notebook and file editor

This page describes some functions available with the Databricks notebook and file editor, including code suggestions and autocomplete, variable inspection, code folding, and side-by-side diffs. When you use the notebook or the file editor, Databricks Assistant is available to help you generate, explain, and debug code. See Use Databricks Assistant for details.

You can choose from a selection of editor themes. Select View > Editor theme and make a selection from the menu.

Personalized 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. Databricks uses your Unity Catalog metadata and usage to personalize suggestions.

  • 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 when 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.2 LTS or above.

how to inspect a variable

See Variable explorer

Go to definition

When a Python notebook is attached to a cluster, you can quickly go to the definition of a variable, function, or the code behind a %run statement. To do this, right-click the variable or function name, and then click Go to definition or Peek definition.

Hold down the Cmd key on macOS or the Ctrl key on Windows and hover over the variable or function name. If a definition is found, the name turns into a hyperlink.

how to get function definitions

The “go to definition” feature is available in Databricks Runtime 12.2 LTS and above.

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 vertically aligned cursors 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 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 vertically aligned cursors 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

Python error highlighting

When a notebook is connected to a cluster, syntax errors are underlined in red. For Python, the cluster must be running Databricks Runtime 12.2 LTS or above.

Hover the syntax warning and select Quick Fix for possible actions.

example for code actions on syntax error highlighting

Workspaces with Databricks Assistant enabled can also select Fix with Assistant for AI-assisted suggestions.

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

  1. Click your username at the upper-right of the workspace, then click 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.

Python formatting highlighting

Python code formatting errors and warnings are underlined in yellow. Hover over the syntax warnings to see more information. The cluster must be running Databricks Runtime 12.1 LTS or above.

To enable formatting errors and warnings:

  1. Click your username at the upper-right of the workspace, then click Settings in the dropdown list.
  2. In the Settings sidebar, select Developer.
  3. In the Experimental features section, toggle the setting for Python format error highlighting