Skip to main content

Overview

The Vim.unmap() function removes previously defined key mappings created with Vim.map() or Vim.noremap().

Signature

Vim.unmap(lhs: string, context?: string): void

Parameters

lhs
string
required
The left-hand side: the key sequence to unmap. This should match the lhs parameter used when creating the mapping.
context
string
The mode context from which to remove the mapping. Valid values:
  • "insert" - Remove mapping from insert mode
  • "normal" - Remove mapping from normal mode (default)
  • "visual" - Remove mapping from visual mode
If omitted, removes the mapping from normal mode.

Return Value

return
void
This function does not return a value.

Examples

Unmap in Insert Mode

Remove the jj to <Esc> mapping:
import { Vim } from "@replit/codemirror-vim";

// First create a mapping
Vim.map("jj", "<Esc>", "insert");

// Later, remove it
Vim.unmap("jj", "insert");

Unmap in Normal Mode

Remove a normal mode mapping:
// Create a mapping
Vim.map("Y", "y$");

// Remove it
Vim.unmap("Y");

Conditional Unmapping

Unmap based on user preference:
function toggleJJMapping(enabled) {
  if (enabled) {
    Vim.map("jj", "<Esc>", "insert");
  } else {
    Vim.unmap("jj", "insert");
  }
}

Notes

  • Unmapping a non-existent mapping has no effect and does not throw an error
  • The context parameter must match the context used when creating the mapping
  • You cannot unmap built-in Vim keybindings, only user-defined mappings
  • Key mappings are global and affect all editor instances

See Also

Build docs developers (and LLMs) love