Skip to content

Commit

Permalink
improved vim keybindings
Browse files Browse the repository at this point in the history
  • Loading branch information
Nimaoth committed Mar 17, 2024
1 parent 01fb081 commit 5facd3e
Show file tree
Hide file tree
Showing 7 changed files with 169 additions and 69 deletions.
23 changes: 18 additions & 5 deletions config/keybindings_vim.nim
Original file line number Diff line number Diff line change
Expand Up @@ -858,10 +858,20 @@ proc loadVimKeybindings*() {.scriptActionWasmNims("load-vim-keybindings").} =
addSubCommandWithCount "", "move", "gj", "vim-move-cursor-line", 1

# search
addTextCommandBlock "", "*": editor.setSearchQueryFromMove("word")
addTextCommandBlock "visual", "*": editor.setSearchQuery(editor.getText(editor.selection))
addTextCommand "", "n", "select-move", "next-find-result", true
addTextCommand "", "N", "select-move", "prev-find-result", true
addTextCommandBlock "", "*":
editor.selection = editor.setSearchQueryFromMove("word", prefix=r"\b", suffix=r"\b").first.toSelection
addTextCommandBlock "visual", "*":
editor.setSearchQuery(editor.getText(editor.selection, inclusiveEnd=true))
editor.selection = editor.selection.first.toSelection
editor.setMode("normal")
addTextCommandBlock "", "n":
editor.selection = editor.getNextFindResult(editor.selection.last).first.toSelection
editor.scrollToCursor Last
editor.updateTargetColumn()
addTextCommandBlock "", "N":
editor.selection = editor.getPrevFindResult(editor.selection.last).first.toSelection
editor.scrollToCursor Last
editor.updateTargetColumn()

addTextCommandBlock "", "/":
commandLine("set-search-query \\")
Expand Down Expand Up @@ -1146,7 +1156,10 @@ proc loadVimKeybindings*() {.scriptActionWasmNims("load-vim-keybindings").} =
addTextCommand "", "<C-UP>", "scroll-lines", -1
addTextCommand "", "<C-DOWN>", "scroll-lines", 1

addTextCommand "", "<C-k><C-c>", "toggle-line-comment"
addTextCommandBlock "", "<C-k><C-c>":
editor.addNextCheckpoint "insert"
editor.toggleLineComment()

addTextCommand "", "<C-k><C-u>", "print-undo-history"
addTextCommand "", "<C-k><C-t>", "print-treesitter-tree"
addTextCommandBlock "", "<C-k><C-l>": lspToggleLogServerDebug()
Expand Down
2 changes: 1 addition & 1 deletion config/keybindings_vim_like.nim
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ proc loadVimLikeKeybindings*() {.scriptActionWasmNims("load-vim-like-keybindings
addTextCommand "", "n", "select-move", "next-find-result", true
addTextCommand "", "N", "select-move", "prev-find-result", true

addTextCommandBlock "", "*": editor.setSearchQueryFromMove("word")
addTextCommandBlock "", "*": editor.selection = editor.setSearchQueryFromMove("word")

# editing
addTextCommand "", "x", "delete-right"
Expand Down
23 changes: 13 additions & 10 deletions scripting/absytree_internal.nim
Original file line number Diff line number Diff line change
Expand Up @@ -122,17 +122,19 @@ proc editor_text_addCursorBelow_void_TextDocumentEditor_impl*(
proc editor_text_addCursorAbove_void_TextDocumentEditor_impl*(
self: TextDocumentEditor) =
discard
proc editor_text_getPrevFindResult_Selection_TextDocumentEditor_Cursor_int_impl*(
self: TextDocumentEditor; cursor: Cursor; offset: int = 0): Selection =
proc editor_text_getPrevFindResult_Selection_TextDocumentEditor_Cursor_int_bool_bool_impl*(
self: TextDocumentEditor; cursor: Cursor; offset: int = 0;
includeAfter: bool = true; wrap: bool = true): Selection =
discard
proc editor_text_getNextFindResult_Selection_TextDocumentEditor_Cursor_int_impl*(
self: TextDocumentEditor; cursor: Cursor; offset: int = 0): Selection =
proc editor_text_getNextFindResult_Selection_TextDocumentEditor_Cursor_int_bool_bool_impl*(
self: TextDocumentEditor; cursor: Cursor; offset: int = 0;
includeAfter: bool = true; wrap: bool = true): Selection =
discard
proc editor_text_addNextFindResultToSelection_void_TextDocumentEditor_impl*(
self: TextDocumentEditor) =
proc editor_text_addNextFindResultToSelection_void_TextDocumentEditor_bool_bool_impl*(
self: TextDocumentEditor; includeAfter: bool = true; wrap: bool = true) =
discard
proc editor_text_addPrevFindResultToSelection_void_TextDocumentEditor_impl*(
self: TextDocumentEditor) =
proc editor_text_addPrevFindResultToSelection_void_TextDocumentEditor_bool_bool_impl*(
self: TextDocumentEditor; includeAfter: bool = true; wrap: bool = true) =
discard
proc editor_text_setAllFindResultToSelection_void_TextDocumentEditor_impl*(
self: TextDocumentEditor) =
Expand Down Expand Up @@ -276,8 +278,9 @@ proc editor_text_moveFirst_void_TextDocumentEditor_string_SelectionCursor_bool_i
proc editor_text_setSearchQuery_void_TextDocumentEditor_string_bool_impl*(
self: TextDocumentEditor; query: string; escapeRegex: bool = false) =
discard
proc editor_text_setSearchQueryFromMove_void_TextDocumentEditor_string_int_impl*(
self: TextDocumentEditor; move: string; count: int = 0) =
proc editor_text_setSearchQueryFromMove_Selection_TextDocumentEditor_string_int_string_string_impl*(
self: TextDocumentEditor; move: string; count: int = 0; prefix: string = "";
suffix: string = ""): Selection =
discard
proc editor_text_toggleLineComment_void_TextDocumentEditor_impl*(
self: TextDocumentEditor) =
Expand Down
23 changes: 13 additions & 10 deletions scripting/absytree_internal_wasm.nim
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,16 @@ proc editor_text_addCursorBelow_void_TextDocumentEditor_impl(
self: TextDocumentEditor) {.importc.}
proc editor_text_addCursorAbove_void_TextDocumentEditor_impl(
self: TextDocumentEditor) {.importc.}
proc editor_text_getPrevFindResult_Selection_TextDocumentEditor_Cursor_int_impl(
self: TextDocumentEditor; cursor: Cursor; offset: int = 0): Selection {.importc.}
proc editor_text_getNextFindResult_Selection_TextDocumentEditor_Cursor_int_impl(
self: TextDocumentEditor; cursor: Cursor; offset: int = 0): Selection {.importc.}
proc editor_text_addNextFindResultToSelection_void_TextDocumentEditor_impl(
self: TextDocumentEditor) {.importc.}
proc editor_text_addPrevFindResultToSelection_void_TextDocumentEditor_impl(
self: TextDocumentEditor) {.importc.}
proc editor_text_getPrevFindResult_Selection_TextDocumentEditor_Cursor_int_bool_bool_impl(
self: TextDocumentEditor; cursor: Cursor; offset: int = 0;
includeAfter: bool = true; wrap: bool = true): Selection {.importc.}
proc editor_text_getNextFindResult_Selection_TextDocumentEditor_Cursor_int_bool_bool_impl(
self: TextDocumentEditor; cursor: Cursor; offset: int = 0;
includeAfter: bool = true; wrap: bool = true): Selection {.importc.}
proc editor_text_addNextFindResultToSelection_void_TextDocumentEditor_bool_bool_impl(
self: TextDocumentEditor; includeAfter: bool = true; wrap: bool = true) {.importc.}
proc editor_text_addPrevFindResultToSelection_void_TextDocumentEditor_bool_bool_impl(
self: TextDocumentEditor; includeAfter: bool = true; wrap: bool = true) {.importc.}
proc editor_text_setAllFindResultToSelection_void_TextDocumentEditor_impl(
self: TextDocumentEditor) {.importc.}
proc editor_text_clearSelections_void_TextDocumentEditor_impl(
Expand Down Expand Up @@ -192,8 +194,9 @@ proc editor_text_moveFirst_void_TextDocumentEditor_string_SelectionCursor_bool_i
count: int = 0) {.importc.}
proc editor_text_setSearchQuery_void_TextDocumentEditor_string_bool_impl(
self: TextDocumentEditor; query: string; escapeRegex: bool = false) {.importc.}
proc editor_text_setSearchQueryFromMove_void_TextDocumentEditor_string_int_impl(
self: TextDocumentEditor; move: string; count: int = 0) {.importc.}
proc editor_text_setSearchQueryFromMove_Selection_TextDocumentEditor_string_int_string_string_impl(
self: TextDocumentEditor; move: string; count: int = 0; prefix: string = "";
suffix: string = ""): Selection {.importc.}
proc editor_text_toggleLineComment_void_TextDocumentEditor_impl(
self: TextDocumentEditor) {.importc.}
proc editor_text_gotoDefinition_void_TextDocumentEditor_impl(
Expand Down
33 changes: 20 additions & 13 deletions scripting/editor_text_api.nim
Original file line number Diff line number Diff line change
Expand Up @@ -120,17 +120,23 @@ proc addCursorBelow*(self: TextDocumentEditor) =
proc addCursorAbove*(self: TextDocumentEditor) =
editor_text_addCursorAbove_void_TextDocumentEditor_impl(self)
proc getPrevFindResult*(self: TextDocumentEditor; cursor: Cursor;
offset: int = 0): Selection =
editor_text_getPrevFindResult_Selection_TextDocumentEditor_Cursor_int_impl(
self, cursor, offset)
offset: int = 0; includeAfter: bool = true;
wrap: bool = true): Selection =
editor_text_getPrevFindResult_Selection_TextDocumentEditor_Cursor_int_bool_bool_impl(
self, cursor, offset, includeAfter, wrap)
proc getNextFindResult*(self: TextDocumentEditor; cursor: Cursor;
offset: int = 0): Selection =
editor_text_getNextFindResult_Selection_TextDocumentEditor_Cursor_int_impl(
self, cursor, offset)
proc addNextFindResultToSelection*(self: TextDocumentEditor) =
editor_text_addNextFindResultToSelection_void_TextDocumentEditor_impl(self)
proc addPrevFindResultToSelection*(self: TextDocumentEditor) =
editor_text_addPrevFindResultToSelection_void_TextDocumentEditor_impl(self)
offset: int = 0; includeAfter: bool = true;
wrap: bool = true): Selection =
editor_text_getNextFindResult_Selection_TextDocumentEditor_Cursor_int_bool_bool_impl(
self, cursor, offset, includeAfter, wrap)
proc addNextFindResultToSelection*(self: TextDocumentEditor;
includeAfter: bool = true; wrap: bool = true) =
editor_text_addNextFindResultToSelection_void_TextDocumentEditor_bool_bool_impl(
self, includeAfter, wrap)
proc addPrevFindResultToSelection*(self: TextDocumentEditor;
includeAfter: bool = true; wrap: bool = true) =
editor_text_addPrevFindResultToSelection_void_TextDocumentEditor_bool_bool_impl(
self, includeAfter, wrap)
proc setAllFindResultToSelection*(self: TextDocumentEditor) =
editor_text_setAllFindResultToSelection_void_TextDocumentEditor_impl(self)
proc clearSelections*(self: TextDocumentEditor) =
Expand Down Expand Up @@ -285,9 +291,10 @@ proc setSearchQuery*(self: TextDocumentEditor; query: string;
editor_text_setSearchQuery_void_TextDocumentEditor_string_bool_impl(self,
query, escapeRegex)
proc setSearchQueryFromMove*(self: TextDocumentEditor; move: string;
count: int = 0) =
editor_text_setSearchQueryFromMove_void_TextDocumentEditor_string_int_impl(
self, move, count)
count: int = 0; prefix: string = "";
suffix: string = ""): Selection =
editor_text_setSearchQueryFromMove_Selection_TextDocumentEditor_string_int_string_string_impl(
self, move, count, prefix, suffix)
proc toggleLineComment*(self: TextDocumentEditor) =
editor_text_toggleLineComment_void_TextDocumentEditor_impl(self)
proc gotoDefinition*(self: TextDocumentEditor) =
Expand Down
86 changes: 71 additions & 15 deletions scripting/editor_text_api_wasm.nim
Original file line number Diff line number Diff line change
Expand Up @@ -794,10 +794,11 @@ proc addCursorAbove*(self: TextDocumentEditor) =
argsJsonString.cstring)


proc editor_text_getPrevFindResult_Selection_TextDocumentEditor_Cursor_int_wasm(
proc editor_text_getPrevFindResult_Selection_TextDocumentEditor_Cursor_int_bool_bool_wasm(
arg: cstring): cstring {.importc.}
proc getPrevFindResult*(self: TextDocumentEditor; cursor: Cursor;
offset: int = 0): Selection =
offset: int = 0; includeAfter: bool = true;
wrap: bool = true): Selection =
var argsJson = newJArray()
argsJson.add block:
when TextDocumentEditor is JsonNode:
Expand All @@ -814,16 +815,27 @@ proc getPrevFindResult*(self: TextDocumentEditor; cursor: Cursor;
offset
else:
offset.toJson()
argsJson.add block:
when bool is JsonNode:
includeAfter
else:
includeAfter.toJson()
argsJson.add block:
when bool is JsonNode:
wrap
else:
wrap.toJson()
let argsJsonString = $argsJson
let res {.used.} = editor_text_getPrevFindResult_Selection_TextDocumentEditor_Cursor_int_wasm(
let res {.used.} = editor_text_getPrevFindResult_Selection_TextDocumentEditor_Cursor_int_bool_bool_wasm(
argsJsonString.cstring)
result = parseJson($res).jsonTo(typeof(result))


proc editor_text_getNextFindResult_Selection_TextDocumentEditor_Cursor_int_wasm(
proc editor_text_getNextFindResult_Selection_TextDocumentEditor_Cursor_int_bool_bool_wasm(
arg: cstring): cstring {.importc.}
proc getNextFindResult*(self: TextDocumentEditor; cursor: Cursor;
offset: int = 0): Selection =
offset: int = 0; includeAfter: bool = true;
wrap: bool = true): Selection =
var argsJson = newJArray()
argsJson.add block:
when TextDocumentEditor is JsonNode:
Expand All @@ -840,37 +852,69 @@ proc getNextFindResult*(self: TextDocumentEditor; cursor: Cursor;
offset
else:
offset.toJson()
argsJson.add block:
when bool is JsonNode:
includeAfter
else:
includeAfter.toJson()
argsJson.add block:
when bool is JsonNode:
wrap
else:
wrap.toJson()
let argsJsonString = $argsJson
let res {.used.} = editor_text_getNextFindResult_Selection_TextDocumentEditor_Cursor_int_wasm(
let res {.used.} = editor_text_getNextFindResult_Selection_TextDocumentEditor_Cursor_int_bool_bool_wasm(
argsJsonString.cstring)
result = parseJson($res).jsonTo(typeof(result))


proc editor_text_addNextFindResultToSelection_void_TextDocumentEditor_wasm(
proc editor_text_addNextFindResultToSelection_void_TextDocumentEditor_bool_bool_wasm(
arg: cstring): cstring {.importc.}
proc addNextFindResultToSelection*(self: TextDocumentEditor) =
proc addNextFindResultToSelection*(self: TextDocumentEditor;
includeAfter: bool = true; wrap: bool = true) =
var argsJson = newJArray()
argsJson.add block:
when TextDocumentEditor is JsonNode:
self
else:
self.toJson()
argsJson.add block:
when bool is JsonNode:
includeAfter
else:
includeAfter.toJson()
argsJson.add block:
when bool is JsonNode:
wrap
else:
wrap.toJson()
let argsJsonString = $argsJson
let res {.used.} = editor_text_addNextFindResultToSelection_void_TextDocumentEditor_wasm(
let res {.used.} = editor_text_addNextFindResultToSelection_void_TextDocumentEditor_bool_bool_wasm(
argsJsonString.cstring)


proc editor_text_addPrevFindResultToSelection_void_TextDocumentEditor_wasm(
proc editor_text_addPrevFindResultToSelection_void_TextDocumentEditor_bool_bool_wasm(
arg: cstring): cstring {.importc.}
proc addPrevFindResultToSelection*(self: TextDocumentEditor) =
proc addPrevFindResultToSelection*(self: TextDocumentEditor;
includeAfter: bool = true; wrap: bool = true) =
var argsJson = newJArray()
argsJson.add block:
when TextDocumentEditor is JsonNode:
self
else:
self.toJson()
argsJson.add block:
when bool is JsonNode:
includeAfter
else:
includeAfter.toJson()
argsJson.add block:
when bool is JsonNode:
wrap
else:
wrap.toJson()
let argsJsonString = $argsJson
let res {.used.} = editor_text_addPrevFindResultToSelection_void_TextDocumentEditor_wasm(
let res {.used.} = editor_text_addPrevFindResultToSelection_void_TextDocumentEditor_bool_bool_wasm(
argsJsonString.cstring)


Expand Down Expand Up @@ -1920,10 +1964,11 @@ proc setSearchQuery*(self: TextDocumentEditor; query: string;
argsJsonString.cstring)


proc editor_text_setSearchQueryFromMove_void_TextDocumentEditor_string_int_wasm(
proc editor_text_setSearchQueryFromMove_Selection_TextDocumentEditor_string_int_string_string_wasm(
arg: cstring): cstring {.importc.}
proc setSearchQueryFromMove*(self: TextDocumentEditor; move: string;
count: int = 0) =
count: int = 0; prefix: string = "";
suffix: string = ""): Selection =
var argsJson = newJArray()
argsJson.add block:
when TextDocumentEditor is JsonNode:
Expand All @@ -1940,9 +1985,20 @@ proc setSearchQueryFromMove*(self: TextDocumentEditor; move: string;
count
else:
count.toJson()
argsJson.add block:
when string is JsonNode:
prefix
else:
prefix.toJson()
argsJson.add block:
when string is JsonNode:
suffix
else:
suffix.toJson()
let argsJsonString = $argsJson
let res {.used.} = editor_text_setSearchQueryFromMove_void_TextDocumentEditor_string_int_wasm(
let res {.used.} = editor_text_setSearchQueryFromMove_Selection_TextDocumentEditor_string_int_string_string_wasm(
argsJsonString.cstring)
result = parseJson($res).jsonTo(typeof(result))


proc editor_text_toggleLineComment_void_TextDocumentEditor_wasm(arg: cstring): cstring {.
Expand Down
Loading

0 comments on commit 5facd3e

Please sign in to comment.