Skip to content

Commit d2ea481

Browse files
authored
Merge pull request #95 from BreitbandModem/feature/vim-keybinds
Add more basic VIM bindings for query editor: I, C, D
2 parents 2a1e047 + 3fc62df commit d2ea481

File tree

4 files changed

+16
-1
lines changed

4 files changed

+16
-1
lines changed

sqlit/core/keymap.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,7 @@ def _build_action_keys(self) -> list[ActionKeyDef]:
331331
ActionKeyDef("question_mark", "show_help", "global"),
332332
# Query (normal mode)
333333
ActionKeyDef("i", "enter_insert_mode", "query_normal"),
334+
ActionKeyDef("I", "prepend_insert_mode", "query_normal"),
334335
ActionKeyDef("o", "open_line_below", "query_normal"),
335336
ActionKeyDef("O", "open_line_above", "query_normal"),
336337
ActionKeyDef("enter", "execute_query", "query_normal"),
@@ -341,6 +342,8 @@ def _build_action_keys(self) -> list[ActionKeyDef]:
341342
ActionKeyDef("backspace", "show_history", "query_normal"),
342343
ActionKeyDef("N", "new_query", "query_normal"),
343344
ActionKeyDef("d", "delete_leader_key", "query_normal"),
345+
ActionKeyDef("C", "change_line_end_motion", "query_normal"),
346+
ActionKeyDef("D", "delete_line_end", "query_normal"),
344347
ActionKeyDef("u", "undo", "query_normal"),
345348
ActionKeyDef("ctrl+r", "redo", "query_normal"),
346349
# Vim cursor movement (normal mode)

sqlit/domains/query/state/query_normal.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,15 @@ def _setup_actions(self) -> None:
3939
self.allows("cursor_find_char_back", help="Find char backward")
4040
self.allows("cursor_till_char", help="Move till char forward")
4141
self.allows("cursor_till_char_back", help="Move till char backward")
42+
self.allows("prepend_insert_mode", help="Insert at line start")
4243
self.allows("append_insert_mode", help="Append after cursor")
4344
self.allows("append_line_end", help="Append at line end")
4445
# Vim open line
4546
self.allows("open_line_below", help="Open line below")
4647
self.allows("open_line_above", help="Open line above")
48+
# Vim delete or change
49+
self.allows("change_line_end_motion", help="Change to line end")
50+
self.allows("delete_line_end", help="Delete to line end")
4751
# Clipboard actions
4852
self.allows("select_all", help="Select all text")
4953
self.allows("copy_selection", help="Copy selection")

sqlit/domains/query/ui/mixins/query_editing_cursor.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,12 @@ def action_cursor_till_char_back(self: QueryMixinHost) -> None:
131131
"""Move till after previous char (T{c})."""
132132
self._show_motion_char_pending_menu("T")
133133

134+
def action_prepend_insert_mode(self: QueryMixinHost) -> None:
135+
"""Enter insert mode at start of line (I)."""
136+
row, _ = self.query_input.cursor_location
137+
self.query_input.cursor_location = (row, 0)
138+
self.action_enter_insert_mode()
139+
134140
def action_append_insert_mode(self: QueryMixinHost) -> None:
135141
"""Enter insert mode after cursor (a)."""
136142
lines = self.query_input.text.split("\n")

sqlit/domains/shell/state/machine.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,10 @@ def binding(key: str, desc: str, indent: int = 4) -> str:
185185
# ═══════════════════════════════════════════════════════════════════
186186
lines.append(section("QUERY EDITOR"))
187187
lines.append(subsection("Normal Mode:"))
188-
lines.append(binding("i", "Enter INSERT mode"))
188+
lines.append(binding("i/I", "Enter INSERT mode"))
189189
lines.append(binding("o/O", "Open line below/above"))
190+
lines.append(binding("C", "Change to line end"))
191+
lines.append(binding("D", "Delete to line end"))
190192
lines.append(binding("<enter>/gr", "Execute query"))
191193
lines.append(binding("gt", "Execute as transaction"))
192194
lines.append(binding("<backspace>", "Query history"))

0 commit comments

Comments
 (0)