[英]how to output all the lines into python console in vim?
I have set F2 prompt key with map <f2> :w<cr>:! D:\\Python34\\python %<cr>
我已经用
map <f2> :w<cr>:! D:\\Python34\\python %<cr>
设置了F2提示键map <f2> :w<cr>:! D:\\Python34\\python %<cr>
map <f2> :w<cr>:! D:\\Python34\\python %<cr>
,when i open an python file in vim and press F2,the python file will be executed .For a simple example, here is my python file and opened in gvim . map <f2> :w<cr>:! D:\\Python34\\python %<cr>
,当我在vim中打开python文件并按F2时,将执行python文件。举个简单的例子,这是我的python文件并在gvim中打开。
Now i can't input other python lines ,only thing i can do is to see the result and hit any key to close this window. 现在我无法输入其他python行,我唯一能做的就是查看结果并按任意键关闭此窗口。 What i want is : when i press F2, (the python file was opened in gvim) ,the python console pop up,and all the files in the python file were copied into the python console automatically,and i can go no to input some lines such as
Obj().hello
in the python console or go on to edit in gvim ,i am a lazy man ,the gvim and python console all opened waiting to serve me , can i write a vim scripts to achieve the target? 我想要的是:当我按F2,(python文件在gvim中打开)时,python控制台弹出,python文件中的所有文件都被自动复制到python控制台,我可以拒绝输入一些在python控制台中如
Obj().hello
这样的行或者继续在gvim中编辑,我是一个懒人,gvim和python控制台都打开等待为我服务,我可以编写一个vim脚本来实现目标吗? The command :!D:\\Python34\\python -i %
works fine ,i got the ouput 命令
:!D:\\Python34\\python -i %
工作正常,我得到了输出 There is still a problem remain, 1)when command
:!D:\\Python34\\python -i %
works ,the gvim window will be frozen , i can't drag my mouse to see codes in vim. 还有一个问题依旧,1)当命令
:!D:\\Python34\\python -i %
工作时,gvim窗口将被冻结,我无法拖动鼠标来查看vim中的代码。 2)there is no any python codes in the python console wiondow 2)python控制台wiondow中没有任何python代码
So if the program is full of many lines ,and i can't remember the previous content ,worse still, the gvim window frozen ,how can i get the codes? 因此,如果程序中有很多行,并且我记不起以前的内容,更糟糕的是,gvim窗口被冻结,我怎样才能获得代码?
To make the call asynchonous (to avoid that GVIM is blocked during the Python session), use the Windows-specific :!start
command: 要使调用异步(以避免在Python会话期间阻止GVIM),请使用特定于Windows的
:!start
命令:
nnoremap <f2> :w<cr>:!start D:\Python34\python -i %<cr>
I don't know whether it is possible to list the passed source code from the interactive Python debugger. 我不知道是否可以从交互式Python调试器列出传递的源代码。 But you can print the file contents before starting it:
但您可以在启动之前打印文件内容:
nnoremap <f2> :w<cr>:!start cmd /c type % && D:\Python34\python -i %<cr>
:noremap
; :noremap
; it makes the mapping immune to remapping and recursion. :nnoremap
(or extend it to support visual-mode selections, too). :nnoremap
(或将其扩展为支持可视模式选择)。 :ConqueTermVSplit python -i test.py
(VSplit is for vertical split - you may use horizontal) :ConqueTermVSplit python -i test.py
(VSplit用于垂直拆分 - 你可以使用水平) You could approach the problem from the Python angle (2.7). 您可以从Python角度(2.7)处理问题。
import demo
import demo
demo.SomeModule().meth()
demo.SomeModule().meth()
reload(demo)
reload(demo)
demo.SomeModule().differentMeth()
demo.SomeModule().differentMeth()
You can also have vim create a file with shortcut functions for loading/reloading the file you are working on. 您还可以让vim创建一个带有快捷功能的文件,用于加载/重新加载您正在处理的文件。 When vim kicks off the interpreter, you can have it set this file to the
PYTHONSTARTUP
environment variable, which is a file the interpreter will automatically load when it starts up. 当vim启动解释器时,您可以将此文件设置为
PYTHONSTARTUP
环境变量,该变量是解释器在启动时自动加载的文件。 For example, you could have a function called r()
to automatically reload the file you are working on. 例如,您可以使用一个名为
r()
的函数来自动重新加载您正在处理的文件。
It's also worth mentioning that reloading modules can be a little weird. 值得一提的是,重装模块可能有点奇怪。 If you instantiate some modules then reload the file, only new modules will use the new code;
如果你实例化一些模块然后重新加载文件,只有新模块将使用新代码; the old modules will run with the old code.
旧模块将使用旧代码运行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.