﻿---
title: Shell Inline Editing & Vim/Emacs Keybindings
date: 2025-08-14
excerpt: A deep dive into inline editing in the terminal — configuring Vi and Emacs keybindings and using an external line editor to speed up your workflow.
tags:
  - Shell
  - Workflow
  - Nushell
  - Vim
cover: https://assets.vluv.space/cover/inline-editing.avif
updated: 2026-05-23 15:36:36
lang: en
i18n:
  cn: /inline_editing
  translation: 2
---

## Inline Edit Mode: Emacs or Vim

Shells typically use `emacs` keybindings by default. You can also switch to Vim-style keybindings:

- **Bash**: `{bash} set -o vi`
- **Zsh**: `{zsh} bindkey -v`
- **Nushell**: `{nu} $env.config.edit_mode = vi`
- **Fish**: `{fish} fish_vi_key_bindings`

![shell_emacs_shortcut|700](https://assets.vluv.space/piclist-clipboard-images-20260206183527683.avif)

## Vim Tricks

### Text Objects

Text Objects[^1] are the Vim feature that drew me in the most. They let you operate on text by semantic units — deleting content inside brackets or quotes becomes effortless. For example, in **NORMAL mode**, move the cursor inside a pair of brackets and type `di(` or `dib` (delete inside bracket) to delete the text within:

```nushell
$env.LS_COLORS = (vivid generate catppuccin-mocha)
# press `dib` inside bracket
$env.LS_COLORS = ()
```

### Cursor Jump

Navigating long commands is where Vim keybindings really shine.

| Key       | Action                                                    |
| --------- | --------------------------------------------------------- |
| `w` / `b` | Next word / previous word                                 |
| `I` / `A` | Jump to line start and insert / jump to line end and insert |
| `F<char>` | Search backward for `<char>` and jump                     |
| `f<char>` | Search forward for `<char>` and jump                      |

When editing `UNIX` or `GNU`-style command-line arguments, using `F/f` to hop between arguments feels remarkably smooth.

| Style       | Prefix | Format | Example                | Jump Strategy              |
| ----------- | ------ | ------ | ---------------------- | -------------------------- |
| **Unix**    | `-`    | Letter | `{shell} ls -la`       | Use `f-` to jump to option |
| **GNU**     | `--`   | Word   | `{shell} grep --color` | Use `f-`                   |
| **Windows** | `/`    | Word   | `{shell} DIR /W`       | Use `f/`                   |

## Line Editor

Many shells also support editing commands in an external editor — so you can use NeoVim or Helix to edit your command line. If you don't mind startup time, even VSCode works. 🤓

| Shell   | Vi Mode                    | Emacs Mode       |
| ------- | -------------------------- | ---------------- |
| Bash    | Press `v` in Normal mode   | `Ctrl+x Ctrl+e`  |
| Zsh     | No idea `චᆽච`              | No idea `චᆽච`   |
| Fish    | `Alt+e`                    | `Alt+e`          |
| Nushell | `Ctrl+o`                   | `Ctrl+o`         |

Here's a quick demo: say you're using `scp` to copy a file from a remote machine to local, but you mistyped the hostname.

<video autoplay loop muted playsinline>
    <source src="https://assets.vluv.space/inline-editing.mp4" type="video/mp4" alt="demo">
</video>

**Isn't this cool? As a STEM nerd, I think this is incredibly cool.** 🤓🤓🤓

### Change Default Editor

How do you choose which editor opens?

Generally, shells read the `VISUAL` or `EDITOR` environment variable to decide which editor to use. Nushell also supports the `$env.config.buffer_editor` variable.

```shell
# ----------------------------------------
# For Nushell (config.nu)
# ----------------------------------------
$env.config = {
   # Prefer a fast-starting editor like Helix/Neovim/Vim
   buffer_editor: "helix"  # [!code ++]
}

# ----------------------------------------
# For Bash / Zsh (.bashrc or .zshrc)
# ----------------------------------------
# VISUAL usually takes precedence over EDITOR
export VISUAL=nvim  # [!code ++]
export EDITOR=nvim

# ----------------------------------------
# For Fish (config.fish)
# ----------------------------------------
set -gx VISUAL nvim  # [!code ++]
```

For setting system environment variables on Unix, see 👉 [[unix_environment_variables|Set System Env-Vars in UNIX]]

[^1]: Text Objects can be quotes, brackets, words, sentences, paragraphs, and more. For details, see [Motion#text-objects - Neovim docs](https://neovim.io/doc/user/motion.html#text-objects)