Skip to content

Commit

Permalink
Improved vim keybindings for indentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Nimaoth committed Apr 26, 2024
1 parent 812b3c9 commit e7abb76
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
Binary file modified config/absytree_config_wasm.wasm
Binary file not shown.
36 changes: 17 additions & 19 deletions config/keybindings_vim.nim
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,14 @@ proc vimCloseCurrentViewOrQuit() {.expose("vim-close-current-view-or-quit").} =
else:
closeCurrentView(keepHidden=false)

proc vimIndent(editor: TextDocumentEditor) {.expose("vim-indent").} =
editor.addNextCheckpoint "insert"
editor.indent()

proc vimUnindent(editor: TextDocumentEditor) {.expose("vim-unindent").} =
editor.addNextCheckpoint "insert"
editor.unindent()

proc loadVimKeybindings*() {.scriptActionWasmNims("load-vim-keybindings").} =
let t = startTimer()
defer:
Expand Down Expand Up @@ -1131,8 +1139,8 @@ proc loadVimKeybindings*() {.scriptActionWasmNims("load-vim-keybindings").} =

addTextCommand "", "<ENTER>", "insert-text", "\n"

addTextCommand "", r"\>\>", "indent"
addTextCommand "", r"\<\<", "unindent"
addTextCommand "", r"\>\>", "vim-indent"
addTextCommand "", r"\<\<", "vim-unindent"

addTextCommandBlock "normal", "s":
editor.setMode "visual"
Expand Down Expand Up @@ -1180,8 +1188,8 @@ proc loadVimKeybindings*() {.scriptActionWasmNims("load-vim-keybindings").} =
addTextCommandBlock "insert", "<C-u>":
editor.deleteMove("line-back", inside=false, which=SelectionCursor.First)

addTextCommand "insert", "<C-t>", "indent"
addTextCommand "insert", "<C-d>", "unindent"
addTextCommand "insert", "<C-t>", "vim-indent"
addTextCommand "insert", "<C-d>", "vim-unindent"
addTextCommand "insert", "<move>", "vim-select-last <move>"

# Visual mode
Expand Down Expand Up @@ -1209,8 +1217,8 @@ proc loadVimKeybindings*() {.scriptActionWasmNims("load-vim-keybindings").} =

addTextCommand "visual", "<?-count><text_object>", """vim-select-move <text_object> <#count>"""

addTextCommand "visual", r"\>", "indent"
addTextCommand "visual", r"\<", "unindent"
addTextCommand "visual", r"\>", "vim-indent"
addTextCommand "visual", r"\<", "vim-unindent"

# Visual line mode
addTextCommandBlock "", "V":
Expand All @@ -1228,8 +1236,8 @@ proc loadVimKeybindings*() {.scriptActionWasmNims("load-vim-keybindings").} =

addTextCommand "visual-line", "<?-count><text_object>", """vim-select-move <text_object> <#count>"""

addTextCommand "visual-line", r"\>", "indent"
addTextCommand "visual-line", r"\<", "unindent"
addTextCommand "visual-line", r"\>", "vim-indent"
addTextCommand "visual-line", r"\<", "vim-unindent"

# todo: not really vim keybindings
addTextCommand "", "gd", "goto-definition"
Expand Down Expand Up @@ -1273,17 +1281,7 @@ proc loadVimKeybindings*() {.scriptActionWasmNims("load-vim-keybindings").} =
addTextCommand "", "<C-UP>", "scroll-lines", -1
addTextCommand "", "<C-DOWN>", "scroll-lines", 1

addTextCommandBlock "insert", "<TAB>":
if editor.hasTabStops():
editor.selectNextTabStop()
else:
editor.indent()

addTextCommandBlock "insert", "<S-TAB>":
if editor.hasTabStops():
editor.selectPrevTabStop()
else:
editor.unindent()
addTextCommand "insert", "<TAB>", "insert-indent"

addTextCommandBlock "", "gc":
editor.addNextCheckpoint "insert"
Expand Down

0 comments on commit e7abb76

Please sign in to comment.