Show More
@@ -0,0 +1,21 | |||||
|
1 | Terminal shortcuts customization | |||
|
2 | ================================ | |||
|
3 | ||||
|
4 | Previously modifying shortcuts was only possible by hooking into startup files | |||
|
5 | and practically limited to adding new shortcuts or removing all shortcuts bound | |||
|
6 | to a specific key. This release enables users to override existing terminal | |||
|
7 | shortcuts, disable them or add new keybindings. | |||
|
8 | ||||
|
9 | For example, to set the :kbd:`right` to accept a single character of auto-suggestion | |||
|
10 | you could use:: | |||
|
11 | ||||
|
12 | my_shortcuts = [ | |||
|
13 | { | |||
|
14 | "command": "IPython:auto_suggest.accept_character", | |||
|
15 | "new_keys": ["right"] | |||
|
16 | } | |||
|
17 | ] | |||
|
18 | %config TerminalInteractiveShell.shortcuts = my_shortcuts | |||
|
19 | ||||
|
20 | You can learn more in :std:configtrait:`TerminalInteractiveShell.shortcuts` | |||
|
21 | configuration reference. No newline at end of file |
@@ -444,19 +444,23 class TerminalInteractiveShell(InteractiveShell): | |||||
444 | "create": Bool(default=False), |
|
444 | "create": Bool(default=False), | |
445 | }, |
|
445 | }, | |
446 | ), |
|
446 | ), | |
447 |
help= |
|
447 | help="""Add, disable or modifying shortcuts. | |
448 |
|
448 | |||
449 | Each entry on the list should be a dictionary with ``command`` key |
|
449 | Each entry on the list should be a dictionary with ``command`` key | |
450 | identifying the target function executed by the shortcut and at least |
|
450 | identifying the target function executed by the shortcut and at least | |
451 |
one of the following: |
|
451 | one of the following: | |
|
452 | ||||
452 | - ``match_keys``: list of keys used to match an existing shortcut, |
|
453 | - ``match_keys``: list of keys used to match an existing shortcut, | |
453 | - ``match_filter``: shortcut filter used to match an existing shortcut, |
|
454 | - ``match_filter``: shortcut filter used to match an existing shortcut, | |
454 | - ``new_keys``: list of keys to set, |
|
455 | - ``new_keys``: list of keys to set, | |
455 | - ``new_filter``: a new shortcut filter to set |
|
456 | - ``new_filter``: a new shortcut filter to set | |
456 |
|
457 | |||
457 | The filters have to be composed of pre-defined verbs and joined by one |
|
458 | The filters have to be composed of pre-defined verbs and joined by one | |
458 | of the following conjunctions: ``&`` (and), ``|` (or), ``~`` (not). |
|
459 | of the following conjunctions: ``&`` (and), ``|`` (or), ``~`` (not). | |
459 |
The pre-defined verbs are: |
|
460 | The pre-defined verbs are: | |
|
461 | ||||
|
462 | {} | |||
|
463 | ||||
460 |
|
464 | |||
461 | To disable a shortcut set ``new_keys`` to an empty list. |
|
465 | To disable a shortcut set ``new_keys`` to an empty list. | |
462 | To add a shortcut add key ``create`` with value ``True``. |
|
466 | To add a shortcut add key ``create`` with value ``True``. | |
@@ -467,9 +471,13 class TerminalInteractiveShell(InteractiveShell): | |||||
467 | ``new_keys`` can be omitted which will result in reuse of the existing |
|
471 | ``new_keys`` can be omitted which will result in reuse of the existing | |
468 | filter/keys. |
|
472 | filter/keys. | |
469 |
|
473 | |||
470 |
Only shortcuts defined in IPython (and not default prompt |
|
474 | Only shortcuts defined in IPython (and not default prompt-toolkit | |
471 | shortcuts) can be modified or disabled. |
|
475 | shortcuts) can be modified or disabled. The full list of shortcuts, | |
472 | """, |
|
476 | command identifiers and filters is available under | |
|
477 | :ref:`terminal-shortcuts-list`. | |||
|
478 | """.format( | |||
|
479 | "\n ".join([f"- `{k}`" for k in KEYBINDING_FILTERS]) | |||
|
480 | ), | |||
473 | ).tag(config=True) |
|
481 | ).tag(config=True) | |
474 |
|
482 | |||
475 | @observe("shortcuts") |
|
483 | @observe("shortcuts") |
@@ -185,10 +185,16 AUTO_SUGGEST_BINDINGS = [ | |||||
185 | "default_buffer_focused & (ebivim | ~vi_insert_mode)", |
|
185 | "default_buffer_focused & (ebivim | ~vi_insert_mode)", | |
186 | ), |
|
186 | ), | |
187 | Binding( |
|
187 | Binding( | |
188 |
auto_suggest.accept_in_vi_insert_mode, |
|
188 | auto_suggest.accept_in_vi_insert_mode, | |
|
189 | ["c-e"], | |||
|
190 | "vi_insert_mode & default_buffer_focused & ebivim", | |||
|
191 | ), | |||
|
192 | Binding(auto_suggest.accept, ["c-f"], "vi_insert_mode & default_buffer_focused"), | |||
|
193 | Binding( | |||
|
194 | auto_suggest.accept_word, | |||
|
195 | ["escape", "f"], | |||
|
196 | "vi_insert_mode & default_buffer_focused & ebivim", | |||
189 | ), |
|
197 | ), | |
190 | Binding(auto_suggest.accept, ["c-f"], "focused_insert_vi"), |
|
|||
191 | Binding(auto_suggest.accept_word, ["escape", "f"], "focused_insert_vi & ebivim"), |
|
|||
192 | Binding( |
|
198 | Binding( | |
193 | auto_suggest.accept_token, |
|
199 | auto_suggest.accept_token, | |
194 | ["c-right"], |
|
200 | ["c-right"], | |
@@ -249,7 +255,7 AUTO_SUGGEST_BINDINGS = [ | |||||
249 |
|
255 | |||
250 |
|
256 | |||
251 | SIMPLE_CONTROL_BINDINGS = [ |
|
257 | SIMPLE_CONTROL_BINDINGS = [ | |
252 |
Binding(cmd, [key], " |
|
258 | Binding(cmd, [key], "vi_insert_mode & default_buffer_focused & ebivim") | |
253 | for key, cmd in { |
|
259 | for key, cmd in { | |
254 | "c-a": nc.beginning_of_line, |
|
260 | "c-a": nc.beginning_of_line, | |
255 | "c-b": nc.backward_char, |
|
261 | "c-b": nc.backward_char, | |
@@ -262,7 +268,7 SIMPLE_CONTROL_BINDINGS = [ | |||||
262 |
|
268 | |||
263 |
|
269 | |||
264 | ALT_AND_COMOBO_CONTROL_BINDINGS = [ |
|
270 | ALT_AND_COMOBO_CONTROL_BINDINGS = [ | |
265 |
Binding(cmd, list(keys), " |
|
271 | Binding(cmd, list(keys), "vi_insert_mode & default_buffer_focused & ebivim") | |
266 | for keys, cmd in { |
|
272 | for keys, cmd in { | |
267 | # Control Combos |
|
273 | # Control Combos | |
268 | ("c-x", "c-e"): nc.edit_and_execute, |
|
274 | ("c-x", "c-e"): nc.edit_and_execute, |
@@ -190,7 +190,6 KEYBINDING_FILTERS = { | |||||
190 | "is_windows_os": is_windows_os, |
|
190 | "is_windows_os": is_windows_os, | |
191 | "auto_match": auto_match, |
|
191 | "auto_match": auto_match, | |
192 | "focused_insert": (vi_insert_mode | emacs_insert_mode) & default_buffer_focused, |
|
192 | "focused_insert": (vi_insert_mode | emacs_insert_mode) & default_buffer_focused, | |
193 | "focused_insert_vi": vi_insert_mode & default_buffer_focused, |
|
|||
194 | "not_inside_unclosed_string": not_inside_unclosed_string, |
|
193 | "not_inside_unclosed_string": not_inside_unclosed_string, | |
195 | "readline_like_completions": readline_like_completions, |
|
194 | "readline_like_completions": readline_like_completions, | |
196 | "preceded_by_paired_double_quotes": preceding_text( |
|
195 | "preceded_by_paired_double_quotes": preceding_text( | |
@@ -203,7 +202,6 KEYBINDING_FILTERS = { | |||||
203 | "preceded_by_two_double_quotes": preceding_text(r'^.*""$'), |
|
202 | "preceded_by_two_double_quotes": preceding_text(r'^.*""$'), | |
204 | "preceded_by_two_single_quotes": preceding_text(r"^.*''$"), |
|
203 | "preceded_by_two_single_quotes": preceding_text(r"^.*''$"), | |
205 | "followed_by_closing_paren_or_end": following_text(r"[,)}\]]|$"), |
|
204 | "followed_by_closing_paren_or_end": following_text(r"[,)}\]]|$"), | |
206 | # match |
|
|||
207 | "preceded_by_opening_round_paren": preceding_text(r".*\($"), |
|
205 | "preceded_by_opening_round_paren": preceding_text(r".*\($"), | |
208 | "preceded_by_opening_bracket": preceding_text(r".*\[$"), |
|
206 | "preceded_by_opening_bracket": preceding_text(r".*\[$"), | |
209 | "preceded_by_opening_brace": preceding_text(r".*\{$"), |
|
207 | "preceded_by_opening_brace": preceding_text(r".*\{$"), |
@@ -200,10 +200,20 With (X)EMacs >= 24, You can enable IPython in python-mode with: | |||||
200 | Keyboard Shortcuts |
|
200 | Keyboard Shortcuts | |
201 | ================== |
|
201 | ================== | |
202 |
|
202 | |||
|
203 | .. versionadded:: 8.10 | |||
|
204 | ||||
|
205 | You can modify, disable or modify keyboard shortcuts for IPython Terminal using | |||
|
206 | :std:configtrait:`TerminalInteractiveShell.shortcuts` traitlet. | |||
|
207 | ||||
|
208 | The list of shortcuts is available in the Configuring IPython :ref:`terminal-shortcuts-list` section. | |||
|
209 | ||||
|
210 | Advanced configuration | |||
|
211 | ---------------------- | |||
|
212 | ||||
203 | .. versionchanged:: 5.0 |
|
213 | .. versionchanged:: 5.0 | |
204 |
|
214 | |||
205 | You can customise keyboard shortcuts for terminal IPython. Put code like this in |
|
215 | Creating custom commands requires adding custom code to a | |
206 |
|
|
216 | :ref:`startup file <startup_files>`:: | |
207 |
|
217 | |||
208 | from IPython import get_ipython |
|
218 | from IPython import get_ipython | |
209 | from prompt_toolkit.enums import DEFAULT_BUFFER |
|
219 | from prompt_toolkit.enums import DEFAULT_BUFFER |
@@ -1,8 +1,10 | |||||
|
1 | .. _terminal-shortcuts-list: | |||
|
2 | ||||
1 | ================= |
|
3 | ================= | |
2 | IPython shortcuts |
|
4 | IPython shortcuts | |
3 | ================= |
|
5 | ================= | |
4 |
|
6 | |||
5 |
|
|
7 | Shortcuts available in an IPython terminal. | |
6 |
|
8 | |||
7 | .. note:: |
|
9 | .. note:: | |
8 |
|
10 | |||
@@ -12,7 +14,10 Available shortcuts in an IPython terminal. | |||||
12 |
|
14 | |||
13 | * Comma-separated keys, e.g. :kbd:`Esc`, :kbd:`f`, indicate a sequence which can be activated by pressing the listed keys in succession. |
|
15 | * Comma-separated keys, e.g. :kbd:`Esc`, :kbd:`f`, indicate a sequence which can be activated by pressing the listed keys in succession. | |
14 | * Plus-separated keys, e.g. :kbd:`Esc` + :kbd:`f` indicate a combination which requires pressing all keys simultaneously. |
|
16 | * Plus-separated keys, e.g. :kbd:`Esc` + :kbd:`f` indicate a combination which requires pressing all keys simultaneously. | |
15 |
* Hover over the ⓘ icon in the filter column to see when the shortcut is active. |
|
17 | * Hover over the ⓘ icon in the filter column to see when the shortcut is active. | |
|
18 | ||||
|
19 | You can use :std:configtrait:`TerminalInteractiveShell.shortcuts` configuration | |||
|
20 | to modify, disable or add shortcuts. | |||
16 |
|
21 | |||
17 | .. role:: raw-html(raw) |
|
22 | .. role:: raw-html(raw) | |
18 | :format: html |
|
23 | :format: html |
General Comments 0
You need to be logged in to leave comments.
Login now