When I am developing some python script, I regularly find myself running part of the code to see if it does what I want it to do. Currently I do this by copying the code that I want to run to the clipboard, alt-tabbing to the console and then %pasteing the code into ipython.
Of course this procedure is far from ideal, which is why I want to make use of the new :term and term_sendkeys(). I can send code to ipython using term_sendkeys(), but somehow I cannot get ipython to actually run the code. Below is a summary of my steps thus far:
First I start vim 8.1 using vim -u NONE in a normal command prompt on Windows 7. Then I run :term to create the terminal buffer. In this buffer I type <c-w>:echo bufnr('%')<cr> to find the number of the buffer and find that the number is 2. Then I move to the text buffer and run two commands:
:call term_sendkeys(2, "ipython\<cr>")
:call term_sendkeys(2, "a=1\<cr>")
The first starts ipython as expected. The second enters a=1 and a newline. However, when I type the same sequence of keys in ipython hitting enter actual executes the statement instead of starting a new line. I therefore believe that either vim is sending another key than I think it's sending or that ipython treats keys received in this way differently than keys received from the user directly. What am I doing wrong?
:call term_feedkeys(2, "a=1\<cr>")results in an unknown function error and:h term_feedkeyssays there is no help for this function. – Octaviour Jul 11 '19 at 07:56feedkeysmaybe – D. Ben Knoble Jul 11 '19 at 13:05:buffer 2|feedkeys("a=1\<cr>", 'x')|buffer 1? This produces the same result asterm_sendkeys. – Octaviour Jul 11 '19 at 13:19:h terminal-to-job), regular python, or ipython. For me, all three of those do the correct thing. Note that the help says the job must be in the right state; perhaps your keys are being sent to ipython too early? Yet even for me sending the keys immediately works as expected – D. Ben Knoble Jul 11 '19 at 13:42