Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ test.txt
.history
src/.history
src/moepkg/.history
*.gdb
15 changes: 15 additions & 0 deletions documents/configfile.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
";" = ":"
```

6 changes: 4 additions & 2 deletions src/moepkg/normalmode.nim
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions src/moepkg/settings.nim
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ type PersistSettings* = object
exCommand*: bool
search*: bool

type CommandMaps* = Table[Rune, Rune]

type EditorSettings* = object
editorColorTheme*: ColorTheme
statusLine*: StatusLineSettings
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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:
Expand Down