diff --git a/.gitignore b/.gitignore index a6a024274..5a7241d6b 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ test.txt .history src/.history src/moepkg/.history +*.gdb diff --git a/documents/configfile.md b/documents/configfile.md index 4336b3f48..ff5b26a2f 100644 --- a/documents/configfile.md +++ b/documents/configfile.md @@ -1463,3 +1463,18 @@ Current line background color ``` currentLineBg ``` + +### Map command + +Define character level keymap in normal mode: +``` +[Map.Normal] +";" = ":" +``` + +Likewise, define keymap in visual mode with: +``` +[Map.Visual] +";" = ":" +``` + diff --git a/src/moepkg/normalmode.nim b/src/moepkg/normalmode.nim index 0ed113e28..25793a902 100644 --- a/src/moepkg/normalmode.nim +++ b/src/moepkg/normalmode.nim @@ -1,8 +1,8 @@ from strutils import parseInt -import terminal, times +import terminal, times, tables import editorstatus, ui, gapbuffer, unicodeext, fileutils, undoredostack, window, movement, editor, search, color, bufferstatus, quickrun, - messages, commandline + messages, commandline, settings proc searchOneCharactorToEndOfLine(bufStatus: var BufferStatus, windowNode: WindowNode, @@ -878,6 +878,8 @@ proc normalMode*(status: var EditorStatus) = if not pressCtrlC: status.eventLoopTask key = getKey(currentMainWindowNode) + if key in status.settings.commandMaps: + key = status.settings.commandMaps[key] else: pressCtrlC = false status.commandLine.writeExitHelp diff --git a/src/moepkg/settings.nim b/src/moepkg/settings.nim index b8efe3331..48cbce13f 100644 --- a/src/moepkg/settings.nim +++ b/src/moepkg/settings.nim @@ -148,6 +148,8 @@ type PersistSettings* = object exCommand*: bool search*: bool +type CommandMaps* = Table[Rune, Rune] + type EditorSettings* = object editorColorTheme*: ColorTheme statusLine*: StatusLineSettings @@ -182,6 +184,7 @@ type EditorSettings* = object debugModeSettings*: DebugModeSettings highlightSettings*: HighlightSettings persist*: PersistSettings + commandMaps*: CommandMaps # Warning: inherit from a more precise exception type like ValueError, IOError or OSError. # If these don't suit, inherit from CatchableError or Defect. [InheritFromException] @@ -1612,6 +1615,12 @@ proc parseSettingsFile*(settings: TomlValueRef): EditorSettings = if vscodeTheme: result.editorColorTheme = loadVSCodeTheme() + if settings.contains("Map"): + if settings["Map"].contains("Normal"): + result.commandMaps = initTable[Rune, Rune]() + for k, v in settings["Map"]["Normal"].getTable().pairs: + result.commandMaps[k.runeAt(0)] = ($v).runeAt(0) + proc validateTomlConfig(toml: TomlValueRef): Option[string] = template validateStandardTable() = for item in json["Standard"].pairs: