Yank/copy selected text to clipboard in IPython Vi mode

Zaid Gharaybeh :

I can't figure out how to copy lines that I selected/highlighted in IPython in Vim mode to the normal clipboard (to be pasted outside of the IPython shell). Normally, in vim I can yank text using "+y and paste it somewhere else, but hitting those keys in IPython Vim mode doesn't seem to work. So I end up having to highlight the desired text using my mouse and copying it with Command-C.

This is an annoyance because if I have multiple lines in IPython there will be many junk characters that I have to filter out as seen below:

In [8]: import numpy as np 
   ...: import math 
   ...:  
   ...: print("hi") 
   ...: while(True): 
   ...:     break 
   ...:  
   ...: x = 3 
   ...: y = 4 
   ...:  
   ...:   

Here I would have to filter out the In [8] and the ...: on each line. But selecting using v or V appropriately ignores these junk characters.

This answer doesn't say how to do it in Vi mode and also doesn't mention anything about yanking to the system's clipboard.

CyclicUniverse :

if you are running ipython inside vim terminal, you can type the following in ipython: %history -l 10

This will print last 10 commands without the leading dots. Which can be easily copied.

You need to open the ipython in vim terminal. And then, after typing the %history command (above), you will need to go to normal mode with key-combination Ctrl-W Shift_N. Then, copy multiple lines using V (block visual model) into + register with "+y command. You can then copy it into another vim buffer using "+p or another application such as gedit using 'right click, then paste.'

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=220598&siteId=1