Skip to content
Tutorials Center
My learning

Topics

Lesson 33 of 36 ยท Workflows

Vi Keys Everywhere

Take Vim's keys beyond the editor: vi mode in bash, zsh and readline, tmux copy mode, less and man, IdeaVim and VS Code, the command-line window, and browser extensions.

The most valuable thing Vim gives you is not the program but the language: operators, motions, counts, text objects. Once you know it, you can use it in dozens of other tools. This lesson lists where vi-style keys are available, how to switch them on and where the emulation falls short.

In the shell

Both bash and zsh offer vi editing for the command line.

Bash uses the GNU Readline library:

Terminal
set -o vi                 # in the current session or ~/.bashrc

or, for every program that uses Readline (Python's REPL, psql, mysql...), put this in ~/.inputrc:

TEXT
set editing-mode vi
set show-mode-in-prompt on

Zsh:

ZSH
bindkey -v
export KEYTIMEOUT=1       # make Esc fast (units of 10 ms)

You start in insert mode. Press Esc and you are in normal mode with h l w b 0 $ x dw cw dd p u and friends; k and j walk through history; / and ? search history (/git then n). Pressing v opens the current command in $EDITOR (Vim), a pleasant way to edit a long pipeline: write it, :wq, and the shell runs it. (In zsh enable it by binding edit-command-line.) The shell versions are partial: no text objects, limited registers, and dot repeat works but macros do not.

Fish has fish_vi_key_bindings.

In tmux, less, man

  • tmux: set-window-option -g mode-keys vi in ~/.tmux.conf gives vi keys in copy mode. Press prefix then [ to enter copy mode, move with hjkl, w, b, / to search, v to start a selection, y to copy (with the usual bind -T copy-mode-vi v send -X begin-selection bindings). set -g status-keys vi does the same for tmux's own command prompt.
  • less and man use many Vim-like keys already: j/k, Ctrl-d/Ctrl-u, g/G, / and ?, n/N. v in less opens the file in your editor.
  • git pagers, top-like tools (htop, btop) and many TUI programs (lazygit, ranger, yazi, k9s) follow the same conventions.
  • vimtutor is a 30-minute interactive lesson; Neovim has :Tutor.

In IDEs and other editors

Editor Plugin Notes
JetBrains IDEs IdeaVim Config file ~/.ideavimrc accepts many Vim commands, set options, map and an ideaVim action list; plugins like surround and commentary are emulated
VS Code VSCodeVim, or the VS Code Neovim extension VSCodeVim emulates Vim in JavaScript with settings.json entries (vim.leader, vim.normalModeKeyBindingsNonRecursive); the Neovim extension embeds a real Neovim instance, so Lua config works
Visual Studio VsVim Includes .vsvimrc
Emacs Evil mode (or the Doom/Spacemacs setups) A thorough Vim emulation
Sublime Text Vintageous/NeoVintageous Basic to good
Obsidian, Zed, Helix built-in or optional Vim modes Helix has a different, selection-first model

Tips:

  • Keep one set of shortcuts in your head: use the same leader key and the same few mappings in every environment.
  • Disable the emulation's conflicts: IDE shortcuts like Ctrl-c, Ctrl-v and Ctrl-r may be taken by the editor or by Vim. Most plugins let you choose per key.
  • Know the limits: IDE-based emulators handle the editing language very well but do not run your vimrc or Vim script plugins (except where they say so).

In the browser

Extensions such as Vimium, Vimium C and Tridactyl (Firefox) bring keys for scrolling (j, k, d, u, gg, G), link hints (f), tab switching (J, K), search (/) and history. They do not give you operators, because a web page is not editable text; for text boxes, some sites offer a "edit in external editor" option.

The command-line window

Back inside Vim there is one more place to apply what you know. Pressing q: opens the command-line window: your Ex command history as an ordinary buffer. Edit any old command with all your motions, then Enter runs it. q/ does the same for search history, and Ctrl-f while typing a command switches from the one-line prompt to this window. Close it with :q or Ctrl-c.

A small vi-mode model

JS Stand-in: a tiny vi-mode line editor

Press Run (or Ctrl + Enter) to see the console output here.

No output.

JS Stand-in: which key conventions overlap?

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. How do you turn on vi editing for the bash command line?

    set -o vi (or editing-mode vi in ~/.inputrc) enables vi mode in Readline. bindkey -v is the zsh command.
  2. 2. What does the command-line window q: show?

    q: opens the Ex history; press Enter on a line to run it after editing.
  3. 3. Which tmux setting gives vi keys in copy mode?

    mode-keys vi enables hjkl, / and v in copy mode; status-keys vi affects the command prompt.
  4. 4. What is a limitation of IDE Vim emulations such as IdeaVim and VSCodeVim?

    They implement the editing language themselves; only the VS Code Neovim extension embeds real Neovim.

Summary

  • Vim's keys work in shells (set -o vi, bindkey -v), tmux (mode-keys vi), less, many TUIs, IDEs and browsers.
  • Press v in a vi-mode shell to edit a long command in Vim.
  • IdeaVim, VSCodeVim and others emulate Vim; the VS Code Neovim extension embeds the real one.
  • q: and q/ open history as editable buffers.

Next: Project: Build a Starter vimrc