You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
prompt-toolkit does not process .inputrc yet. Mainly because there was no obvious 1-to-1 mapping of the readline and the prompt-toolkit functionality. Especially because the readline configuration uses vt100 escape codes to define key bindings. This is for historical reasons and not platform independent.
However, detecting whether the editing-mode is vi (set editing-mode vi), or whether the user has interest in history-search-backward (e.g.:"\e[A":history-search-backward) is not going to be difficult.
Hi Paul! I wondered when we'd be seeing you after this change ;-). You're right, we should definitely mention it in the release notes.
I don't think we should try to do any interpretation of inputrc: I'd rather be able to say unambiguously 'no, that no longer affects input in IPython, here are the new ways to configure things', rather than dealing with a situation where some entries in there work and others don't.
For reference, the config option to enable vi mode is now TerminalInteractiveShell.vi_mode (which is a boolean).
So, how do you configure "\e[A":history-search-backward? And how do you get up arrow to be normal up arrow and not history search? In old versions I could do
We should make history search (the behaviour of the up and down arrows) configurable - I've just opened #9961 for that.
For adding custom shortcuts, see the docs. Unfortunately at present you have to go digging in the prompt_toolkit code to find/write a function that does what you want. The normal behaviour of the up-arrow key is defined here and here.
prompt-toolkit introduces several editing regressions compared to readline :/. For example, forward/backward-word do not work anymore in urxvt, and there's no way to configure the different escape sequences without editing the internal bindings.
I agree with @wavexx. I have stopped using the new version of IPython because the prompt is so much worse. Although readline is not perfect, it uses my standard ~/.inputrc and I'm happy. The new version of IPython is unusable because of prompt-toolkit. If I were you, I'd revert that change.
@MarkLodato Could you share your inputrc? Are you missing some functionality, or do you have custom key bindings? I plan to support .inputrc at some point, but it won't be in the near future. (Takes more time than I expected.)
Sorry, we're not about to revert it. We expected there would be some rough edges with a change this big, but prompt_toolkit allows us to do things we couldn't with readline: live syntax highlighting, and proper multiline editing. It also makes installation simpler on Windows and Mac, because we don't need pyreadline and gnureadline (respectively).
If vi mode cannot be supported via readline, what are the instructions and tips
for the forementioned multiline editing -- how does it work?
Can one call vim into the IPython environment to make edits?
In IPython config, the relevant option is TerminalInteractiveShell.editing_mode. Setting it to the string 'vi' should give you prompt_toolkit's vi bindings.
Can one call vim into the IPython environment to make edits?
In 5.2 (coming very soon, we hope), you can press F2 at the IPython prompt to jump into $EDITOR.
Multiline editing in the prompt means that if you type e.g. for a in rage(5):<enter>, you can press up-arrow and go back to the line above, without having to cancel the input. It may sound trivial, but previous versions of IPython couldn't do that.
P.S. is it possible to reassign the ESC key in vi-mode?
See custom keyboard shortcuts - though at present, you'll have to dig around in the prompt_toolkit source code to find what function to call to do the action.
P.S.S. since PromptManager is deprecated, what is the correct way to set PromptManager.in_template?
It is a gist which was adapted from your gist of five months ago.
Unlike the official documentation sample code, the execution_count
number has been included in the custom In and Out prompts.
I will update my gist as I discover new v5+ features.
Not sure if this can be still of any help to anyone, but I just figured out how to get alt-p/alt-n bound to history backward and forward respectively (as @DanielO and @MarkLodato were asking a couple of years ago). Since I haven't found any reference about this other than this old issue, I'll leave it here hoping can be of help.
fromIPythonimportget_ipythonfromprompt_toolkit.enumsimportDEFAULT_BUFFERfromprompt_toolkit.filtersimportHasFocusip=get_ipython()
defhistory_fwd(event):
event.current_buffer.history_forward(count=event.arg)
defhistory_back(event):
event.current_buffer.history_backward(count=event.arg)
# Register the shortcut if IPython is using prompt_toolkit ifgetattr(ip, 'pt_app', None):
registry=ip.pt_app.key_bindingsregistry.add_binding('escape', 'p',
filter=HasFocus(DEFAULT_BUFFER))(history_back)
registry.add_binding('escape', 'n',
filter=HasFocus(DEFAULT_BUFFER))(history_fwd)
If you save this in the startup directory of your default ipython profile, it should work (at least it works for me). Of course it would be nice to get this easily without having to understand part of the internals of both IPython and prompt_toolkit.
HTH
Reacted by Dave Hirschfeld, Markus Wageringel and Nathaniel Whiteinge
Activity
jonathanslenders commentedon Apr 9, 2016
Hi all,
prompt-toolkit does not process
.inputrcyet. Mainly because there was no obvious 1-to-1 mapping of the readline and the prompt-toolkit functionality. Especially because the readline configuration uses vt100 escape codes to define key bindings. This is for historical reasons and not platform independent.However, detecting whether the editing-mode is vi (
set editing-mode vi), or whether the user has interest inhistory-search-backward(e.g.:"\e[A":history-search-backward) is not going to be difficult.The crash guys are doing this: https://github.com/crate/crash/blob/d8e49c0aec8f1c70c49fe56e7f3e967bde1f44a3/src/crate/crash/command.py#L415
See also: prompt-toolkit/python-prompt-toolkit#56
Jonathan
takluyver commentedon Apr 9, 2016
Hi Paul! I wondered when we'd be seeing you after this change ;-). You're right, we should definitely mention it in the release notes.
I don't think we should try to do any interpretation of inputrc: I'd rather be able to say unambiguously 'no, that no longer affects input in IPython, here are the new ways to configure things', rather than dealing with a situation where some entries in there work and others don't.
For reference, the config option to enable vi mode is now
TerminalInteractiveShell.vi_mode(which is a boolean).Carreau commentedon Apr 30, 2016
Marking as 5.0 to, at least, document it.
Update docs on `.inputrc` and input mode.
Carreau commentedon May 27, 2016
documented in #9497, bumbing to 6.0 to reevaluate.
MarkLodato commentedon Sep 18, 2016
So, how do you configure
"\e[A":history-search-backward? And how do you get up arrow to be normal up arrow and not history search? In old versions I could dobut that no longer works.
takluyver commentedon Sep 19, 2016
We should make history search (the behaviour of the up and down arrows) configurable - I've just opened #9961 for that.
For adding custom shortcuts, see the docs. Unfortunately at present you have to go digging in the prompt_toolkit code to find/write a function that does what you want. The normal behaviour of the up-arrow key is defined here and here.
wavexx commentedon Nov 9, 2016
prompt-toolkit introduces several editing regressions compared to readline :/. For example, forward/backward-word do not work anymore in urxvt, and there's no way to configure the different escape sequences without editing the internal bindings.
takluyver commentedon Nov 9, 2016
Forward/backward word works OK in my terminal; I don't see urxvt in my repos to test with.
wavexx commentedon Nov 9, 2016
On Wed, Nov 09 2016, Thomas Kluyver wrote:
On debian it's rxvt-unicode/rxvt-unicode-*.
See prompt-toolkit/python-prompt-toolkit#415
MarkLodato commentedon Nov 9, 2016
I agree with @wavexx. I have stopped using the new version of IPython because the prompt is so much worse. Although readline is not perfect, it uses my standard ~/.inputrc and I'm happy. The new version of IPython is unusable because of prompt-toolkit. If I were you, I'd revert that change.
jonathanslenders commentedon Nov 9, 2016
@MarkLodato Could you share your inputrc? Are you missing some functionality, or do you have custom key bindings? I plan to support .inputrc at some point, but it won't be in the near future. (Takes more time than I expected.)
6 remaining items
takluyver commentedon Nov 9, 2016
@jonathanslenders thanks, that's a good start. I might look into ways to scrape that list of names to offer a list in the docs.
DanielO commentedon Jan 19, 2017
Is there a handy cut & paste to get reverse/forward history search with esc-p / esc-n? :)
rsvp commentedon Jan 29, 2017
What would be the IPython equivalent to
set editing-mode viin an .inputrc Linux readline config file?@takluyver wrote:
If vi mode cannot be supported via readline, what are the instructions and tips
for the forementioned multiline editing -- how does it work?
Can one call vim into the IPython environment to make edits?
takluyver commentedon Jan 29, 2017
In IPython config, the relevant option is
TerminalInteractiveShell.editing_mode. Setting it to the string 'vi' should give you prompt_toolkit's vi bindings.In 5.2 (coming very soon, we hope), you can press F2 at the IPython prompt to jump into $EDITOR.
takluyver commentedon Jan 29, 2017
Multiline editing in the prompt means that if you type e.g.
for a in rage(5):<enter>, you can press up-arrow and go back to the line above, without having to cancel the input. It may sound trivial, but previous versions of IPython couldn't do that.rsvp commentedon Jan 30, 2017
hi @takluyver Thanks very much for your prompt :) support !
Just to clarify for other users...
Setting IPython (v5+) PROMPT to vi-mode
This works like Linux vi-mode for readline, except the developers
have crafted a cross-platform solution.
c.TerminalInteractiveShell.editing_mode = 'vi'P.S. is it possible to reassign the ESC key in vi-mode?
I have been using semi-colon for this purpose.
P.S.S. since PromptManager is deprecated, what is the correct way
to set PromptManager.in_template?
Edit: Updated solutions posted here: https://git.io/ipython_config.py
takluyver commentedon Jan 30, 2017
See custom keyboard shortcuts - though at present, you'll have to dig around in the prompt_toolkit source code to find what function to call to do the action.
See custom prompts. :-)
rsvp commentedon Jan 30, 2017
@takluyver Thanks for your tremendous help. I've summarized the solutions so far here:
https://git.io/ipython_config.py
It is a gist which was adapted from your gist of five months ago.
Unlike the official documentation sample code, the execution_count
number has been included in the custom In and Out prompts.
I will update my gist as I discover new v5+ features.
takluyver commentedon Jan 30, 2017
Thanks for that summary 🍪
mrrech commentedon Apr 4, 2019
Not sure if this can be still of any help to anyone, but I just figured out how to get
alt-p/alt-nbound to history backward and forward respectively (as @DanielO and @MarkLodato were asking a couple of years ago). Since I haven't found any reference about this other than this old issue, I'll leave it here hoping can be of help.If you save this in the startup directory of your default ipython profile, it should work (at least it works for me). Of course it would be nice to get this easily without having to understand part of the internals of both IPython and prompt_toolkit.
HTH