ajaxorg/ace · error · Error

(Vim.defineEx) "'+prefix+'" is not a prefix of "'+name+'", c

Error message

(Vim.defineEx) "'+prefix+'" is not a prefix of "'+name+'", command not registered

What it means

Vim.defineEx(name, prefix, func) requires prefix to be a prefix of the command name (or omitted). Registering an ex command whose prefix isn't actually a prefix of the name would create an inconsistent command map, so it throws without registering.

Source

Thrown at src/keyboard/vim.js:1675

                  }
                }
              }
            }
          }
        }
      },
      langmap: updateLangmap,
      vimKeyFromEvent: vimKeyFromEvent,
      // TODO: Expose setOption and getOption as instance methods. Need to decide how to namespace
      // them, or somehow make them work with the existing CodeMirror setOption/getOption API.
      setOption: setOption,
      getOption: getOption,
      defineOption: defineOption,
      defineEx: function(name, prefix, func){
        if (!prefix) {
          prefix = name;
        } else if (name.indexOf(prefix) !== 0) {
          throw new Error('(Vim.defineEx) "'+prefix+'" is not a prefix of "'+name+'", command not registered');
        }
        exCommands[name]=func;
        exCommandDispatcher.commandMap_[prefix]={name:name, shortName:prefix, type:'api'};
      },
      handleKey: function (cm, key, origin) {
        var command = this.findKey(cm, key, origin);
        if (typeof command === 'function') {
          return command();
        }
      },
      multiSelectHandleKey: multiSelectHandleKey,

      /**
       * This is the outermost function called by CodeMirror, after keys have
       * been mapped to their Vim equivalents.
       *
       * Finds a command based on the key (and cached keys if there is a
       * multi-key sequence). Returns `undefined` if no key is matched, a noop

View on GitHub (pinned to 2c1eddc392)

Solutions

  1. Make prefix an actual prefix of name, or pass null/undefined prefix to use the full name as prefix
  2. Fix the name/prefix pair so name.indexOf(prefix) === 0
  3. Remove the prefix argument if no abbreviation is needed

Example fix

// before
Vim.defineEx('writeall', 'wa!', fn); // 'wa!' not a prefix
// after
Vim.defineEx('writeall', 'wa', fn);
Defensive patterns

Strategy: validation

Validate before calling

function safeDefineEx(Vim, name, prefix, func) {
  if (prefix && name.indexOf(prefix) !== 0) throw new Error('prefix must start name');
  Vim.defineEx(name, prefix, func);
}

Type guard

function isValidExPair(name, prefix) { return !prefix || name.indexOf(prefix) === 0; }

Try / catch

try { Vim.defineEx(name, prefix, fn); } catch (e) { if (/is not a prefix of/.test(e.message)) Vim.defineEx(name, null, fn); else throw e; }

Prevention

When it happens

Trigger: CodeMirror.defineEx('wq', 'w!', fn) or defineEx('substitute', 's', fn) where the prefix string isn't a leading substring of name.

Common situations: Custom ex command registration with abbreviated names that don't match; copy-pasted defineEx calls where name was edited but prefix wasn't.

Related errors


AI-assisted analysis of ajaxorg/ace@2c1eddc392 (2026-08-30). Data as JSON: /api/errors/621f2c238443cf43. Report an issue: GitHub.