Skip to content

Commit 73204ea

Browse files
authored
Merge pull request #225 from Maxteabag/feat/custom-keybindings
Additive custom keymaps with conflict detection
2 parents e0c937d + cdc57f7 commit 73204ea

18 files changed

Lines changed: 1697 additions & 125 deletions

File tree

‎README.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,10 @@ Connections and settings are stored in `$XDG_CONFIG_HOME/sqlit/` (default: `~/.c
241241

242242
If an older install left files in `~/.sqlit/`, they are moved to the new location automatically on first run.
243243

244+
### Custom keybindings
245+
246+
Edit the `keymap.json` file in your sqlit config dir. See [`config/keymap.template.json`](config/keymap.template.json) for the full default keymap. Keymap.json need to only contain the overriding keymaps.
247+
244248
## FAQ
245249

246250
### How are sensitive credentials stored?

‎config/keymap.template.json‎

Lines changed: 352 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,352 @@
1+
{
2+
"keymap": {
3+
"action_keys": {
4+
"global": {
5+
"leader_key": "space",
6+
"quit": "ctrl+q",
7+
"cancel_operation": "escape",
8+
"show_help": "?",
9+
"enter_command_mode": ":",
10+
"undo": "ctrl+z",
11+
"redo": "ctrl+y"
12+
},
13+
"navigation": {
14+
"focus_explorer": "e",
15+
"focus_query": "q",
16+
"focus_results": "r"
17+
},
18+
"tree": {
19+
"new_connection": "n",
20+
"enter_tree_visual_mode": "v",
21+
"clear_connection_selection": "escape",
22+
"select_table": "s",
23+
"refresh_tree": [
24+
"f",
25+
"R"
26+
],
27+
"edit_connection": "e",
28+
"rename_connection_folder": "M",
29+
"delete_connection_folder": [
30+
"d",
31+
"delete"
32+
],
33+
"delete_connection": [
34+
"d",
35+
"delete"
36+
],
37+
"duplicate_connection": "D",
38+
"move_connection_to_folder": "m",
39+
"disconnect": "x",
40+
"collapse_tree": "z",
41+
"tree_cursor_down": [
42+
"j",
43+
"down"
44+
],
45+
"tree_cursor_up": [
46+
"k",
47+
"up"
48+
],
49+
"tree_filter": "/"
50+
},
51+
"tree_filter": {
52+
"tree_filter_close": "escape",
53+
"tree_filter_accept": "enter"
54+
},
55+
"tree_visual": {
56+
"exit_tree_visual_mode": [
57+
"escape",
58+
"v"
59+
]
60+
},
61+
"query_normal": {
62+
"enter_insert_mode": "i",
63+
"prepend_insert_mode": "I",
64+
"open_line_below": "o",
65+
"open_line_above": "O",
66+
"execute_query": "enter",
67+
"paste": "p",
68+
"yank_leader_key": "y",
69+
"change_leader_key": "c",
70+
"g_leader_key": "g",
71+
"show_history": "backspace",
72+
"new_query": "N",
73+
"delete_leader_key": "d",
74+
"change_line_end_motion": "C",
75+
"delete_line_end": "D",
76+
"undo": "u",
77+
"redo": "ctrl+r",
78+
"cursor_left": "h",
79+
"cursor_down": "j",
80+
"cursor_up": "k",
81+
"cursor_right": "l",
82+
"cursor_word_forward": "w",
83+
"cursor_WORD_forward": "W",
84+
"cursor_word_back": "b",
85+
"cursor_WORD_back": "B",
86+
"cursor_line_start": "0",
87+
"cursor_first_non_blank": "^",
88+
"cursor_line_end": "$",
89+
"cursor_last_line": "G",
90+
"cursor_matching_bracket": "%",
91+
"cursor_find_char": "f",
92+
"cursor_find_char_back": "F",
93+
"cursor_till_char": "t",
94+
"cursor_till_char_back": "T",
95+
"enter_visual_mode": "v",
96+
"enter_visual_line_mode": "V",
97+
"delete_char": "x",
98+
"append_insert_mode": "a",
99+
"append_line_end": "A"
100+
},
101+
"query_insert": {
102+
"exit_insert_mode": "escape",
103+
"execute_query_insert": "ctrl+enter",
104+
"select_all": "ctrl+a",
105+
"copy_selection": "ctrl+c",
106+
"paste": "ctrl+v"
107+
},
108+
"query_visual": {
109+
"exit_visual_mode": [
110+
"escape",
111+
"v"
112+
],
113+
"switch_to_visual_line_mode": "V",
114+
"visual_yank": "y",
115+
"visual_delete": [
116+
"d",
117+
"x"
118+
],
119+
"visual_change": "c",
120+
"visual_execute": "enter",
121+
"cursor_left": [
122+
"h",
123+
"left"
124+
],
125+
"cursor_down": [
126+
"j",
127+
"down"
128+
],
129+
"cursor_up": [
130+
"k",
131+
"up"
132+
],
133+
"cursor_right": [
134+
"l",
135+
"right"
136+
],
137+
"cursor_word_forward": "w",
138+
"cursor_WORD_forward": "W",
139+
"cursor_word_back": "b",
140+
"cursor_WORD_back": "B",
141+
"cursor_line_start": "0",
142+
"cursor_first_non_blank": "^",
143+
"cursor_line_end": "$",
144+
"cursor_last_line": "G",
145+
"g_leader_key": "g",
146+
"cursor_matching_bracket": "%",
147+
"cursor_find_char": "f",
148+
"cursor_find_char_back": "F",
149+
"cursor_till_char": "t",
150+
"cursor_till_char_back": "T"
151+
},
152+
"query_visual_line": {
153+
"exit_visual_line_mode": [
154+
"escape",
155+
"V"
156+
],
157+
"switch_to_visual_mode": "v",
158+
"visual_line_yank": "y",
159+
"visual_line_delete": [
160+
"d",
161+
"x"
162+
],
163+
"visual_line_change": "c",
164+
"cursor_down": [
165+
"j",
166+
"down"
167+
],
168+
"cursor_up": [
169+
"k",
170+
"up"
171+
],
172+
"cursor_last_line": "G",
173+
"g_leader_key": "g",
174+
"visual_line_execute": "enter"
175+
},
176+
"autocomplete": {
177+
"autocomplete_next": [
178+
"ctrl+j",
179+
"down"
180+
],
181+
"autocomplete_prev": [
182+
"ctrl+k",
183+
"up"
184+
],
185+
"autocomplete_accept": "tab",
186+
"autocomplete_close": "escape"
187+
},
188+
"results": {
189+
"view_cell": "v",
190+
"view_cell_full": "V",
191+
"edit_cell": "u",
192+
"delete_row": "d",
193+
"results_yank_leader_key": "y",
194+
"clear_results": "x",
195+
"results_filter": "/",
196+
"results_cursor_left": "h",
197+
"results_cursor_down": "j",
198+
"results_cursor_up": "k",
199+
"results_cursor_right": "l",
200+
"rg_leader_key": "g",
201+
"results_cursor_last_row": "G",
202+
"results_page_up": "ctrl+u",
203+
"results_page_down": "ctrl+d",
204+
"results_cursor_first_column": "0",
205+
"results_cursor_last_column": "$",
206+
"results_column_picker": [
207+
"f",
208+
"F"
209+
],
210+
"next_result_section": "tab",
211+
"prev_result_section": "shift+tab",
212+
"toggle_result_section": "z"
213+
},
214+
"results_filter": {
215+
"results_filter_close": "escape",
216+
"results_filter_accept": "enter"
217+
},
218+
"value_view": {
219+
"close_value_view": [
220+
"q",
221+
"escape"
222+
],
223+
"copy_value_view": "y",
224+
"toggle_value_view_mode": "t",
225+
"collapse_all_json_nodes": "z",
226+
"expand_all_json_nodes": "Z"
227+
}
228+
},
229+
"leader_commands": {
230+
"leader": {
231+
"toggle_explorer": "e",
232+
"toggle_fullscreen": "f",
233+
"show_connection_picker": "c",
234+
"disconnect": "x",
235+
"cancel_operation": "z",
236+
"change_theme": "t",
237+
"edit_query_in_editor": "o",
238+
"show_help": "h",
239+
"telescope": "space",
240+
"telescope_filter": "/",
241+
"quit": "q"
242+
},
243+
"delete": {
244+
"line": "d",
245+
"word": "w",
246+
"WORD": "W",
247+
"word_back": "b",
248+
"WORD_back": "B",
249+
"word_end": "e",
250+
"WORD_end": "E",
251+
"line_start": "0",
252+
"line_end_motion": "$",
253+
"line_end": "D",
254+
"char": "x",
255+
"char_back": "X",
256+
"left": "h",
257+
"down": "j",
258+
"up": "k",
259+
"right": "l",
260+
"to_end": "G",
261+
"find_char": "f",
262+
"find_char_back": "F",
263+
"till_char": "t",
264+
"till_char_back": "T",
265+
"matching_bracket": "%",
266+
"inner": "i",
267+
"around": "a"
268+
},
269+
"yank": {
270+
"line": "y",
271+
"word": "w",
272+
"WORD": "W",
273+
"word_back": "b",
274+
"WORD_back": "B",
275+
"word_end": "e",
276+
"WORD_end": "E",
277+
"line_start": "0",
278+
"line_end_motion": "$",
279+
"left": "h",
280+
"down": "j",
281+
"up": "k",
282+
"right": "l",
283+
"to_end": "G",
284+
"find_char": "f",
285+
"find_char_back": "F",
286+
"till_char": "t",
287+
"till_char_back": "T",
288+
"matching_bracket": "%",
289+
"inner": "i",
290+
"around": "a"
291+
},
292+
"change": {
293+
"line": "c",
294+
"word": "w",
295+
"WORD": "W",
296+
"word_back": "b",
297+
"WORD_back": "B",
298+
"word_end": "e",
299+
"WORD_end": "E",
300+
"line_start": "0",
301+
"line_end_motion": "$",
302+
"left": "h",
303+
"down": "j",
304+
"up": "k",
305+
"right": "l",
306+
"to_end": "G",
307+
"find_char": "f",
308+
"find_char_back": "F",
309+
"till_char": "t",
310+
"till_char_back": "T",
311+
"matching_bracket": "%",
312+
"inner": "i",
313+
"around": "a"
314+
},
315+
"g": {
316+
"first_line": "g",
317+
"word_end_back": "e",
318+
"WORD_end_back": "E",
319+
"comment": "c",
320+
"execute_query": "r",
321+
"execute_single_statement": "s",
322+
"execute_query_atomic": "t"
323+
},
324+
"gc": {
325+
"line": "c",
326+
"down": "j",
327+
"up": "k",
328+
"to_end": "G",
329+
"selection": "s",
330+
"statement": "S"
331+
},
332+
"ry": {
333+
"cell": "c",
334+
"row": "y",
335+
"all": "a",
336+
"export": "e"
337+
},
338+
"rye": {
339+
"csv": "c",
340+
"json": "j"
341+
},
342+
"rg": {
343+
"first_row": "g"
344+
},
345+
"vy": {
346+
"value": "y",
347+
"field": "f",
348+
"all": "a"
349+
}
350+
}
351+
}
352+
}

‎config/settings.template.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"_note": "Copy to .sqlit/settings.json (gitignored) and run: sqlit --settings .sqlit/settings.json",
33
"theme": "tokyo-night",
44
"custom_themes": [],
5+
"custom_keymap": "default",
56
"expanded_nodes": [],
67
"process_worker": true,
78
"process_worker_warm_on_idle": true,

‎sqlit/core/__init__.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
ActionKeyDef,
66
KeymapProvider,
77
LeaderCommandDef,
8+
build_textual_keymap,
89
format_key,
910
get_keymap,
1011
reset_keymap,
@@ -19,6 +20,7 @@
1920
"KeymapProvider",
2021
"LeaderCommandDef",
2122
"VimMode",
23+
"build_textual_keymap",
2224
"format_key",
2325
"get_keymap",
2426
"get_leader_commands",

0 commit comments

Comments
 (0)