Nushell
Get Nu!
Getting Started
  • The Nushell Book
  • Command Reference
  • Cookbook
  • Language Reference Guide
  • Contributing Guide
Blog
  • English
  • 中文
  • Deutsch
  • Français
  • Español
  • 日本語
  • Português do Brasil
  • Русский язык
  • 한국어
GitHub
Get Nu!
Getting Started
  • The Nushell Book
  • Command Reference
  • Cookbook
  • Language Reference Guide
  • Contributing Guide
Blog
  • English
  • 中文
  • Deutsch
  • Français
  • Español
  • 日本語
  • Português do Brasil
  • Русский язык
  • 한국어
GitHub
  • Introduction
  • Installation
    • Default Shell
  • Getting Started
    • Quick Tour
    • Moving Around the System
    • Thinking in Nu
    • Nushell Cheat Sheet
  • Nu Fundamentals
    • Types of Data
    • Loading Data
    • Data Formats
    • Working with SQLite
    • Pipelines
    • Working with Strings
    • Regular Expressions
    • Working with Binary Data
    • Working with Lists
    • Working with Records
    • Working with Numbers
    • Working with Tables
    • Working with Paths
    • Navigating and Accessing Structured Data
    • Special Variables
  • Programming in Nu
    • Custom Commands
    • Aliases
    • Operators
    • Variables
    • Control Flow
    • Scripts
    • Modules
      • Using Modules
      • Creating Modules
    • Overlays
    • Sorting
    • Testing your Nushell Code
    • Debugging Scripts
    • Language Server
    • Best Practices
  • Nu as a Shell
    • Configuration
    • Configuration Reference
    • Environment
    • Stdout, Stderr, and Exit Codes
    • Working with the Terminal
    • Running System (External) Commands
    • How to Configure 3rd Party Prompts
    • Directory Stack
    • Reedline, Nu's Line Editor
    • Custom Completions
    • Externs
    • Coloring and Theming in Nu
    • Hooks
    • Background Jobs
  • Coming to Nu
    • Coming from Bash
    • Coming from CMD.EXE
    • Coming from PowerShell
    • Nu map from other shells and domain specific languages
    • Nu Map from Imperative Languages
    • Nu Map from Functional Languages
    • Nushell operator map
  • Design Notes
    • How Nushell Code Gets Run
  • (Not So) Advanced
    • Standard Library
      • std/assert
      • std/bench
      • std/clip
      • std/config
      • std/dt
      • std/formats
      • std/help
      • std/input
      • std/iter
      • std/log
      • std/math
      • std/random
      • std/util
      • std/xml
      • std-rfc
    • Dataframes
      • Dataframe Operations
      • Column Selectors
      • Math Expressions
      • String Expressions
      • Dates and Times in Dataframes
      • Masks and Conditionals
      • Aggregations and Window Functions
    • Metadata
    • Creating Your Own Errors
    • Parallelism
    • Plugins
    • explore
    • Building TUIs with tui
    • MCP Server

Reedline, Nu's Line Editor

Nushell's line-editor Reedline is cross-platform and designed to be modular and flexible. The line-editor is in charge of controlling the command history, validations, completions, hints, the status line, screen paint, and more.

  • Multi-line Editing
  • Setting the Editing Mode
  • Default Keybindings
    • Keybindings Added by Nushell
    • Common Keybindings
    • The cut buffer
    • Emacs Mode
    • Vi Mode
    • Helix Mode
  • Command History
    • The history commands
    • Prefix search with the arrow keys
    • Reverse history search
  • Hints
  • Status Line
  • Customizing the Prompt
  • Keybindings
    • Send Type
    • Edit Type
    • Until Type
    • Changing the line from Nushell code
    • Removing a Default Keybinding
    • Troubleshooting Keybinding Problems
  • Menus
    • Menu Keybindings
    • Help Menu
    • Completion Menu
    • Ide Completion Menu
    • History Menu
    • User Defined Menus
    • Menu Keybindings
  • Abbreviations
  • Terminal integration
  • Event and edit reference
    • Events
    • Edit commands

Multi-line Editing

Reedline allows Nushell commandlines to extend across multiple lines. This can be accomplished using several methods:

  1. Pressing Enter when a bracketed expression is open.

    For example, you can type this command over three lines:

    def my-command [] {
      print "Hello from my-command"
    }

    Pressing Enter after the open-bracket will insert a newline instead of running the command. This will also occur with opening (and valid) ( and [ expressions.

    An unclosed string continues the same way. A line that ends inside a ", ', backtick or raw string gets a newline, and the newline becomes part of the string. Nushell parses the line, and when the first error it finds is that something is still open, Enter inserts a newline. Any other first error runs the line so that you see the error. That includes an extra closing bracket, as in echo (1 + 2)).

    This is commonly used to create blocks and closures (as above), but also list, record, and table literals:

    let file = {
      name: 'repos.sqlite'
      hash: 'b939a3fa4ca011ca1aa3548420e78cee'
      version: '1.4.2'
    }

    It can even be used to continue a single command across multiple lines:

    Example
    (
      tar
      -cvz
      -f archive.tgz
      --exclude='*.temp'
      --directory=../project/
      ./
    )
  2. Pressing Enter at the end of a line with a trailing pipe-symbol (|).

    ls                     |
    where name =~ '^[0-9]' | # Comments after a trailing pipe are okay
    get name               |
    mv ...$in ./backups/
  3. Manually insert a newline using Alt+Enter or Shift+Enter.

    This can be used to create a somewhat more readable version of the previous commandline:

    ls
    | where name =~ '^[0-9]'  # Files starting with a digit
    | get name
    | mv ...$in ./backups/

    Tips

    It's possible that one or both of these keybindings may be intercepted by the terminal application or window-manager. For instance, Windows Terminal (and most other terminal applications on Windows) assign Alt+Enter to expand the terminal to full-screen. If neither of the above keybindings work in your terminal, you can assign a different keybinding to the insertnewline edit (event: { edit: insertnewline }).

    See Edit Type below for an example, and Keybindings for more details.

  4. Pressing Ctrl+O opens the current commandline in your editor. Saving the resulting file and exiting the editor will update the commandline with the results.

    The editor is $env.config.buffer_editor if it's set, otherwise $env.VISUAL, otherwise $env.EDITOR (see Configuration). When none of them is set, or the program it names isn't found, Ctrl+O does nothing.

    To open the editor with the cursor where you left it, use the {file}, {line} and {col} placeholders described under buffer_editor:

    $env.config.buffer_editor = ["hx", "{file}:{line}:{col}"]
    $env.config.buffer_editor = ["vim", "+{line}"]   # cursor on line 2: vim +2 <temp file>

Setting the Editing Mode

Reedline allows you to edit text using three modes — Emacs, Vi and Helix. If not specified, the default mode is Emacs. To change the mode, use the edit_mode setting, which accepts emacs, vi or helix.

$env.config.edit_mode = 'vi'

This can be changed at the commandline or persisted in config.nu.

Note

Vi is a "modal" editor with a "normal" mode, an "insert" mode and a "visual" mode. We recommend becoming familiar with these modes through the use of the Vim or Neovim editors before using Vi mode in Nushell. Each has a built-in tutorial covering the basics (and more) of modal editing.

Helix mode follows the Helix editor, which is also modal but "selection-first": you first select text with a motion, and then act on the selection. See Helix Mode below.

The cursor shape can be set separately for each mode with $env.config.cursor_shape, which has the keys emacs, vi_insert, vi_normal, vi_visual, helix_normal, helix_select and helix_insert. Each accepts block, underscore, line, blink_block, blink_underscore, blink_line or inherit (keep the terminal's cursor shape):

$env.config.cursor_shape.vi_insert = 'line'
$env.config.cursor_shape.vi_normal = 'block'

Every key defaults to inherit, which means Nushell doesn't change the cursor in that mode. vi_visual is the exception. When it's inherit, visual mode uses the vi_normal shape, so the example above also gives visual mode a block cursor.

Default Keybindings

Each of the three edit modes is built from a few shared sets of keybindings plus its own additions. The tables below follow Reedline's keybinding reference for the Reedline version that ships with Nushell. Run keybindings default to list Reedline's built-in key table for the emacs, vi_normal, vi_insert, helix_normal and helix_insert modes. It has no rows for vi_visual or helix_select, and it leaves out the plain-key Vi and Helix commands such as w and d, which Reedline handles outside that table.

keybindings default prints Reedline's own names for keys and events, which differ from the ones you write in $env.config.keybindings. KeyModifiers(0x0) is no modifier, Char('k') is char_k, UntilFound([...]) is an until list, and Edit([...]) is an edit event:

keybindings default | where mode == emacs and code in [Down "Char('k')"] | first 2
# => ╭───┬───────┬───────────────────────┬───────────┬──────────────────────────────╮
# => │ # │ mode  │       modifier        │   code    │            event             │
# => ├───┼───────┼───────────────────────┼───────────┼──────────────────────────────┤
# => │ 0 │ emacs │ KeyModifiers(0x0)     │ Down      │ UntilFound([MenuDown, Down]) │
# => │ 1 │ emacs │ KeyModifiers(CONTROL) │ Char('k') │ Edit([KillLine])             │
# => ╰───┴───────┴───────────────────────┴───────────┴──────────────────────────────╯

It doesn't include the bindings that Nushell adds or the ones in your configuration. Those are in $env.config.keybindings, shown below.

Some keys are a fallback chain: Reedline tries each step and takes the first one that applies. The tables write those with "otherwise". For example, → accepts a history hint if one is showing, otherwise moves right in an open menu, otherwise moves the cursor right.

Keybindings Added by Nushell

Nushell adds the following keybindings on top of Reedline's defaults. They are defined in $env.config.keybindings, so you can change or remove them, and they apply in every edit mode:

KeyAction
TabOpen the completion menu, otherwise select the next item, otherwise complete
Shift+TabSelect the previous item in the menu
Ctrl+SpaceOpen the IDE-style completion menu, otherwise select the next item, otherwise complete
Ctrl+ROpen the history menu (this replaces Reedline's Ctrl+R history search)
Ctrl+QSearch the history
Ctrl+XShow the next page of an open menu
Ctrl+ZShow the previous page of an open menu, otherwise undo
F1Open the help menu
$env.config.keybindings | select name modifier keycode
# => ╭───┬────────────────────────────┬──────────┬─────────╮
# => │ # │            name            │ modifier │ keycode │
# => ├───┼────────────────────────────┼──────────┼─────────┤
# => │ 0 │ completion_menu            │ none     │ tab     │
# => │ 1 │ ide_completion_menu        │ control  │ space   │
# => │ 2 │ completion_previous        │ shift    │ backtab │
# => │ 3 │ history_menu               │ control  │ char_r  │
# => │ 4 │ next_page_menu             │ control  │ char_x  │
# => │ 5 │ undo_or_previous_page_menu │ control  │ char_z  │
# => │ 6 │ help_menu                  │ none     │ f1      │
# => │ 7 │ search_history             │ control  │ char_q  │
# => ╰───┴────────────────────────────┴──────────┴─────────╯

Common Keybindings

Four sets of keybindings are shared between the edit modes:

SetEmacsVi insertVi normal / visualHelix insertHelix normal / select
Controlyesyesyesyesyes
Navigationyesyesyes, rebound in visualyesyes, rebound in select
Editingyesyesnoyesno
Selectionyesyesyesyesyes

A mode without the editing set rebinds Backspace and Delete itself. Modes may also override single keys within a set; those keys are noted in the mode's own tables.

Control Keybindings

KeyAction
EscClose an open menu and clear the selection; in Vi and Helix modes, also switch mode
Ctrl+CCancel the current input
Ctrl+DDelete the character under the cursor, or exit Nushell when the line is empty
Ctrl+LClear the screen, keeping the current input
Ctrl+RSearch the history (Nushell binds this key to the history menu instead, see above)
Ctrl+OOpen the current input in your editor (see $env.config.buffer_editor)

When background jobs not spawned with --auto-kill are running, Ctrl+D on an empty line doesn't exit right away. Like exit, it prints a background_jobs_running warning and returns to the prompt. Pressing Ctrl+D again kills the jobs and exits, unless you run another command first.

Navigation Keybindings

KeyAction
↑, Ctrl+PMove up in an open menu, otherwise move one line up, walking back through the history from the first line
↓, Ctrl+NMove down in an open menu, otherwise move one line down, walking forward through the history from the last line
PageUpMove one page up in an open menu, otherwise jump to the oldest history entry
PageDownMove one page down in an open menu, otherwise leave the history for the line you were typing
←Move left in an open menu, otherwise move one character left
→Accept a history hint, otherwise move right in an open menu, otherwise move one character right
Ctrl+←Move one word left
Ctrl+→Accept one word of a history hint, otherwise move one word right
Home, Ctrl+AMove to the start of the line
End, Ctrl+EAccept a history hint, otherwise move to the end of the line
Ctrl+Home, Alt+<Move to the start of the buffer
Ctrl+End, Alt+>Move to the end of the buffer

On terminals that use the Kitty keyboard protocol, Shift+Alt+, and Shift+Alt+. also work for Alt+< and Alt+>.

When the line already has text and the cursor is at its end, ↑ and ↓ only show history entries that start with that text, and PageUp jumps to the oldest of them. See Prefix search with the arrow keys.

Editing Keybindings

KeyAction
Backspace, Ctrl+HDelete the character to the left
DeleteDelete the character under the cursor
Ctrl+Backspace, Ctrl+WDelete the word to the left
Ctrl+DeleteDelete the word to the right
Shift+Enter, Alt+EnterInsert a newline without running the input
Ctrl+JRun the input, or insert a newline if it is incomplete

None of these fill the cut buffer, except Ctrl+W in Emacs mode, which rebinds it to a cut. When Nushell is built with the system-clipboard feature, this set also has Ctrl+Shift+X, Ctrl+Shift+C and Ctrl+Shift+V to cut, copy and paste the selection with the system clipboard.

Selection Keybindings

KeyAction
Shift+←, Shift+→Extend the selection by one character
Shift+↑, Shift+↓Extend the selection by one line
Ctrl+Shift+←, Ctrl+Shift+→Extend the selection by one word
Shift+Home, Shift+EndExtend the selection to the line start or end
Ctrl+Shift+Home, Ctrl+Shift+EndExtend the selection to the buffer start or end
Ctrl+Shift+ASelect the whole buffer

The cut buffer

Reedline keeps one cut buffer for all edit modes. Every command that cuts or copies replaces what's in it, such as Ctrl+K in Emacs mode or d and y in Vi and Helix mode, and every paste inserts it, such as Ctrl+Y or p. It stays filled after you run a command, so you can cut text from one command line and paste it into the next. There are no named registers. In Vi normal mode, "a ignores the " and starts appending.

Commands that delete, as opposed to cut, leave the cut buffer alone. Among the keys, those are Backspace, Delete and the editing keybindings above, Vi's C and Helix's Alt+D. Among the edit commands, the ones named after "backspace", "delete", "clear" or "erase" leave it alone, and the ones named after "cut" or "copy" fill it. The system clipboard is separate, see The system clipboard.

Emacs Mode

Emacs mode is the default. It has all four common sets, plus:

KeyAction
Ctrl+BMove left in an open menu, otherwise move one character left
Ctrl+FAccept a history hint, otherwise move right in an open menu, otherwise move one character right
Alt+←, Alt+BMove one word left
Alt+→, Alt+FAccept one word of a history hint, otherwise move one word right
EnterRun the input, or insert a newline if it is incomplete
Alt+Backspace, Alt+MDelete the word to the left
Alt+DeleteDelete the word to the right
Ctrl+WCut the word to the left
Alt+DCut the word to the right
Ctrl+KCut to the end of the line, or join the next line when already at the end
Ctrl+UCut from the start of the line to the cursor
Ctrl+YPaste the cut buffer before the cursor
Ctrl+TSwap the two characters around the cursor
Ctrl+ZUndo (Nushell binds this key to "previous menu page, otherwise undo", see above)
Ctrl+GRedo
Alt+UUppercase the word under the cursor
Alt+LLowercase the word under the cursor
Alt+CUppercase the first letter of the word under the cursor and lowercase the rest

Alt+U, Alt+L and Alt+C change the whole word, even with the cursor in the middle of it. With the cursor just before the r of world, Alt+U gives WORLD. Bash and other readline-based shells change only the part from the cursor on, giving woRLD.

Vi Mode

Vi mode starts in insert mode. Esc switches to normal mode, i and its siblings return to insert mode, and v enters visual mode from normal mode. In visual mode, Esc returns to normal mode; in normal mode it cancels a half-typed command.

An operator waits for a motion, and the motion picks the range the operator acts on: d then w cuts a word. A count can prefix a motion or a command, and counts on an operator and its motion multiply: 2d3w cuts six words.

In every Vi mode, an Alt+<char> chord that isn't bound is read as Esc followed by <char> (the "meta" convention of readline and zsh). For example, Alt+k in insert mode recalls the previous line. This is also how you can use a terminal that doesn't send Alt: press Esc first, then the key.

Vi Insert Mode

Insert mode has all four common sets, plus:

KeyAction
EnterRun the input, or insert a newline if it is incomplete
EscSwitch to normal mode, moving the cursor back onto the last typed character

The Emacs cut and case commands (Ctrl+K, Ctrl+U, Ctrl+Y, Ctrl+T, Alt+D, Alt+U, Alt+L and Alt+C) are not bound in insert mode. Because of the meta convention, Alt+u undoes, and Alt+d leaves insert mode and starts a d operator. Ctrl+W deletes the word to the left without cutting it.

Vi Normal Mode

Normal mode and visual mode have the control, navigation and selection sets, but not the editing set. In its place:

KeyAction
BackspaceMove one character left in normal mode; extend the selection one character left in visual mode
DeleteDelete the character under the cursor in normal mode; in visual mode, cut the selection like d

These motions move the cursor in normal mode. In visual mode, they extend the selection instead:

KeyMotion
h, lMove one character left or right
j, kMove one line down or up, walking through the history at the edge of the buffer
w, WMove to the start of the next word or WORD
e, EMove to the end of the next word or WORD
b, BMove to the start of the previous word or WORD
0Move to the start of the line
^Move to the first non-blank character of the line
$Move to the end of the line
gg, GMove to the start or end of the buffer
f<char>, F<char>Move onto the next or previous occurrence of <char>
t<char>, T<char>Move just before the next or previous occurrence of <char>
;, ,Repeat the last f/t/F/T search, forwards or reversed

A WORD is delimited only by whitespace; a word is also delimited by punctuation. In normal mode, h, j, k and l follow the same fallback chain as the arrow keys: an open menu takes the key first, and l accepts a history hint before it moves.

Normal mode commands:

KeyAction
i, aInsert before or after the cursor
I, AInsert at the start or at the end of the line
o, OOpen a line below or above, and insert
vEnter visual mode
x, XCut the character under or before the cursor
sCut the character under the cursor and insert
r<char>Replace the character under the cursor with <char>
CChange to the end of the line, without filling the cut buffer
SChange the whole line
DCut to the end of the line
p, PPaste the cut buffer after or before the cursor
uUndo
~Switch the case of the character under the cursor
.Repeat the last change
?Search the history and switch to insert mode
EnterRun the input, or insert a newline and switch to insert mode if it is incomplete

A half-typed command, such as f, r, an operator or a count, takes the next character before any keybinding sees it. So rv replaces the character under the cursor with v, and fv moves to the next v. A vi_normal binding on a letter can't fire as the argument of f, even one with Ctrl held, so after f a bound Ctrl+X searches for x. A count waits for more keys too, which is why 2v doesn't enter visual mode. With nothing half-typed, a vi_normal binding on a plain letter takes the place of the built-in command for that letter. A bound key that isn't a character, such as an arrow or F5, fires at any time and drops whatever was half-typed.

Vi Operators and Text Objects

d, c and y take any motion, and cut, change or copy the range it covers. Doubling an operator applies it to the whole line: dd, cc, yy.

An operator can also take a text object, with i for "inside" or a for "around":

ObjectSelects
w, WA word or WORD
bThe enclosing brackets
qThe enclosing quotes

A delimiter works as a text object too: (, ), [, ], {, }, <, >, ", ', ` and $. Either half of a pair does the same thing, so di( is the same as di). All three operators take the inside form; only d and y take the around form.

Vi Visual Mode

Pressing v in normal mode starts visual mode, which selects text as you move the cursor with the motions. Visual mode rebinds the navigation set so each key extends the selection the way its Vi counterpart does:

  • ←, → and Backspace follow h and l.
  • ↑, ↓, Ctrl+P and Ctrl+N follow k and j.
  • Ctrl+← and Ctrl+→ follow b and w.
  • Home, End, Ctrl+A and Ctrl+E follow 0 and $.
  • Ctrl+Home, Ctrl+End, Alt+< and Alt+> follow gg and G.

In visual mode, ↑ and ↓ never walk through the history, and history hints are not accepted.

The normal mode commands apply in visual mode too, except for these keys, which act on the selection:

KeyAction
d, xCut the selection and return to normal mode
XCut the selected lines, staying in visual mode
c, sChange the selection and switch to insert mode
yCopy the selection and return to normal mode
p, PReplace the selection with the cut buffer, staying in visual mode
u, UMake the selection lowercase or uppercase, then return to normal mode
~Switch the case of the selection, then return to normal mode
o, OMove the cursor to the other end of the selection
r<char>Replace every selected character with <char>, then return to normal mode
EscDrop the selection and return to normal mode

Normal mode and visual mode have separate keybinding tables. Keybindings for visual mode use the vi_visual mode name, and bindings for vi_normal don't apply in visual mode.

Helix Mode

With $env.config.edit_mode = 'helix', the line editor follows the Helix editor. A motion carries a selection with it, and a command acts on what is selected. There is no operator-pending state: w selects a word, and d then deletes it.

Helix mode starts in insert mode. Esc switches to normal mode, i and its siblings return to insert mode, and v toggles select mode, where a motion extends the selection instead of replacing it. A count can prefix any key except g. A count typed before g is dropped along with the g, so 3gh acts like h alone. A key you bound yourself, such as Ctrl+X, runs once after a count and drops it.

Insert mode has all four common sets, plus Enter (run the input, or insert a newline if it is incomplete) and Esc (switch to normal mode).

Normal mode and select mode have the control, navigation and selection sets, but not the editing set. In its place:

KeyAction
BackspaceMove one character left in normal mode; extend one left in select mode
DeleteDelete the character under the cursor
Alt+DDelete the selection without yanking it
Alt+`Make the selected text uppercase

As in Vi visual mode, select mode rebinds the navigation set so each key extends the selection like its Helix counterpart, and ↑/↓ never walk through the history. The arrows, Backspace, Ctrl+P and Ctrl+N follow h, j, k and l, and Ctrl+← and Ctrl+→ follow b and w. Home, End, Ctrl+A and Ctrl+E follow gh and gl. Ctrl+Home, Ctrl+End, Alt+< and Alt+> follow gg and ge.

Motions:

KeyAction
h, lMove left / right
j, kMove down / up (walking through the history at the buffer's edge)
w, b, eMove to the next word start / previous word start / next word end
W, B, EMove to the next WORD start / previous WORD start / next WORD end
f<char>, F<char>Find the next / previous <char>
t<char>, T<char>Find till the next / previous <char>
gh, glGo to the start / end of the line
gsGo to the first non-whitespace character of the line
gg, geGo to the start / end of the buffer

h, l and the g motions collapse the selection onto the new position, while w, b, e, f and t select the text they move over.

Selection:

KeyAction
xSelect the current line; if it is already selected, extend to the next line
%Select the whole buffer
vToggle select mode
EscCollapse the selection in normal mode; leave select mode in select mode

In the Helix editor, Esc in normal mode keeps the selection, and ; collapses it. Nushell's Helix mode has no ;, so Esc does that job.

Changes:

KeyAction
i, aInsert before / after the selection
I, AInsert at the first non-blank character of the line / at the end of the line
o, OOpen a new line below / above the selection
dDelete the selection
cChange the selection (delete it and enter insert mode)
yYank (copy) the selection
p, PPaste after / before the selection
r<char>Replace the selection with <char>
~Switch the case of the selected text
`Make the selected text lowercase
u, UUndo / redo
EnterRun the input, or insert a newline and switch to insert mode if it is incomplete

d, y and p return to normal mode, and c switches to insert mode.

Match mode starts with m:

KeyAction
mi<char>Select inside the pair or word that <char> names
ma<char>Select around it, delimiters included
ms<char>Surround the selection with the pair
md<char>Delete the pair around the cursor, keeping what's inside
mr<old><new>Replace the pair around the cursor with another pair

<char> is w or W for a word or WORD (with i and a only), either half of (), [], {} or <>, or a quote. Any other printable ASCII character pairs with itself, so mi| selects the text between two |. On echo (abc def) with the cursor inside the parentheses, mi( and then d leave echo ().

These Helix keys aren't available: ;, ,, J, G, X, >, <, the /, n and N search commands, mm (go to the matching bracket), and the multi-cursor commands.

Keybindings for Helix mode use the helix_normal, helix_select and helix_insert mode names. The prompt uses PROMPT_INDICATOR_VI_INSERT in Helix insert mode, and PROMPT_INDICATOR_VI_NORMAL in normal and select mode.

Tips

The selection in Vi visual mode and Helix mode is styled with $env.config.color_config.selection (reverse video by default). $env.config.color_config.selection_cursor styles the character under the cursor inside a selection:

$env.config.color_config.selection = { bg: '#44475a' }

Command History

As mentioned before, Reedline manages and stores all the commands that are edited and sent to Nushell. To configure the max number of records that Reedline should store you will need to adjust this value in your config file:

# in config.nu
$env.config.history.max_size = 1000

The default is 100_000, and SQLite history ignores the limit. History in the configuration reference describes every history setting.

Note

The history.max_size, history.file_format, history.isolation and history.path settings must be set in config.nu. They can't be changed once the REPL has started. Setting $env.config.history.path to null turns off the history file.

The history commands

history returns the saved history as a table, oldest command first. With the default plain-text history it has two columns, command and index, the entry's position in the file. The table shows index in its # column:

history
# => ╭───┬─────────╮
# => │ # │ command │
# => ├───┼─────────┤
# => │ 0 │ ls      │
# => │ 1 │ echo hi │
# => │ 2 │ cd /tmp │
# => ╰───┴─────────╯

With SQLite history, the columns are start_timestamp, command, cwd, duration and exit_status, so you can ask questions such as history | where exit_status != 0 and cwd == $env.PWD. --long (-l) adds item_id, session_id, hostname and idx, the row's position in the database. Plain-text history stores only the command lines, and --long changes nothing there. SQLite history is read from the database only when a later command needs the rows, so describe calls the result SQLiteQueryBuilder. Most commands treat it as a table, but a few, such as to nuon, reject it with custom values are currently not nuon-compatible. Pipe it through into value first to get a plain table.

history reads the history file, so it shows what has been written to it:

  • Plain-text history writes the new commands to the file just before the next prompt, with the default history.sync_on_enter. The line that runs history isn't in the file yet, so history | last is the command before it. With sync_on_enter: false, the file is written only when Nushell exits, and history doesn't show this session's commands at all.
  • SQLite history saves each command when you press Enter, so history | last is the line that runs history.

Started with nu --no-history, history returns nothing.

history --clear (-c) deletes the history without asking. It removes the plain-text file, or every row of the SQLite database. With plain-text history and the default sync_on_enter, the session's own list is emptied at the next prompt too, so ↑ then finds only the history --clear line.

history session returns the ID of the current session. With SQLite history and history.isolation turned on, each command is saved with this ID in its session_id column, so this lists the commands you have run in this session:

history --long | where session_id == (history session) | get command

With history.isolation off, history session returns 0, and session_id stays empty. Plain-text history can't store the ID, but with isolation on, history session still returns one. The ID is the time the session started, in nanoseconds since 1970, so history session | into datetime shows when that was.

history import adds commands to the history file in use. With no input, it copies every entry from the file of the other format, history.sqlite3 when you use plain text or history.txt when you use SQLite, which keeps your history when you change history.file_format. It looks for that file in the configuration directory, even when history.path points elsewhere. If there's no such file, it creates an empty one and imports nothing. Like history, it does nothing in a nu --no-history session.

Piped input can be:

  • A string or a list of strings, one command each. This suits another shell's history file: open ~/.bash_history | lines | history import.
  • A table with a command column and any of start_timestamp (a date), hostname, cwd, duration (a duration) and exit_status (an int).

Plain-text history keeps only the command, and it skips a command that is the same as the one before it. A missing command column is an error, and so is any other column, which means the output of history can't go straight back in. history | history import fails with unsupported column names: index.

Before it writes anything, history import copies the current history file to <file>.bak, or to <file>.bak.1, <file>.bak.2 and so on when that name is taken, and prints Backed history to and the path. It does this even when the import then fails. After 99 numbered backups it fails with Too many backup files until you delete some.

Prefix search with the arrow keys

On an empty line, ↑ (or Ctrl+P) steps back through the whole history, newest entry first. Once you have typed something and the cursor is at the end of the line, ↑ searches instead. It jumps to the newest entry that starts with the text you typed, and each further press goes to the next older match. Say your history holds, from oldest to newest:

echo apple
echo banana
echo apricot
echo apricot
ls

Typing echo ap and pressing ↑ gives echo apricot. Pressing it again gives echo apple, because the search passes over echo banana and ls, and it also skips the second echo apricot since that's the entry already on the line. At the oldest match, ↑ does nothing. ↓ walks back toward newer matches, and past the newest one it gives you back echo ap. If nothing in the history starts with your text, the line stays as you typed it.

Some details:

  • The search text is the line as it was at the first press of ↑, and it stays fixed while you step through the matches. Editing the recalled line ends the search. The next ↑ starts a new one, with the edited line as the search text.
  • An entry matches only if it starts with the search text, letter case included. echo ap doesn't find ECHO apple or print (echo ap).
  • With the cursor anywhere but at the end of the line, ↑ ignores the text and steps through the whole history, as on an empty line. Press End first to search.
  • A multi-line command never searches. ↑ and ↓ move between its lines, and from the first line ↑ steps through the whole history.
  • In Vi and Helix normal mode, k and j search the same way. After Esc the cursor rests on the last character, which counts as the end of the line.
  • With history.isolation turned on, the search sees what plain ↑ sees, which is this session's commands and the ones saved before the session started.

To find a command by text in the middle of the line, use Ctrl+Q or the history menu instead.

Reverse history search

Ctrl+Q (the SearchHistory event) starts an incremental search backwards through the history. The prompt changes to (reverse-search: ), and as you type, the search text appears after the colon and the newest command that contains it appears after the closing parenthesis:

(reverse-search: ba)echo bat

The text can match anywhere in the command, and the search starts empty, whatever was on the line before. In the search:

  • ↑ goes to the next older match, and ↓ back to a newer one.
  • Backspace removes the last character of the search text.
  • Enter puts the match on the line without running it, so you can edit it first.
  • Esc ends the search and gives you back the line you were typing.
  • Ctrl+C ends the search and abandons the line you were typing, so the next prompt starts empty.

When nothing matches, the prompt says so, as in (failing reverse-search: echqq).

Hints

As you type, Reedline shows a hint in a dimmed color ($env.config.color_config.hints) after the cursor. By default the hint is the most recent matching command from your history. Press → or End to accept the whole hint, or Ctrl+→ to accept one word of it. Set $env.config.show_hints = false to turn hints off.

The hint is a command from the history that starts with everything typed so far, letter case included. With the sqlite history format, Nushell prefers the most recent such command that you ran in the current directory, and falls back to the most recent one from anywhere. The plaintext format doesn't record directories, so there the hint is always the most recent match.

show_hints defaults to true, but hints also need color. While $env.config.use_ansi_coloring is false, or auto decides against color, no hint shows, whatever show_hints says.

To compute hints yourself, set $env.config.hinter.closure to a closure. It receives a record with the current line, the cursor position pos and the working directory cwd, and returns the text to show after the cursor, or null for no hint. It can also return a record {hint: string, next_token: string}, where next_token is the part that Ctrl+→ accepts. The closure runs on every keystroke, so keep it fast.

let snippets = ["git status", "git switch -c", "cargo build --release"]
$env.config.hinter.closure = {|ctx|
    let match = $snippets | where $it starts-with $ctx.line | first
    if ($ctx.line | is-empty) or $match == null {
        null
    } else {
        $match | str substring ($ctx.line | str length)..
    }
}

Set $env.config.hinter.closure = null to go back to the built-in history hints.

When the closure fails, or returns anything other than a string, a record with a hint string, or null, no hint shows and nothing is printed. To see why, log the errors to a file, as in nu --log-level error --log-target file --log-file hints.log. A closure that returns 42 logs external_hinter: unsupported closure return type int there on every keystroke.

Status Line

Below the line you're editing, Nushell draws a status line, one row that tells you what the parser makes of the line so far. Nushell already parses the line on every keystroke to highlight it, and the status line reuses that parse. Running the line erases the status line, and it stays hidden while you search the history.

~> "a,b" | split row ","
  split row {flags} <separator>   → list<string>   = [a, b]

The status line has up to three parts, left to right:

  • Signature. The signature of the command under the cursor, with the parameter you're typing in bold and underlined. Required parameters are in <angle brackets>, optional ones in (parentheses), and a rest parameter starts with .... {flags} stands for all of the command's flags, and it's the part underlined while the cursor is on a flag or its value.
  • Type. → and the type that the pipeline at the cursor outputs, as far as the parser can tell. Inside a closure, block or subexpression, it's the type of the pipeline inside it. The status line leaves out any and nothing.
  • Preview. = and the value of the line, when every command in it is a const command. A line such as ls | length gets no preview, because ls can't run at parse time. If a preview takes longer than 25 milliseconds, Nushell stops computing it and leaves it out.
Line, with the cursor at the endStatus line
"hello" | str lengthstr length {flags} ...(rest) → int = 5
[1 2 3] | math summath sum {flags} ...(columns) → number = 6
ls | update name {|r| [1 2] | math summath sum {flags} ...(columns) → number
ls | → table
1 + 2→ int = 3

In str substring 1..2, the cursor is on the range, so the status line underlines <range> in str substring {flags} <range> ...(rest).

The status line never takes more than one row. When it's wider than the terminal, it's cut off with …. A preview drops any ANSI escapes the value contains, so (ansi red) + "hi" previews as a plain hi. Line breaks and tabs show as \n, \r and \t, and other control characters as escapes such as \u{7f}. "a\tb" + "c" previews as a\tbc.

When the line has a parse or type error, the status line shows the first one instead, in red:

~> let x: int = "a"
  ✗ Type mismatch: expected int, found string

An error shows up only once it's no longer about the text you're still typing:

  • let x: int = "a" shows no error until you type a space after "a".
  • str substring doesn't report its missing range while the cursor waits for it. Move on to str substring | str length and the status line shows ✗ Missing required positional argument: missing range.
  • An unfinished line, such as one with an open {, shows no error.
  • A line that uses a module that isn't loaded yet shows no error and no preview. The parse behind the highlighting doesn't load the module, so the names it imports would look unknown.

Each part can be turned off on its own. All of these default to true, and a change takes effect at the next prompt:

$env.config.status_line.enable = true    # false hides the status line entirely
$env.config.status_line.errors = true    # the first parse or type error
$env.config.status_line.signature = true # the signature of the command under the cursor
$env.config.status_line.type = true      # the type the pipeline outputs
$env.config.status_line.preview = true   # the value of a line of const commands

The status line is drawn in $env.config.color_config.status_line, or in the hints style when that key isn't set. Errors use $env.config.color_config.status_line_error, which is red by default. With $env.config.use_ansi_coloring = false, the status line is plain text. See Coloring and Theming for the style syntax.

$env.config.color_config.status_line = 'cyan'
$env.config.color_config.status_line_error = { fg: 'yellow' attr: b }

Customizing the Prompt

The Reedline prompt is configured using a number of environment variables. See Prompt Configuration for details.

Keybindings

Reedline keybindings are powerful constructs that let you build chains of events that can be triggered with a specific combination of keys.

For example, let's say that you would like to map the completion menu to the Ctrl + t keybinding (default is tab). You can add the next entry to your config file.

$env.config.keybindings ++= [{
    name: completion_menu_ctrl_t
    modifier: control
    keycode: char_t
    mode: emacs
    event: { send: menu name: completion_menu }
}]

After loading this new config.nu, your new keybinding (Ctrl + t) will open the completion command.

Each keybinding has the next elements:

  • name: A label for your keybinding. It is optional, and Nushell doesn't use it to match entries.
  • modifier: none, or one or more of control, shift, alt, super, hyper and meta joined with _, such as control_alt. The names can come in any order and any letter case, so Shift_Control works too, and so does a set of three or more, such as control_alt_super.
  • keycode: The key without its modifiers. It is one of backspace, enter, space, tab, backtab (Shift+Tab), esc (or escape), up, down, left, right, home, end, pageup, pagedown, delete, insert, null, f1 to f35, char_ followed by one character, such as char_t or char_|, or char_u followed by a hexadecimal Unicode code point, such as char_u00e9 for é. Nushell lowercases the keycode before reading it, so char_A binds the a key. To bind a capital letter, use modifier: shift with keycode: char_a.
  • mode: emacs, vi_insert, vi_normal, vi_visual, helix_insert, helix_normal or helix_select (a single string or a list. e.g. [vi_insert vi_normal]). Lists can be nested, which helps when you build the list from variables. The names can also be written as ViNormal, HelixSelect and so on, in any letter case. An entry with an empty list binds nothing, and Nushell doesn't read its event.
  • event: The type of event that is going to be sent by the keybinding. The options are:
    • send
    • edit
    • until

Assigning a list to $env.config.keybindings replaces the whole list, including the default bindings that open the menus (such as Tab for the completion menu), so add your bindings with ++= as in the example above. When two entries bind the same mode, modifier and keycode, the later one wins. $env.config.keybindings = [] removes every binding in the list, but Reedline's built-in bindings for moving and editing stay.

Nushell checks every entry's mode, modifier and keycode when you assign the list. If one of them is wrong, such as modifier: ctrl, Nushell reports the error (expected 'control', 'shift', 'alt', 'super', 'hyper', 'meta', or 'none', but got 'ctrl') and rejects the whole list, so the previous one stays in effect. The event is read later, when the next prompt is built. A bad event, such as { send: clearscren }, is stored with the list, and Nushell prints its error before every prompt and keeps the keybindings it had until you fix it.

Tips

All of the available modifiers, keycodes and events can be found with the command keybindings list. Its flags list one kind at a time: --modifiers (-m), --keycodes (-k), --modes (-o), --events (-e) and --edits (-d). Without flags it lists them all, as a table with a type column (modifiers, keycodes, modes, events or edits) and a name column. The modifier list shows only the common combinations, and the keycode list writes Char_<letter> and F<number> for whole ranges.

keybindings on its own only prints its help, which lists its three subcommands: keybindings default, keybindings list and keybindings listen.

Tips

The keybindings added to vi_insert mode will be available when the line editor is in insert mode (when you can write text), and the keybindings marked with vi_normal mode will be available when in normal (when the cursor moves using h, j, k or l)

The event section of the keybinding entry is where the actions to be performed are defined. In this field you can use either a record or a list of records. For example, this keybinding sends a single event, which opens the current command line in your editor when you press Alt+E

$env.config.keybindings ++= [{
    name: open_editor_alt_e
    modifier: alt
    keycode: char_e
    mode: emacs
    event: { send: OpenEditor }
}]

and this one sends a list of events, which moves the cursor to the start of the line and inserts sudo there when you press Alt+S

$env.config.keybindings ++= [{
    name: prepend_sudo_alt_s
    modifier: alt
    keycode: char_s
    mode: emacs
    event: [
        { edit: MoveToLineStart }
        { edit: InsertString, value: "sudo " }
    ]
}]

The first keybinding example shown in this page follows the first case; a single event is sent to the engine.

The next keybinding is an example of a series of events sent to the engine. It first clears the prompt, inserts a string and then enters that value

$env.config.keybindings ++= [{
    name: change_dir_with_fzf
    modifier: CONTROL
    keycode: Char_t
    mode: emacs
    event: [
        { edit: Clear }
        {
          edit: InsertString,
          value: "cd (ls | where type == dir | each { |row| $row.name} | str join (char nl) | fzf | decode utf-8 | str trim)"
        }
        { send: Enter }
    ]
}]

One disadvantage of the previous keybinding is the fact that the inserted text will be processed by the validator and saved in the history, making the keybinding a bit slow and populating the command history with the same command. For that reason there is the executehostcommand type of event. The next example does the same as the previous one in a simpler way, sending a single event to the engine

$env.config.keybindings ++= [{
    name: change_dir_with_fzf_host_command
    modifier: CONTROL
    keycode: Char_y
    mode: emacs
    event: {
        send: executehostcommand,
        cmd: "cd (ls | where type == dir | each { |row| $row.name} | str join (char nl) | fzf | decode utf-8 | str trim)"
    }
}]

Before we continue you must have noticed that the syntax changes for edits and sends, and for that reason it is important to explain them a bit more. A send is all the Reedline events that can be processed by the engine and an edit are all the EditCommands that can be processed by the engine.

Send Type

To find all the available options for send you can use

keybindings list --events

And the syntax for send events is event: { send: <NAME OF EVENT FROM LIST> }. Events at the end of this page says what each one does.

Tips

You can write the name of the events with capital letters. The keybinding parser is case insensitive

There are three exceptions to this rule: Menu, ExecuteHostCommand and SwitchMode. Those events require an extra field to be complete. The Menu needs the name of the menu to be activated (such as completion_menu or history_menu)

$env.config.keybindings ++= [{
    name: history_menu_alt_h
    modifier: alt
    keycode: char_h
    mode: emacs
    event: {
        send: menu
        name: history_menu
    }
}]

and the ExecuteHostCommand requires a valid command that will be sent to the engine

$env.config.keybindings ++= [{
    name: go_home_alt_g
    modifier: alt
    keycode: char_g
    mode: emacs
    event: {
        send: executehostcommand
        cmd: "cd ~"
    }
}]

The command runs without touching the line you were typing, and the line is still there afterwards. The command isn't saved in the history. It can read and change the line with commandline and its subcommands, which Changing the line from Nushell code explains.

and the SwitchMode event needs the mode to switch to. It accepts the same mode names as the keybinding's mode field (such as vi_normal or helix_normal). This keybinding leaves Vi insert mode with Ctrl+G:

$env.config.keybindings ++= [{
    name: vi_normal_ctrl_g
    modifier: control
    keycode: char_g
    mode: vi_insert
    event: {
        send: switchmode
        mode: vi_normal
    }
}]

A SwitchMode event can only switch between the modes of the current edit_mode, so a switch to vi_normal does nothing in Helix mode. A switch to the mode that is already active also does nothing. The older ViChangeMode (with mode: normal, insert or visual) and HelixChangeMode (with mode: normal, insert or select) events are still accepted and work like SwitchMode.

It is worth mentioning that the events list also shows event: { edit: <edit> }, event: { send: list<event> } and event: { until: list<event> }. These are not events that you send by name. They show the other forms that the event field can take: an edit record (the edit type that was mentioned), a list of events that are all sent one after another, and the until type mentioned later.

Edit Type

The edit type sends one of Reedline's edit commands, which change the text of the command line or move the cursor. To list the available options you can use the next command

keybindings list --edits

The usual syntax for an edit is event: { edit: <NAME OF EDIT FROM LIST> }. Edit commands at the end of this page describes each one and its fields. For example, this keybinding inserts a newline when you press Alt+N, which is useful if your terminal intercepts Alt+Enter and Shift+Enter

$env.config.keybindings ++= [{
    name: insert_newline_alt_n
    modifier: alt
    keycode: char_n
    mode: [emacs vi_insert helix_insert]
    event: { edit: insertnewline }
}]

Some edits in the list are followed by extra fields, such as InsertString value: <string>. Those edits need the extra fields to be fully defined. For example, if we would like to insert a string at the cursor, then you will have to use

$env.config.keybindings ++= [{
    name: insert_to_json_alt_j
    modifier: alt
    keycode: char_j
    mode: emacs
    event: {
        edit: insertstring
        value: " | to json"
    }
}]

or say you want to move right until the next |

$env.config.keybindings ++= [{
    name: move_to_pipe_alt_p
    modifier: alt
    keycode: char_p
    mode: emacs
    event: {
        edit: moverightuntil
        value: "|"
    }
}]

As you can see, these two types will allow you to construct any type of keybinding that you require

Configurations written for older versions of Nushell may use the pair edits CutInsidePair, CopyInsidePair, CutAroundPair and CopyAroundPair. Each takes a left and a right field of one character. Reedline no longer has these edits and keybindings list doesn't show them, but Nushell still accepts them and turns each one into a text object edit on the pair you give. CutInsidePair and CutAroundPair become CutTextObject, the two copy edits become CopyTextObject, and Inside and Around become scope: inner and scope: around. These two events do the same thing. Each cuts the text between the parentheses around the cursor, or inside the next pair of parentheses when the cursor isn't between any:

event: { edit: CutInsidePair, left: "(", right: ")" }
event: { edit: CutTextObject, scope: inner, object_type: { left: "(", right: ")" } }

A missing left or right, or a value longer than one character, makes a bad event, which Nushell handles as described under Keybindings.

Until Type

To complete this keybinding tour we need to discuss the until type for event. As you have seen so far, you can send a single event or a list of events. And as we have seen, when a list of events is sent, each and every one of them is processed.

However, there may be cases when you want to assign different events to the same keybinding. This is especially useful with Nushell menus. For example, say you still want to activate your completion menu with Ctrl + t but you also want to move to the next element in the menu once it is activated using the same keybinding.

For these cases, we have the until keyword. The events listed inside the until event will be processed one by one with the difference that as soon as one is successful, the event processing is stopped.

The next keybinding represents this case.

$env.config.keybindings ++= [{
    name: completion_menu_ctrl_t
    modifier: control
    keycode: char_t
    mode: emacs
    event: {
        until: [
          { send: menu name: completion_menu }
          { send: menunext }
        ]
    }
}]

The previous keybinding will first try to open a completion menu. If the menu is not active, it will activate it and send a success signal. If the keybinding is pressed again, since there is an active menu, then the next event it will send is MenuNext, which means that it will move the selector to the next element in the menu.

As you can see the until keyword allows us to define two events for the same keybinding. An event only lets until move on to the next one when it had nothing to do. The menu event has nothing to do when a menu is already open, menunext when no menu is open, and { edit: moveleft } when the cursor is at the start of the line. Most other events always succeed, so the until event stops as soon as it reaches them. The reference at the end of this page lists when each event and edit has nothing to do.

For example, the next keybinding sends a down whenever there is a line or a newer history entry to move to, and only opens the completion menu when there isn't

$env.config.keybindings ++= [{
    name: completion_menu_ctrl_t
    modifier: control
    keycode: char_t
    mode: emacs
    event: {
        until: [
            { send: down }
            { send: menu name: completion_menu }
            { send: menunext }
        ]
    }
}]

The SwitchMode event makes one keybinding work in more than one edit mode. The next keybinding uses Ctrl+G to leave insert mode in both Vi and Helix mode: in Vi mode the first event switches to vi_normal, and in Helix mode the first event has nothing to do, so the second one switches to helix_normal

$env.config.keybindings ++= [{
    name: leave_insert_mode
    modifier: control
    keycode: char_g
    mode: [vi_insert helix_insert]
    event: {
        until: [
            { send: SwitchMode, mode: vi_normal }
            { send: SwitchMode, mode: helix_normal }
        ]
    }
}]

Changing the line from Nushell code

commandline returns the text in the line editor's buffer as a string. Three subcommands read or change the buffer and the cursor:

  • commandline get-cursor returns the cursor position, 0 before the first character and the length of the line when the cursor is at the end. It counts characters as you see them, the way str length --grapheme-clusters does, so é or an emoji counts as one.
  • commandline set-cursor moves the cursor to a position counted the same way. 0 or a negative position goes to the start, and a position past the end goes to the end. --end (-e) also goes to the end. Given both a position and --end, it uses the position, and given neither, it fails with Required a positional argument or a flag.
  • commandline edit changes the text. --replace (-r), the default, replaces the whole line and puts the cursor at its end. --insert (-i) inserts the text at the cursor and moves the cursor past it. --append (-a) adds the text at the end and leaves the cursor where it was. Only one of the three applies. --append beats --insert, which beats --replace. --accept (-A) works with any of them and runs the line as soon as the change is made, as if you had pressed Enter.

These commands are mostly used from a keybinding with executehostcommand. This one types () at the cursor and puts the cursor between the parentheses, ready for a subexpression:

$env.config.keybindings ++= [{
    name: insert_parens
    modifier: alt
    keycode: char_p
    mode: [emacs vi_insert]
    event: {
        send: executehostcommand
        cmd: 'commandline edit --insert "()"; commandline set-cursor ((commandline get-cursor) - 1)'
    }
}]

Where the command runs decides which line it sees and when its changes show up:

  • In an executehostcommand keybinding, commandline returns the line you are editing, and the changes apply to that line when the command finishes.
  • Typed at the prompt, the command runs after its own line was submitted, so commandline returns an empty string. commandline edit fills in the line of the next prompt instead. commandline edit 'git status' leaves git status there to edit, and with --accept it runs right away.
  • In a pre_prompt or env_change hook, commandline edit fills in the line of the prompt that is about to appear.
  • In a pre_execution hook, commandline returns the line about to run, but a change made with commandline edit is thrown away. The line has already been read.
  • In a script or with nu -c, there is no line editor. commandline returns an empty string until commandline edit stores some text, and nothing ever runs it.

Removing a Default Keybinding

If you want to remove a certain default keybinding without replacing it with a different action, you can set event: null.

e.g. to disable screen clearing with Ctrl + l for all edit modes

$env.config.keybindings ++= [{
    modifier: control
    keycode: char_l
    mode: [emacs, vi_normal, vi_insert, vi_visual, helix_normal, helix_select, helix_insert]
    event: null
}]

event: null takes the key out of the keybinding table, and the key then does whatever the edit mode does with a key that has no binding. A plain character is typed into the line, and in Vi or Helix normal mode a letter goes back to its built-in command. To make a key do nothing at all, bind it to the None event instead. Vi's x isn't in the table, so event: null can't turn it off, but this can:

$env.config.keybindings ++= [{
    modifier: none
    keycode: char_x
    mode: vi_normal
    event: { send: none }
}]

Troubleshooting Keybinding Problems

Your terminal environment may not always propagate your key combinations on to Nushell the way you expect it to. You can use the command keybindings listen to determine if certain keypresses are actually received by Nushell, and how.

After you run it, each key you press prints one line describing what Nushell received, until you press Esc:

> keybindings listen
Type any key combination to see key details. Press ESC to abort.
char: r, code: 0x000072, modifier: KeyModifiers(CONTROL), flags: 0b000010, kind: Press, state: KeyEventState(0x0)
code: Up, modifier: KeyModifiers(0x0), flags: 0b000000, kind: Press, state: KeyEventState(0x0)

A character key shows the char and its code point. Other keys show the code name, such as Up or F(5). modifier and flags show the modifiers held down. kind and state add detail that most terminals leave at Press and KeyEventState(0x0). Input that isn't a key, such as a terminal resize, prints as an event: ... line instead. With $env.config.use_kitty_protocol on, it first prints a warning if the terminal doesn't support the protocol. The command's own help calls it a debugging tool and suggests input listen --types [key] instead, which returns a record you can work with; see Acting on keypresses using input listen.

Menus

Thanks to Reedline, Nushell has menus that can help you with your day to day shell scripting. Next we present the default menus that are available when using Nushell

Menus are configured in $env.config.menus. Assigning a list to it replaces every menu, including the defaults, so $env.config.menus = [] removes them all and Tab no longer opens a completion menu. To add a menu or change a default one, append it with ++=. When two menus share a name, the later one replaces the earlier one, so an appended completion_menu takes the place of the default completion menu.

Every menu needs a name, a marker (the text shown in place of the prompt indicator while the menu is open), a type record with a layout, a style record ({} is enough), and either input_mode or the older only_buffer_difference, both described below. output_mode and source are optional. Nushell checks each menu's layout, input_mode and output_mode when you assign the list. If one of them is wrong, or a required field is missing, Nushell reports it and rejects the whole list, keeping the previous menus. The layout has to be in lowercase. The other fields of type, such as columns, are read when the next prompt is built. A wrong one there, such as columns: "four", prints its error before every prompt until you fix it.

Each menu sets input_mode, which controls the text that the menu searches:

  • diff - only the text typed after the menu was activated
  • cursor_prefix - the line from its start up to the cursor
  • full_buffer - the whole line, including any text after the cursor

It can also set output_mode, which controls what an accepted suggestion replaces:

  • suggested_span - the part of the line that the suggestion names (the default)
  • full_buffer - the whole line
  • extend_to_end - from the start of the suggestion's span to the end of the line

Older configurations use only_buffer_difference instead of input_mode. It still works: true is the same as input_mode: diff, and false is the same as input_mode: cursor_prefix.

By default, erasing text while a menu is open can close the menu. With $env.config.completions.persistent_menus at its default, false:

  • Backspace, Ctrl+Backspace and Home close a menu with the columnar or ide layout, such as the completion menu, as long as $env.config.completions.quick is on (the default). With quick off, the menu stays open and updates its suggestions.
  • Any edit that empties the line closes any menu, including the history and help menus.

Set $env.config.completions.persistent_menus = true to keep menus open while you edit. The menu then updates its suggestions instead, and only closes when you accept a suggestion or press Esc or Ctrl+C.

Typing past the last match doesn't close an open completion menu. It shows NO RECORDS FOUND and fills again as soon as the text matches something.

Menu Keybindings

When a menu is active, some keybindings change based on the keybinding until specifier discussed above. Common keybindings for menus are:

KeyEvent
TabSelect next item
Shift+TabSelect previous item
EnterAccept selection
↑ (Up Arrow)Move menu up
↓ (Down Arrow)Move menu down
← (Left Arrow)Move menu left
→ (Right Arrow)Move menu right
Ctrl+PMove menu up
Ctrl+NMove menu down
Ctrl+BMove menu left
Ctrl+FMove menu right

Note

Menu direction behavior varies based on the menu type (see below). For example, in a description menu, "Up" and "Down" apply to the "Extra" list, but in a list menu the directions apply to the selection.

Help Menu

The help menu is there to ease your transition into Nushell. Say you are putting together an amazing pipeline and then you forgot the internal command that would reverse a string for you. Instead of deleting your pipe, you can activate the help menu with F1. Once active just type keywords for the command you are looking for and the menu will show you commands that match your input. The matching is done on the name of the commands or the commands description.

To navigate the menu you can select the next element by using tab, you can scroll the description by pressing left or right and you can even paste into the line the available command examples.

The help menu can be configured by modifying the next parameters

$env.config.menus ++= [{
    name: help_menu
    input_mode: diff             # Search is done on the text written after activating the menu
    marker: "? "                 # Indicator that appears with the menu is active
    type: {
        layout: description      # Type of menu
        columns: 4               # Number of columns where the options are displayed
        col_width: 20            # Optional value. If missing all the screen width is used to calculate column width
        col_padding: 2           # Padding between columns
        selection_rows: 4        # Number of rows allowed to display found options
        description_rows: 20     # Number of rows allowed to display command description
    }
    style: {
        text: green                   # Text style
        selected_text: green_reverse  # Text style for selected option
        description_text: yellow      # Text style for description
    }
}]

Completion Menu

The completion menu is a context sensitive menu that will present suggestions based on the status of the prompt. These suggestions can range from path suggestions to command alternatives. While writing a command, you can activate the menu to see available flags for an internal command. Also, if you have defined your custom completions for external commands, these will appear in the menu as well.

The completion menu by default is accessed by pressing tab and it can be configured by modifying these values from the config object:

$env.config.menus ++= [{
    name: completion_menu
    input_mode: cursor_prefix       # Search is done on the text from the start of the line up to the cursor
    marker: "| "                    # Indicator that appears with the menu is active
    type: {
        layout: columnar            # Type of menu
        columns: 4                  # Number of columns where the options are displayed
        col_width: 20               # Optional value. If missing all the screen width is used to calculate column width
        col_padding: 2              # Padding between columns
        tab_traversal: "horizontal" # Direction in which pressing <Tab> will cycle through options, "horizontal" (the default) or "vertical"
    }
    style: {
        text: green                   # Text style
        selected_text: green_reverse  # Text style for selected option
        description_text: yellow      # Text style for description
        match_text: { attr: u }       # Matched style
        selected_match_text: { attr: ur }    } # Selected matched style
}]

By modifying these parameters you can customize the layout of your menu to your liking.

The suggestions depend on what is under the cursor. At the start of a command the menu offers command names, after a - the command's flags, after a $ the variables in scope, and for most arguments the names of files and directories. A custom completer can replace the suggestions for a command's arguments. For an external command, generate completions writes extern definitions that give its flags and their values to the menu, built from the command's fish, zsh or carapace completions, its man page, or its --help text (see Generating completions for an external command). The IDE completion menu below shows the same suggestions in a different layout. The sections that follow cover built-in completions that are easy to miss.

To see what Tab would offer for a line, pipe the line to commandline complete, as the examples below do.

Command names, ^ and %

Command name completion lists Nushell's own commands together with the executables in your PATH. When an executable has the same name as a Nushell command, the menu lists it with a ^ in front, and lists the Nushell command a second time with a % in front, so you can pick the one you mean. On a system with a sort executable, typing sort at the prompt offers:

"sort" | commandline complete
# => ╭───┬─────────╮
# => │ 0 │ sort    │
# => │ 1 │ sort-by │
# => │ 2 │ %sort   │
# => │ 3 │ ^sort   │
# => ╰───┴─────────╯

Type the sigil yourself to narrow the list. After ^, the menu offers only executables from PATH, even when $env.config.completions.external.enable is false. After %, it offers only built-in commands. That includes a built-in hidden by a custom command or alias of the same name, or by hide, and leaves out custom commands, aliases and externs:

"%sort" | commandline complete
# => ╭───┬─────────╮
# => │ 0 │ sort    │
# => │ 1 │ sort-by │
# => ╰───┴─────────╯

Accepting a suggestion keeps the sigil and replaces only the name after it, and with the cursor in front of the sigil, Tab offers nothing. See Running System (External) Commands for what ^ and % do when the command runs.

The word right after sudo or doas, written with or without ^, completes from the list of command names, since it names the command to run. Pick the plain name of an executable there, because sudo can't run Nushell commands. Only that first word is special. With options in between, as in sudo -u root sor, and for the arguments of the command that follows, you get the usual completion for an external command, which is your external completer if you have one and file names otherwise. The same happens when no command name matches, and when sudo or doas is a custom command that you defined. An alias that only names the program, such as alias sudo = ^sudo, keeps the command name completion. One that adds options, such as alias doas = ^doas -n, loses it, because the options fill the first-word slot.

Without a sigil, the executables are left out when $env.config.completions.external.enable is false, and $env.config.completions.external.max_results (100 by default) caps how many of them the menu adds. A command whose name has several words completes one word at a time, so after str the menu lists the subcommands of str:

"str c" | commandline complete
# => ╭───┬────────────────╮
# => │ 0 │ str camel-case │
# => │ 1 │ str capitalize │
# => │ 2 │ str contains   │
# => ╰───┴────────────────╯

Flags

After a - in a command's arguments, the menu lists the command's flags, the long form and the short form of each, with each flag's description:

"ls -" | commandline complete | str join " "
# => --all --directory --du --full-paths --help --long --mime-type --short-names --threads -a -D -d -f -h -l -m -s -t

When the command has a command-wide completer, its suggestions are added to the flags, so an external completer can offer flags that a wrapper command doesn't declare. A suggestion that repeats a declared flag appears once.

Cell paths

After a variable and a dot, the menu lists the keys of a record or the columns of a table, with the type of each value as the description:

let user = {name: "Ada", "home dir": "/home/ada", langs: [nu rust], v2: true}
"$user." | commandline complete --detailed | select value description
# => ╭───┬────────────┬──────────────╮
# => │ # │   value    │ description  │
# => ├───┼────────────┼──────────────┤
# => │ 0 │ "home dir" │ string       │
# => │ 1 │ langs      │ list<string> │
# => │ 2 │ name       │ string       │
# => │ 3 │ "v2"       │ bool         │
# => ╰───┴────────────┴──────────────╯

The menu wraps a key in double quotes when it contains anything other than ASCII letters, _ and -, which is why "v2" is quoted along with "home dir". Each further dot goes a level deeper, so $env.config.history. lists the history settings and $table.0. lists the columns of a table's first row. For a list of records, the menu offers every column that appears in any of them. A version from into semver completes to major, minor, patch, pre, build and prefix, and a matrix from into matrix to shape, ndim and size.

The menu reads the actual value when it has one: a variable set by an earlier command, a constant, $env, $nu, or a literal such as {a: 1, b: 2}.. Otherwise it falls back on the declared type. Inside a command body, a parameter typed record<name: string, age: int> completes to age and name, and (sys host). completes the fields that sys host declares for its output. Completion never runs the command, so (ls). offers nothing, because ls only declares that it returns a table.

Operators

After a value and a space, the menu offers the operators that work with the value's type, each with a short description. An integer gets the arithmetic, comparison and bitwise operators, and a float gets the same without the bitwise ones. A string gets the comparisons, the regex operators =~ and !~, which also appear as like and not-like, then starts-with, ends-with, has and their not- forms, and ++. A date gets only comparisons, among them older-than and newer-than:

"(date now) " | commandline complete
# => ╭───┬────────────╮
# => │ 0 │ !=         │
# => │ 1 │ <          │
# => │ 2 │ <=         │
# => │ 3 │ ==         │
# => │ 4 │ >          │
# => │ 5 │ >=         │
# => │ 6 │ in         │
# => │ 7 │ newer-than │
# => │ 8 │ not-in     │
# => │ 9 │ older-than │
# => ╰───┴────────────╯

A list gets ==, !=, in, not-in, has, not-has and ++, a record or a range gets the same without ++, and a boolean gets and, or and xor plus ==, !=, in and not-in. When the type isn't known, as for a column inside where (ls | where size ), the menu offers every operator except like and not-like. Typing the start of an operator narrows the list, so 1 b offers the five bit- operators.

A mutable variable, or a variable under $env, also gets the assignment operators that fit its type: =, +=, -=, *= and /= for a number, = and ++= for a string or a list, and only = for a boolean, date, record or range.

Attributes

Typing @ at the start of a line and pressing Tab lists the attributes you can put above a definition:

"@" | commandline complete
# => ╭───┬───────────────────╮
# => │ 0 │ category          │
# => │ 1 │ complete          │
# => │ 2 │ complete external │
# => │ 3 │ deprecated        │
# => │ 4 │ example           │
# => │ 5 │ interactive       │
# => │ 6 │ search-terms      │
# => │ 7 │ structured        │
# => ╰───┴───────────────────╯

These are all the commands in scope whose names start with attr , shown without that prefix and with their descriptions. Attributes you import show up too, such as @test and @before-each after use std/testing *, and so do ones you define yourself with alias "attr my-tag" = echo (see Defining your own attributes). After the attributes, the menu offers the definitions an attribute can be attached to, which are def, export def, extern and export extern.

Modules and their exports

The module argument of use, export use and overlay use completes from three places:

  • the names of modules already loaded in this session, such as one created with module on an earlier line
  • std and std-rfc, and after std/ or std-rfc/ the submodules that are built into Nushell
  • .nu files and directories in the current directory and in the directories listed in $NU_LIB_DIRS and $env.NU_LIB_DIRS. Other files are left out.
"use std/i" | commandline complete
# => ╭───┬───────────╮
# => │ 0 │ std/input │
# => │ 1 │ std/iter  │
# => ╰───┴───────────╯

After the module, use and export use complete what it exports: commands, aliases, submodules and constants, with names that contain spaces wrapped in quotes. This works for a module file that isn't loaded yet, and inside a bracketed import list:

"use std/log [log-" | commandline complete
# => ╭───┬──────────────────╮
# => │ 0 │ log-ansi         │
# => │ 1 │ log-level        │
# => │ 2 │ log-prefix       │
# => │ 3 │ log-short-prefix │
# => ╰───┴──────────────────╯

overlay use doesn't complete a module's members. source-env offers loaded modules, .nu files and directories like use does, but not std, std-rfc or their submodules, and source offers every file, as for any other path argument.

Ide Completion Menu

The ide_completion_menu works much like the completion_menu but has an ide look and feel about it.

{
  name: ide_completion_menu
  input_mode: cursor_prefix
  marker: "| "
  type: {
    layout: ide
    min_completion_width: 0,
    max_completion_width: 50,
    max_completion_height: 10, # will be limited by the available lines in the terminal
    padding: 0,
    border: true,
    cursor_offset: 0,
    description_mode: "prefer_right"
    min_description_width: 15
    max_description_width: 50
    max_description_height: 10
    description_offset: 1
    # If true, the cursor pos will be corrected, so the suggestions match up with the typed text
    #
    # C:\> str
    #      str join
    #      str trim
    #      str split
    correct_cursor_pos: false
  }
  style: {
    text: green
    selected_text: { attr: r }
    description_text: yellow
    match_text: { attr: u }
    selected_match_text: { attr: ur }
  }
}

The IDE layout draws the suggestions in a box under the cursor, and the selected suggestion's description in a second box beside it. Widths and heights are in terminal columns and rows and include the border:

  • min_completion_width and max_completion_width limit the width of the suggestion box. Suggestions longer than the maximum are cut off.
  • max_completion_height limits its height, and the rows left in the terminal limit it further. It's 10 when not set.
  • padding is the number of spaces on each side of a suggestion.
  • border is true for a rounded border (the default), false for none, or a record of six characters, { top_left: "+", top_right: "+", bottom_left: "+", bottom_right: "+", horizontal: "-", vertical: "|" }.
  • cursor_offset moves the box left (negative) or right (positive) of the cursor. With 0, its left edge lines up with the cursor.
  • description_mode puts the description box on the left or on the right of the suggestion box. prefer_right puts it on the right when there is room, and on the left otherwise.
  • min_description_width, max_description_width and max_description_height limit the description box. The minimum width applies when the suggestion box leaves it little room.
  • description_offset is the gap between the two boxes.

History Menu

The history menu is a handy way to access the editor history. When activating the menu (default Ctrl+r) the command history is presented in reverse chronological order, making it extremely easy to select a previous command.

The history menu can be configured by modifying these values from the config object:

$env.config.menus ++= [{
    name: history_menu
    input_mode: diff             # Search is done on the text written after activating the menu
    marker: "? "                 # Indicator that appears with the menu is active
    type: {
        layout: list             # Type of menu
        page_size: 10            # Number of entries that will presented when activating the menu
    }
    style: {
        text: green                   # Text style
        selected_text: green_reverse  # Text style for selected option
        description_text: yellow      # Text style for description
    }
}]

When the history menu is activated, it pulls page_size records from the history and presents them in the menu. If there is space in the terminal, when you press Ctrl+x again the menu will pull the same number of records and append them to the current page. If it isn't possible to present all the pulled records, the menu will create a new page. The pages can be navigated by pressing Ctrl+z to go to previous page or Ctrl+x to go to next page.

A list layout can also set description_position, for a menu whose suggestions have descriptions (see User Defined Menus). With before, the default, a row shows the description in parentheses ahead of the value, (red or green) apple. With after, it shows apple red or green.

Searching the History

To search in your history you can start typing key words for the command you are looking for. Once the menu is activated, anything that you type will be replaced by the selected command from your history. for example, say that you have already typed this

let a = ()

you can place the cursor inside the () and activate the menu. You can filter the history by typing key words and as soon as you select an entry, the typed words will be replaced

let a = (ls | where size > 10MiB)

Menu Quick Selection

Another nice feature of the menu is the ability to quick select something from it. Say you have activated your menu and it looks like this

>
0: ls | where size > 10MiB
1: ls | where size > 20MiB
2: ls | where size > 30MiB
3: ls | where size > 40MiB

Instead of pressing down to select the fourth entry, you can type !3 and press enter. This will insert the selected text in the prompt position, saving you time scrolling down the menu.

History search and quick selection can be used together. You can activate the menu, do a quick search, and then quick select using the quick selection character.

User Defined Menus

In case you find that the default menus are not enough for you and you have the need to create your own menu, Nushell can help you with that.

In order to add a new menu that fulfills your needs, you can use one of the default layouts as a template. The templates available in nushell are columnar, list, ide or description.

The columnar menu will show you data in a columnar fashion adjusting the column number based on the size of the text displayed in your columns.

The list type of menu will always display suggestions as a list. In the history menu you can also select values using ! plus number combination, see Menu Quick Selection.

The ide type shows the suggestions in a box under the cursor, with the description of the selected one beside it, like the IDE completion menu.

The description type will give you more space to display a description for some values, together with extra information that could be inserted into the buffer.

A menu's suggestions come from its source closure, described below, which works with any of the four layouts. Without a source, the layout decides: columnar and ide menus show Nushell's normal completions, a list menu shows the history, and a description menu shows commands and their help, like the help menu.

Let's say we want to create a menu that displays all the variables created during your session, we are going to call it vars_menu. This menu will use a list layout (layout: list). To search for values, we want to use only the things that are written after the menu has been activated (input_mode: diff).

With that in mind, the desired menu would look like this

$env.config.menus ++= [{
    name: vars_menu
    input_mode: diff
    marker: "# "
    type: {
        layout: list
        page_size: 10
    }
    style: {
        text: green
        selected_text: green_reverse
        description_text: yellow
    }
    source: { |token|
        scope variables
        | where ($it.name | str contains $token.text)
        | sort-by name
        | each { |row| {value: $row.name description: $row.type} }
    }
}]

As you can see, the new menu is identical to the history_menu previously described. The only huge difference is the new field called source. The source field is a closure that returns the values you want to display in the menu. For this menu we are extracting the data from scope variables and we are using it to create records that will be used to populate the menu.

The required structure for the record is the next one

{
  value: "$foo"                 # The value that will be inserted in the buffer
  description: "int"            # Optional. Description that will be displayed with the selected value
  display_override: "foo (int)" # Optional. Text shown in the menu in place of the value
  style: green                  # Optional. Color of the value in the menu
  span: { start: 5, end: 7 }    # Optional. Byte range of the line that the value replaces
  extra: ["first", "second"]    # Optional. A list of strings that will be displayed with the selected value. Only works with a description menu
  append_whitespace: true       # Optional. Adds a space after the value when it's accepted
  match_indices: [1, 2]         # Optional. Positions, from 0, of the characters to draw in the match_text style
  kind: "variable"              # Optional. Accepted as in a custom completer, but a menu ignores it
}

Without match_indices, the menu highlights the typed text wherever it finds it in the value.

For the menu to display something, at least the value field has to be present in the resulting record. The source can also return a plain list of strings, or null to show nothing. It can return the same values as a custom completer, except that the options of a {completions, options} record are ignored.

In order to make the menu interactive, the source closure receives the same inputs as a custom completer. It asks for them by naming its parameters:

  • token - the token under the cursor, as {text, kind, span}. The vars_menu above filters on $token.text, so typing foo after activating the menu shows $foo and $food.
  • place - what is being completed. $place.cursor is the cursor position, and $place.target is the part of the line that a suggestion replaces by default.
  • buffer - the whole line up to the cursor, whatever the menu's input_mode is.

Warning

Before Nushell 0.116, a menu source was written as {|buffer, position| ... }, and with only_buffer_difference: true, $buffer held only the text typed after the menu was activated. A source that declares buffer now always receives the whole line up to the cursor, and a source that declares position still receives the cursor position but prints a deprecation warning. Use $token.text for the text being completed, and $place.cursor for the cursor position.

Using this information, you can design your menu to present the information you require and to replace that value in the location you need it. The only thing extra that you need to play with your menu is to define a keybinding that will activate your brand new menu. For example, to open it with Alt+O:

$env.config.keybindings ++= [{
    name: vars_menu
    modifier: alt
    keycode: char_o
    mode: [emacs, vi_normal, vi_insert]
    event: { send: menu name: vars_menu }
}]

Menu Keybindings

In case you want to change the default way both menus are activated, you can change that by defining new keybindings. For example, the next two keybindings assign the completion and history menu to Ctrl+t and Ctrl+y respectively

$env.config.keybindings ++= [
    {
        name: completion_menu_ctrl_t_vi
        modifier: control
        keycode: char_t
        mode: [vi_insert vi_normal]
        event: {
            until: [
                { send: menu name: completion_menu }
                { send: menupagenext }
            ]
        }
    }
    {
        name: history_menu_ctrl_y_vi
        modifier: control
        keycode: char_y
        mode: [vi_insert vi_normal]
        event: {
            until: [
                { send: menu name: history_menu }
                { send: menupagenext }
            ]
        }
    }
]

Abbreviations

Reedline abbreviations are a convenient way to expand a command into a different command that is often longer and/or more complex. This is similar to an alias with two main exceptions: (1) the expanded command is what gets stored to history, (2) the expanded command can be edited before being used.

Abbreviations are expanded on space or enter and you can add them to your config like this

$env.config.abbreviations = {
    ll: "ls -l"
    gs: "git status"
    ptop: "ps | compact cpu | sort-by cpu -r | first 15"
}

The word before the cursor has to match the abbreviation exactly, and a word ends only at whitespace, so (ll isn't expanded while ( ll is. Nushell also looks at how the word parses. It doesn't expand a word that is text: a string, a raw string, a string interpolation, a bare word passed where a command expects a string, as in echo ll, or an argument of an external command, as in git ll. A word in command position expands, at the start of the line or after |, ; or let x =. So does a path argument, as in ls ll, which isn't text to the parser.

You can see the currently active abbreviations with abbr list:

abbr list
# => ╭───┬──────┬──────────────────────────────────────────────╮
# => │ # │ name │                  expansion                   │
# => ├───┼──────┼──────────────────────────────────────────────┤
# => │ 0 │ gs   │ git status                                   │
# => │ 1 │ ll   │ ls -l                                        │
# => │ 2 │ ptop │ ps | compact cpu | sort-by cpu -r | first 15 │
# => ╰───┴──────┴──────────────────────────────────────────────╯

abbr list is the only subcommand of abbr, and abbr on its own only prints its help. To add or remove abbreviations, change $env.config.abbreviations.

Terminal integration

Nushell sends escape sequences that tell the terminal where the prompt is, which directory you're in and what is running. Terminals that understand them use them for things like jumping between prompts or opening a new tab in the same directory, and ignore the ones they don't know. If a terminal shows stray characters or misbehaves, turn the matching setting off. Each one is a bool under $env.config.shell_integration:

SettingDefaultWhat it does
osc2trueSets the window or tab title to the current directory, with your home directory shortened to ~. While a command runs, the title also shows the command's first word, as in ~/src> cargo.
osc7true (false on Windows)Reports the current directory to the terminal as a file:// URL, so it can open a new tab or window in the same directory.
osc8trueWrites the file names in ls output as links that the terminal can open. Over SSH the links are left out, see $env.SSH_CLIENT.
osc9_9false (true on Windows)Reports the current directory the way ConEmu and Windows Terminal read it, which Windows Terminal uses to duplicate a tab in the same directory.
osc133trueMarks where the prompt, the command line and each command's output start, and reports each command's exit status. Terminals use the marks to jump between prompts or select a command's output. It also turns on clicking to move the cursor (below).
osc633trueIn the Visual Studio Code terminal, sends VS Code's own marks in place of the OSC 133 ones, see $env.TERM_PROGRAM.
reset_application_modetrueSends ESC[?1l after each command. A program, or a remote host over SSH, can leave the cursor keys in "application mode", where they send different codes. This switches them back.

Nushell sends the directory and title sequences once at startup and again after each command.

With osc133 on, the prompt marks also ask the terminal to report mouse clicks on the command line. In a terminal that supports this, clicking in the line moves the cursor to that spot, and clicking an item in an open menu selects it. Other terminals ignore the request.

Two more settings control how the terminal sends input:

  • $env.config.bracketed_paste (default true) asks the terminal to mark pasted text. Nushell then inserts a multi-line paste into the line as one piece, and nothing runs until you press Enter. With it set to false, a pasted newline acts like Enter, so each pasted line runs as it arrives. Windows doesn't support bracketed paste, and there the setting does nothing.
  • $env.config.use_kitty_protocol (default false) turns on the kitty keyboard protocol in terminals that support it. The protocol reports keys that otherwise send the same code, so you can bind Ctrl+I apart from Tab. When the terminal doesn't support the protocol, the setting has no effect. Nushell checks once at startup, and only writes Terminal doesn't support use_kitty_protocol config to its log, which you see when you start it with --log-level warn. keybindings listen and input listen print a warning on the screen instead.

Event and edit reference

This section lists every event and edit command that a keybinding can name. Names are not case-sensitive. keybindings list --events and keybindings list --edits print the same names, with their fields.

Inside an until list, an event that has nothing to do hands the key to the next event. The tables say when that happens.

Events

Use these with send, as in event: { send: ClearScrollback }. The default key is given where there is one.

EventWhat it does
NoneNothing. A key bound to None is swallowed, while event: null removes the key's binding (see Removing a Default Keybinding). Always counts as having nothing to do.
CtrlCAbandons the line without running it, closes an open menu and clears the undo history. In a reverse history search, it ends the search first. Ctrl+C.
CtrlDExits Nushell when the line is empty, otherwise deletes the character under the cursor. Ctrl+D.
ClearScreenClears the screen and redraws the prompt at the top, keeping the line. Closes an open menu. Ctrl+L.
ClearScrollbackLike ClearScreen, and also clears the terminal's scrollback. Not bound by default.
RepaintRedraws the prompt and the line.
EnterWith a menu open, puts the selected suggestion into the line and stops. Otherwise it expands a history reference such as !! and an abbreviation before the cursor, then runs the line, or inserts a newline when the line is unfinished. Enter.
SubmitLike Enter, but runs the line even when it's unfinished, so echo ( runs and reports the unclosed (.
SubmitOrNewlineInserts a newline when the cursor is before the end of the line. Otherwise works like Enter.
Esc, EscapeCloses an open menu and clears the selection. Has nothing to do when there is neither. It doesn't change Vi or Helix modes. Those modes handle the Esc key themselves, and a binding uses SwitchMode instead.
UpMoves the cursor up a line. On the first line it steps back through the history, searching by prefix like ↑. Has nothing to do when there is no line or entry to move to.
DownMoves the cursor down a line. On the last line it steps forward through the history, and past the newest entry it returns to the line you were typing. Has nothing to do when there is nothing to move to.
PreviousHistorySteps back through the history right away, without first moving through the lines of a multi-line buffer. Like Up, it searches by prefix when the line has text and the cursor is at its end.
NextHistorySteps forward through the history, without first moving through the lines of the buffer.
FirstHistoryJumps to the oldest history entry, or during a prefix search to the oldest entry that starts with the typed text. Has nothing to do when it's already there or nothing matches. PageUp.
LeaveHistoryReturns from the history to the line you were typing. Has nothing to do when you aren't stepping through the history. PageDown.
Left, RightMove the cursor one character. Have nothing to do at the start or end of the line. They don't touch menus or hints. The default ← and → keys get that from an until list that tries MenuLeft, MenuRight and HistoryHintComplete first.
ToStart, ToEndMove to the start or end of the buffer. Unlike the MoveToStart and MoveToEnd edits, they don't end history browsing or add an undo step. Have nothing to do when the cursor is already there. Alt+<, Alt+>.
HistoryHintCompleteAccepts the whole history hint. Has nothing to do when no hint is showing or a menu is open.
HistoryHintWordCompleteAccepts the next word of the hint, under the same conditions.
SearchHistoryStarts a reverse history search. Ctrl+Q.
OpenEditorOpens the line in your editor. Ctrl+O.
Menu name: <string>Opens the named menu. Has nothing to do when a menu is already open.
MenuAcceptPuts the selected suggestion into the line and closes the menu, without running the line. Has nothing to do when the menu has no suggestions.
MenuNext, MenuPreviousSelect the next or previous item. When a columnar or ide menu has a single suggestion, MenuNext accepts it, whatever completions.quick says. With completions.partial on, it first fills in the text that all suggestions share.
MenuUp, MenuDown, MenuLeft, MenuRightMove the selection in that direction. What each direction does depends on the menu's layout.
MenuPageNext, MenuPagePreviousShow the next or previous page of the menu.
ExecuteHostCommand cmd: <string>Runs cmd as a Nushell command and keeps the line, see Send Type.
SwitchMode mode: <string>Switches to another mode of the current edit mode, see Send Type. Has nothing to do when it can't switch.

Every Menu... event other than Menu itself has nothing to do when no menu is open.

Edit commands

Use these with edit, as in event: { edit: MoveToLineEnd }. Fields go in the same record, as in { edit: InsertString, value: " | to json" }. A <char> field takes a string of exactly one character.

An edit that moves the cursor has nothing to do when the cursor stays where it is, and CopySelection has nothing to do when nothing is selected. Every other edit counts as done, even one that changes nothing, such as Clear on an empty line.

Moving the cursor

Each of these takes an optional select: true, which extends the selection to where the cursor lands instead of dropping it.

EditMoves the cursor to
MoveLeft, MoveRightThe previous or next character
MoveWordLeft, MoveBigWordLeftThe start of the previous word or WORD
MoveWordRightThe end of the next word
MoveWordRightStart, MoveBigWordRightStartThe start of the next word or WORD
MoveBigWordRightEndThe end of the next WORD
MoveWordRightEndThe same place as MoveWordRight. Deprecated, use MoveWordRight
MoveToLineStart, MoveToLineEndThe start or end of the line
MoveToLineNonBlankStartThe first character of the line that isn't a space or tab
MoveToStart, MoveToEndThe start or end of the buffer
MoveLineUp, MoveLineDownThe line above or below, without stepping into the history
MoveToPosition value: <int>A byte offset from the start of the buffer
MoveRightUntil, MoveLeftUntil value: <char>The next or previous value character, like Vi f and F
MoveRightBefore, MoveLeftBefore value: <char>Next to the next or previous value character, like Vi t and T

A WORD ends only at whitespace. The edits with Word in their name follow Unicode word rules, the way Emacs mode moves, so foo.bar and can't are one word each while foo-bar and foo|bar are two. Vi's w and the word motion stop at any punctuation, so foo.bar is three words there.

Inserting and replacing text

EditWhat it does
InsertChar value: <char>Inserts one character, replacing the selection
InsertString value: <string>Inserts the text, replacing the selection
InsertNewlineInserts a newline, replacing the selection
InsertNewlineAbove, InsertNewlineBelowOpens an empty line above or below the current one and moves the cursor there
InsertPair open: <char>, close: <char>Inserts both characters with the cursor between them, or wraps the selection in them
ReplaceChar value: <char>Replaces the character under the cursor, or each selected character

Deleting

These delete text without putting it in the cut buffer.

EditDeletes
Backspace, DeleteThe character before or under the cursor
BackspaceWord, DeleteWordThe word before or after the cursor
BackspacePair open: <char>, close: <char>Both characters, when the cursor sits between an empty open and close pair. Otherwise it does nothing
ClearThe whole buffer
ClearToLineEndFrom the cursor to the end of the line
EraseSelectionThe selection

Cutting

These remove text and put it in the cut buffer.

EditCuts
CutChar, CutCharLeftThe character under or before the cursor
CutWordLeft, CutBigWordLeftThe word or WORD before the cursor
CutWordRight, CutBigWordRightThe word or WORD after the cursor
CutWordRightToNext, CutBigWordRightToNextThe word or WORD after the cursor and the whitespace that follows it
CutFromStart, CutToEndFrom the start of the buffer to the cursor, or from the cursor to the end of the buffer
CutFromLineStart, CutToLineEndFrom the start of the line to the cursor, or from the cursor to the end of the line
CutFromLineNonBlankStartFrom the first character of the line that isn't a space or tab, to the cursor
KillLineFrom the cursor to the end of the line, or the line break when the cursor is already at the end (Emacs Ctrl+K)
CutCurrentLineThe whole line, as whole lines
CutFromStartLinewise, CutToEndLinewise keep_line: <bool>Whole lines, from the first line to the cursor's line, or from the cursor's line to the last. keep_line is required. With true, an empty line stays in their place
CutLeftUntil, CutRightUntil value: <char>From the cursor through the previous or next value character
CutLeftBefore, CutRightBefore value: <char>From the cursor up to the previous or next value character, leaving that character
CutSelection granularity?: <string>The selection. With granularity: linewise, the whole lines the selection touches

Copying

The copy edits put text in the cut buffer and leave the line as it is. Each one copies the same text that the cut edit with the matching name would cut: CopyWordLeft, CopyBigWordLeft, CopyWordRight, CopyBigWordRight, CopyWordRightToNext, CopyBigWordRightToNext, CopyFromStart, CopyToEnd, CopyFromLineStart, CopyToLineEnd, CopyFromLineNonBlankStart, CopyCurrentLine, CopyLeftUntil, CopyRightUntil, CopyLeftBefore, CopyRightBefore (these four take value: <char>) and CopySelection. The line-wise CopyFromStartLinewise and CopyToEndLinewise take no keep_line field. CopyLeft and CopyRight copy the character before or under the cursor.

Pasting

EditWhat it does
PasteCutBufferBefore, PastePastes the cut buffer before the cursor (Emacs Ctrl+Y, Vi P). The two names do the same thing
PasteCutBufferAfterPastes the cut buffer after the cursor (Vi p)
PasteAtSelectionEdge direction: <string>, count?: <int>Pastes the cut buffer count times (default 1) after the selection (forward) or before it (backward), and selects what it pasted. Line-wise text isn't pasted

The system clipboard

CutSelectionSystem, CopySelectionSystem and PasteSystem work like CutSelection, CopySelection and PasteCutBufferBefore, but with the system clipboard instead of the cut buffer. They exist only when Nushell is built with the system-clipboard feature, which version | get features lists. In a build without it, a keybinding that names one of them is an error, like any unknown edit.

Changing case and swapping

EditWhat it does
UppercaseWord, LowercaseWordChanges the case of the whole word under the cursor
CapitalizeWordUppercases the first letter of the word under the cursor and lowercases the rest
CapitalizeCharUppercases the character under the cursor
SwitchcaseCharSwitches the case of the character under the cursor
UppercaseSelection, LowercaseSelection, SwitchcaseSelectionChanges the case of the selection
SwapGraphemesSwaps the characters on either side of the cursor (Emacs Ctrl+T)
SwapWordsSwaps the word under the cursor with the next word

Undo, completion and selection

EditWhat it does
Undo, RedoUndoes the last change, or redoes an undone one
CompleteWith a completion menu open and completions.quick on, accepts the suggestion if it's the only one. Otherwise, with completions.partial on, fills in the text the suggestions share. Without a menu it changes nothing
SelectAllSelects the whole buffer
SelectLineExtends the selection to the whole lines it touches, or by one more line when it already covers whole lines (Helix x)
SwapCursorAndAnchorMoves the cursor to the other end of the selection (Vi visual o)
CollapseSelection direction: <string>Drops the selection, leaving the cursor at its start (backward) or its end (forward)

Nushell's Tab binding tries Complete after the menu events, which is how a second Tab can fill in a shared prefix.

Motions

Seven edits act on a motion, which says where the cursor goes. They're the general form behind many of the edits above:

EditWhat it does with the motion
MoveMoves the cursor
ExtendMoves the cursor and keeps the other end of the selection where it is, so the selection grows
SelectSelects from the cursor to where the motion lands
CutCuts from the cursor to where the motion lands
CopyCopies the same text
ChangeCuts like Cut. With granularity: linewise it leaves an empty line, like Vi cc
EraseDeletes the same text without the cut buffer

The motion field picks the motion, and the other fields describe it. direction is forward or backward.

motionOther fieldsGoes to
graphemedirectionThe next or previous character
wordword_kind (word or longword), edge (start or end), directionThe start or end of a word, or of a WORD with longword, like Vi w, b, e
lineedgedirectionThe start (backward) or end (forward) of the line
bufferedgedirectionThe start or end of the buffer
linedirectionThe line above (backward) or below (forward)
findchar, direction, stop (on or before)The next or previous char, or next to it with stop: before, like Vi f and t

With motion: word, a word ends at whitespace and at punctuation, as for Vi's w, and a longword only at whitespace.

Cut, Copy and Change also take granularity, which is charwise (the default) or linewise for whole lines. This binding cuts from the cursor to the end of the WORD, like Vi dE:

$env.config.keybindings ++= [{
    name: cut_to_word_end
    modifier: alt
    keycode: char_x
    mode: emacs
    event: { edit: Cut, motion: word, word_kind: longword, edge: end, direction: forward }
}]

Text objects

CutTextObject, CopyTextObject and SelectTextObject act on the text object around the cursor, like Vi's di(. They take these fields:

  • scope: inner for the text inside the object, around to include the delimiters.
  • object_type: word, bigword, brackets (whichever of (), [], {} or <> is closest), quotes (whichever of ", ' or ` is closest), or one pair: parentheses, square_brackets, curly_brackets, angle_brackets, single_quotes, double_quotes or backticks. The singular spellings, such as parenthesis, work too. Any other pair is a record of two characters, { left: "|", right: "|" }.
  • check_next (default true): when the cursor isn't inside a matching object, act on the next one in the line. With false, the edit then does nothing.

Three more edits change the delimiters themselves. AddTextObject wraps the selection in a pair, RemoveTextObject removes the closest pair around the cursor, and ReplaceTextObject swaps the closest old pair around the cursor for a new one. Their object_type, old and new fields must name a single pair, so word, bigword, brackets and quotes are errors there. These two bindings select the text inside the next pair of quotes, then wrap it in brackets:

$env.config.keybindings ++= [
    {
        name: select_in_quotes
        modifier: alt
        keycode: char_q
        mode: emacs
        event: { edit: SelectTextObject, scope: inner, object_type: quotes }
    }
    {
        name: wrap_in_brackets
        modifier: alt
        keycode: char_b
        mode: emacs
        event: { edit: AddTextObject, object_type: square_brackets }
    }
]

On the line echo "foo bar", Alt+Q and then Alt+B give echo "[foo bar]".

The older pair edits, such as CutInsidePair, still work and become text object edits, see Edit Type.

Edit this page on GitHub
Contributors: Fernando Herrera, rgwood, Reilly Wood, Justin Ma, chtenb, fdncred, Stefan Holderbach, Zhora Trush, Dan Davison, TornaxO7, Joel Afriyie, Máté FARKAS, Mate Farkas, uselesspseudo, amtoine, Marika Chlebowska, TheJiahao, Brad Dunbar, suimong, వీవెన్, Bruce Weirdan, Hofer-Julian, NotTheDr01ds, Jan Klass, Axlefublr, Raphael Das Gupta, casedami
Prev
Directory Stack
Next
Custom Completions