Repository: ipython/ipython
Pull request: Adding and "End" key binding for applying an auto suggestion
For [#13492](https://github.com/ipython/ipython/issues/13492)

Problem statement:
Auto-complete hinted suggestions using the END key
Sorry if this is duplicated and has been implemented already, but I did search the issue tracker and did not find anything mentioning it.

The auto-complete hints in the new version are awesome, however I find myself trying to apply them by pressing the END key, just like I do in the fish shell, and IPython does not seem to have that keybind enabled by default.

Would it be possible to consider adding this to the default keybinds? Several other auto-completion systems do the same, so I don't think I am the only user that would be benefit from this change. I think it would make the defaults slightly better :blush: 

Thank you!

Hints from issue discussion:
Yes, that is a good idea, I thought about it at some point, configure which keys allow to validate hinted suggestion, and also allow other sources of hinted suggestions. I'm not sure I'll have the time to do that soon, so it will likely need someone to contribute it.

Commit message: Format according to black/darker

Patch to review:
diff --git a/IPython/terminal/shortcuts.py b/IPython/terminal/shortcuts.py
index b53e5b49a7c..ba0cf123be3 100644
--- a/IPython/terminal/shortcuts.py
+++ b/IPython/terminal/shortcuts.py
@@ -267,8 +267,7 @@ def ebivim():
     focused_insert_vi = has_focus(DEFAULT_BUFFER) & vi_insert_mode
 
     # Needed for to accept autosuggestions in vi insert mode
-    @kb.add("c-e", filter=focused_insert_vi & ebivim)
-    def _(event):
+    def _apply_autosuggest(event):
         b = event.current_buffer
         suggestion = b.suggestion
         if suggestion:
@@ -276,6 +275,14 @@ def _(event):
         else:
             nc.end_of_line(event)
 
+    @kb.add("end", filter=has_focus(DEFAULT_BUFFER) & ebivim)
+    def _(event):
+        _apply_autosuggest(event)
+
+    @kb.add("c-e", filter=focused_insert_vi & ebivim)
+    def _(event):
+        _apply_autosuggest(event)
+
     @kb.add("c-f", filter=focused_insert_vi)
     def _(event):
         b = event.current_buffer
diff --git a/docs/source/whatsnew/pr/end-shortcut-accept-suggestion.rst b/docs/source/whatsnew/pr/end-shortcut-accept-suggestion.rst
new file mode 100644
index 00000000000..4fc4c991e37
--- /dev/null
+++ b/docs/source/whatsnew/pr/end-shortcut-accept-suggestion.rst
@@ -0,0 +1,5 @@
+Added shortcut for accepting auto suggestion
+============================================
+
+Added End key shortcut for accepting auto-suggestion
+


Code review comments:
diff_hunk: @@ -267,15 +267,22 @@ def ebivim():
     focused_insert_vi = has_focus(DEFAULT_BUFFER) & vi_insert_mode
 
     # Needed for to accept autosuggestions in vi insert mode
-    @kb.add("c-e", filter=focused_insert_vi & ebivim)
-    def _(event):
+    def _apply_autosuggest(event):
         b = event.current_buffer
         suggestion = b.suggestion
         if suggestion:
             b.insert_text(suggestion.text)
         else:
             nc.end_of_line(event)
 
+    @kb.add("end", filter=has_focus(DEFAULT_BUFFER) & ebivim)
path: IPython/terminal/shortcuts.py
text: @user1:
The `ebvim` here states, that if you disable `TerminalInteractiveShell.emacs_bindings_in_vi_insert_mode`, the `End` key stops working in non-vi input mode too, which I think is something we don't want.

The filter here should check if it's outside of vi insert mode - if yes, then apply the binding unconditionally.
If we're in vi insert mode, apply it only when `ebvim` is `True`.

@user1:
See [prompt toolkit's builtin filters](https://python-prompt-toolkit.readthedocs.io/en/master/pages/advanced_topics/filters.html#built-in-filters) - I think you could use `~vi_insert_mode` to get the right condition.

@user2:
So this ended as `(ebivim | ~vi_insert_mode)`. It feels kind of wrong to me because in vi command mode it still evaluates to true (AFAIK). I wonder if it would be better as `(vi_insert_mode & ebivim) | emacs_insert_mode`. @user1 do you happen to still remember if it was considered/would have any disadvantage?