Skip to content

Commit

Permalink
added more vim keybindings
Browse files Browse the repository at this point in the history
  • Loading branch information
Nimaoth committed Jan 14, 2024
1 parent 4e89efa commit 0f1b30e
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 69 deletions.
124 changes: 55 additions & 69 deletions config/default_config.nim
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
import absytree_runtime
import std/[strutils, sugar, sequtils, macros, json]

import keybindings_vim
import keybindings_helix
import keybindings_normal

export keybindings_vim
export keybindings_helix
export keybindings_normal

import languages

# Only when compiled to wasm.
Expand Down Expand Up @@ -183,10 +175,6 @@ proc loadDefaultKeybindings*(clearExisting: bool = false) =
setOption("editor.text.line-numbers", LineNumbers.Relative)
requestRender(true)

addCommand "editor", "kn", () => loadNormalKeybindings()
addCommand "editor", "kv", () => loadVimKeybindings()
addCommand "editor", "kh", () => loadHelixKeybindings()

addCommandBlock "editor", "dl": lspLogVerbose(true)
addCommandBlock "editor", "dL": lspLogVerbose(false)

Expand All @@ -209,63 +197,61 @@ proc loadDefaultKeybindings*(clearExisting: bool = false) =
addCommand "popup.selector", "<C-u>", "prev-x"
addCommand "popup.selector", "<C-d>", "next-x"

loadNormalKeybindings()

addCommand "editor.text", "<C-SPACE>ts", "reload-treesitter"

setHandleInputs("editor.model", true)
addCommand("editor.model", "<LEFT>", "move-cursor-left-line")
addCommand("editor.model", "<RIGHT>", "move-cursor-right-line")
addCommand("editor.model", "<A-LEFT>", "move-cursor-left")
addCommand("editor.model", "<A-RIGHT>", "move-cursor-right")
addCommand("editor.model", "<UP>", "move-cursor-up")
addCommand("editor.model", "<DOWN>", "move-cursor-down")
addCommand("editor.model", "<A-UP>", "select-node")
addCommand("editor.model", "<A-DOWN>", "move-cursor-down")
addCommand("editor.model", "<C-LEFT>", "move-cursor-left-cell")
addCommand("editor.model", "<C-RIGHT>", "move-cursor-right-cell")
addCommand("editor.model", "<HOME>", "move-cursor-line-start")
addCommand("editor.model", "<END>", "move-cursor-line-end")
addCommand("editor.model", "<A-HOME>", "move-cursor-line-start-inline")
addCommand("editor.model", "<A-END>", "move-cursor-line-end-inline")

addCommand("editor.model", "<S-LEFT>", "move-cursor-left-line", true)
addCommand("editor.model", "<S-RIGHT>", "move-cursor-right-line", true)
addCommand("editor.model", "<SA-LEFT>", "move-cursor-left", true)
addCommand("editor.model", "<SA-RIGHT>", "move-cursor-right", true)
addCommand("editor.model", "<S-UP>", "move-cursor-up", true)
addCommand("editor.model", "<S-DOWN>", "move-cursor-down", true)
addCommand("editor.model", "<SA-UP>", "move-cursor-up", true)
addCommand("editor.model", "<SA-DOWN>", "move-cursor-down", true)
addCommand("editor.model", "<SC-LEFT>", "move-cursor-left-cell", true)
addCommand("editor.model", "<SC-RIGHT>", "move-cursor-right-cell", true)
addCommand("editor.model", "<S-HOME>", "move-cursor-line-start", true)
addCommand("editor.model", "<S-END>", "move-cursor-line-end", true)
addCommand("editor.model", "<SA-HOME>", "move-cursor-line-start-inline", true)
addCommand("editor.model", "<SA-END>", "move-cursor-line-end-inline", true)

addCommand("editor.model", "<C-z>", "undo")
addCommand("editor.model", "<C-y>", "redo")
addCommand("editor.model", "<BACKSPACE>", "replace-left")
addCommand("editor.model", "<DELETE>", "replace-right")
addCommand("editor.model", "<SPACE>", "insert-text-at-cursor", " ")
addCommand("editor.model", "<ENTER>", "create-new-node")
addCommand("editor.model", "<TAB>", "select-next-placeholder")
addCommand("editor.model", "<S-TAB>", "select-prev-placeholder")

addCommand("editor.model", "<C-SPACE>", "show-completions")

addCommand("editor.model", "<LEADER>mr", "run-selected-function")
addCommand("editor.model", "<LEADER>md", "toggle-use-default-cell-builder")

addCommand("editor.model.completion", "<ENTER>", "finish-edit", true)
addCommand("editor.model.completion", "<ESCAPE>", "hide-completions")
addCommand("editor.model.completion", "<UP>", "select-prev-completion")
addCommand("editor.model.completion", "<DOWN>", "select-next-completion")
addCommand("editor.model.completion", "<C-SPACE>", "move-cursor-start")
addCommand("editor.model.completion", "<TAB>", "apply-selected-completion")

addCommand "editor.model.goto", "<END>", "end"
# addCommand "editor.text", "<C-SPACE>ts", "reload-treesitter"

# setHandleInputs("editor.model", true)
# addCommand("editor.model", "<LEFT>", "move-cursor-left-line")
# addCommand("editor.model", "<RIGHT>", "move-cursor-right-line")
# addCommand("editor.model", "<A-LEFT>", "move-cursor-left")
# addCommand("editor.model", "<A-RIGHT>", "move-cursor-right")
# addCommand("editor.model", "<UP>", "move-cursor-up")
# addCommand("editor.model", "<DOWN>", "move-cursor-down")
# addCommand("editor.model", "<A-UP>", "select-node")
# addCommand("editor.model", "<A-DOWN>", "move-cursor-down")
# addCommand("editor.model", "<C-LEFT>", "move-cursor-left-cell")
# addCommand("editor.model", "<C-RIGHT>", "move-cursor-right-cell")
# addCommand("editor.model", "<HOME>", "move-cursor-line-start")
# addCommand("editor.model", "<END>", "move-cursor-line-end")
# addCommand("editor.model", "<A-HOME>", "move-cursor-line-start-inline")
# addCommand("editor.model", "<A-END>", "move-cursor-line-end-inline")

# addCommand("editor.model", "<S-LEFT>", "move-cursor-left-line", true)
# addCommand("editor.model", "<S-RIGHT>", "move-cursor-right-line", true)
# addCommand("editor.model", "<SA-LEFT>", "move-cursor-left", true)
# addCommand("editor.model", "<SA-RIGHT>", "move-cursor-right", true)
# addCommand("editor.model", "<S-UP>", "move-cursor-up", true)
# addCommand("editor.model", "<S-DOWN>", "move-cursor-down", true)
# addCommand("editor.model", "<SA-UP>", "move-cursor-up", true)
# addCommand("editor.model", "<SA-DOWN>", "move-cursor-down", true)
# addCommand("editor.model", "<SC-LEFT>", "move-cursor-left-cell", true)
# addCommand("editor.model", "<SC-RIGHT>", "move-cursor-right-cell", true)
# addCommand("editor.model", "<S-HOME>", "move-cursor-line-start", true)
# addCommand("editor.model", "<S-END>", "move-cursor-line-end", true)
# addCommand("editor.model", "<SA-HOME>", "move-cursor-line-start-inline", true)
# addCommand("editor.model", "<SA-END>", "move-cursor-line-end-inline", true)

# addCommand("editor.model", "<C-z>", "undo")
# addCommand("editor.model", "<C-y>", "redo")
# addCommand("editor.model", "<BACKSPACE>", "replace-left")
# addCommand("editor.model", "<DELETE>", "replace-right")
# addCommand("editor.model", "<SPACE>", "insert-text-at-cursor", " ")
# addCommand("editor.model", "<ENTER>", "create-new-node")
# addCommand("editor.model", "<TAB>", "select-next-placeholder")
# addCommand("editor.model", "<S-TAB>", "select-prev-placeholder")

# addCommand("editor.model", "<C-SPACE>", "show-completions")

# addCommand("editor.model", "<LEADER>mr", "run-selected-function")
# addCommand("editor.model", "<LEADER>md", "toggle-use-default-cell-builder")

# addCommand("editor.model.completion", "<ENTER>", "finish-edit", true)
# addCommand("editor.model.completion", "<ESCAPE>", "hide-completions")
# addCommand("editor.model.completion", "<UP>", "select-prev-completion")
# addCommand("editor.model.completion", "<DOWN>", "select-next-completion")
# addCommand("editor.model.completion", "<C-SPACE>", "move-cursor-start")
# addCommand("editor.model.completion", "<TAB>", "apply-selected-completion")

# addCommand "editor.model.goto", "<END>", "end"

proc exampleScriptAction*(a: int, b: string): string {.scriptActionWasmNims("example-script-action").} =
## Test documentation stuff
Expand Down
23 changes: 23 additions & 0 deletions config/keybindings_vim.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import std/[strutils, setutils]
import absytree_runtime, keybindings_normal
import misc/[timer]


infof"import vim keybindings"

proc getVimLineMargin*(): float = getOption[float]("editor.text.vim.line-margin", 5)
proc getVimClipboard*(): string = getOption[string]("editor.text.vim.clipboard", "")
proc getVimDefaultRegister*(): string =
Expand Down Expand Up @@ -272,6 +275,7 @@ proc loadVimKeybindings*() {.scriptActionWasmNims("load-vim-keybindings").} =
setOption "editor.text.cursor.wide.", true

setModeChangedHandler proc(editor, oldMode, newMode: auto) =
# infof"vim: handle mode change {oldMode} -> {newMode}"
if newMode != "normal":
editor.clearCurrentCommandHistory(retainLast=true)

Expand Down Expand Up @@ -310,6 +314,25 @@ proc loadVimKeybindings*() {.scriptActionWasmNims("load-vim-keybindings").} =
editor.setMode("normal")
editor.selection = editor.selection.last.toSelection

# windowing
addCommand "editor", "<C-w><RIGHT>", "prev-view"
addCommand "editor", "<C-w>h", "prev-view"
addCommand "editor", "<C-w><C-h>", "prev-view"
addCommand "editor", "<C-w><LEFT>", "next-view"
addCommand "editor", "<C-w>l", "next-view"
addCommand "editor", "<C-w><C-l>", "next-view"
addCommand "editor", "<C-w>w", "next-view"
addCommand "editor", "<C-w><C-w>", "next-view"
addCommand "editor", "<C-w>p", "open-previous-editor"
addCommand "editor", "<C-w><C-p>", "open-previous-editor"
addCommand "editor", "<C-w>p", "open-previous-editor"
addCommand "editor", "<C-w><C-p>", "open-previous-editor"

# not very vim like, but the windowing system works quite differently
addCommand "editor", "<C-w>H", "move-current-view-prev"
addCommand "editor", "<C-w>L", "move-current-view-next"
addCommand "editor", "<C-w>W", "move-current-view-to-top"

# navigation (horizontal)

addTextCommand "", "h", "vim-move-cursor-column", -1
Expand Down

0 comments on commit 0f1b30e

Please sign in to comment.