1

Sometimes I'll be entering a long statement into ipython

In [4]: def foo():
   ...:     a
   ...:     bery  # here's the error
   ...:     long
   ...:     function
   ...:     definition
   ...:     that
   ...:     has
   ...:     some
   ...:     error
   ...:     at
   ...:     the
   ...:     top
   ...:

And I'd like to be able to fix the error and submit the function but instead my workflow looks like this

In [7]: def foo():
   ...:     a
   ...:     very  # 2) FIXED - I want to be able to ENTER from this line
   ...:     # 3) but instead I get a newline
   ...:     long
   ...:     function
   ...:     definition
   ...:     that
   ...:     has
   ...:     some
   ...:     error
   ...:     at
   ...:     the
   ...:     top
   ...:     # 1) I have to start here and scroll all the way to the top
   ...:     # 4) so now I have  to scroll all the way down here to ENTER the fixed function
   ...:

Any advice on how to

  • More efficiently navigate to the top of the code that I want to edit
  • Be able to submit from a line that is not the end
Dan Frank
  • 1,887
  • 1
  • 18
  • 13

1 Answers1

1

To submit a cell from anywhere in the block, hit ESC + return.

I am not sure about navigating to the top of the code (I am wondering the same myself, which is how I found your question). I find this is particularly problematic when scrolling back through history and then encountering a long block.

Edit: in case it's helpful, another useful trick is Ctrl + O to enter a new line in the same cell regardless of whether iPython wants to or not. Kind of the opposite of ESC + return.

ytrepus
  • 26
  • 1
  • 1
  • Thank you! If you do find a solution to quick navigation please do let me know. – Dan Frank Oct 19 '17 at 18:21
  • Looks like there is more documentation here: http://ipython.readthedocs.io/en/stable/config/shortcuts/ and we can also get into vim command mode with this option --TerminalInteractiveShell.editing_mode=vi See https://stackoverflow.com/questions/10394302/how-do-i-use-vi-keys-in-ipython-under-nix – Dan Frank Oct 20 '17 at 01:49