# Reedline, Nu's Line Editor
Nushell's line-editor [Reedline](https://github.com/nushell/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,
screen paint, and more.
[[toc]]
## Multi-line Editing
Reedline allows Nushell commandlines to extend across multiple lines. This can be accomplished using several methods:
1. Pressing <kbd>Enter</kbd> when a bracketed expression is open.
For example:
```nu
def my-command [] {
```
Pressing <kbd>Enter </kbd> after the open-bracket will insert a newline. This will also occur with opening (and valid) `(` and `[` expressions.
This is commonly used to create blocks and closures (as above), but also list, record, and table literals:
```nu
let file = {
name: 'repos.sqlite'
hash: 'b939a3fa4ca011ca1aa3548420e78cee'
version: '1.4.2'
}
```
It can even be used to continue a single command across multiple lines:
::: details Example
```nu
(
tar
-cvz
-f archive.tgz
--exclude='*.temp'
--directory=../project/
./
)
```
:::
2. Pressing <kbd>Enter</kbd> at the end of a line with a trailing pipe-symbol (`|`).
```nu
ls |
where name =~ '^[0-9]' | # Comments after a trailing pipe are okay
get name |
mv ...$in ./backups/
```
3. Manually insert a newline using <kbd>Alt</kbd>+<kbd>Enter</kbd> or <kbd>Shift</kbd>+<kbd>Enter</kbd>.
This can be used to create a somewhat more readable version of the previous commandline:
```nu
ls
| where name =~ '^[0-9]' # Files starting with a digit
| get name
| mv ...$in ./backups/
```
::: tip
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 <kbd>Alt</kbd>+<kbd>Enter</kbd> to expand the terminal to full-screen. If neither of the above keybindings work in your terminal, you can assign a different keybinding to:
```nu
event: { edit: insertnewline }
```
See [Keybindings](#keybindings) below for more details.
:::
4. Pressing <kbd>Ctrl</kbd>+<kbd>O</kbd> opens the current commandline in your editor. Saving the resulting file and exiting the editor will update the commandline with the results.
## Setting the Editing Mode
Reedline allows you to edit text using two modes — Vi and Emacs. If not
specified, the default mode is Emacs. To change the mode, use the
`edit_mode` setting.
```nu
$env.config.edit_mode = 'vi'
```
This can be changed at the commandline or persisted in `config.nu`.
::: note
Vi is a "modal" editor with "normal" mode and an "insert" 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.
:::
## Default Keybindings
Each edit mode comes with common keybindings for Vi and Emacs text editing.
### Emacs and Vi-insert Keybindings
These keybinding events apply to both Emacs and Vi-insert mode:
| Key | Event |
| ------------------------------------------ | ----------------------------------- |
| <kbd>Shift</kbd>+<kbd>Enter</kbd> | Insert newline |
| <kbd>Alt</kbd>+<kbd>Enter</kbd> | Insert newline |
| <kbd>Backspace</kbd> | Backspace |
| <kbd>End</kbd> | Move to end of line |
| <kbd>End</kbd> | Complete history hint |
| <kbd>Home</kbd> | Move to line start |
| <kbd>Ctrl</kbd>+<kbd>C</kbd> | Cancel current line |