vim 作为 python ide

编程入门 行业动态 更新时间:2024-10-27 01:30:49
本文介绍了vim 作为 python ide的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

Python 支持集成在最新版本的 emacs 中.例如,C-c C-z 为我提供了一个解释器,C-c C-c 会自动解释我正在处理的文件,而无需移动到另一个缓冲区.(虽然 emacs 的方法有一些缺点)

Python support is integrated in the latest versions of emacs. For example C-c C-z provides me an interpreter and C-c C-c automatically interprets the file I'm working on without moving to the other buffer. (Although there are some downsides to emacs's approach)

这在 vim 中是可能的,还是像在 emacs 中一样简单,只需两次击键?我知道我可以用 :python 计算表达式,但这不是我想要的.

Is this possible in vim, or as easy done as in emacs with just two keystrokes? I know I can evaluate an expression with :python, but it is not exactly what I desire.

推荐答案

要在 python 中执行当前文件,可以使用命令 :!python %.您可以通过编辑 vimrc 将其绑定到键盘快捷键.例如,将 nnoremap \ll :!python %<cr> 添加到您的 vimrc 中,当您在正常模式下键入 \ll 时,将在 python 中执行当前文件.(* 更多细节见脚注).

To execute the current file in python, you can use the command :!python %. You can bind this to a keyboard shortcut by editing your vimrc. For example, adding nnoremap \ll :!python %<cr> to your vimrc will execute the current file in python when you type \ll in normal mode. (* see footnote for more details).

vim-ipython 插件可以让你在 vim 中打开一个 ipython 窗口.您可能还对 tmux 感兴趣,它允许您将终端垂直拆分为两个(这样您就可以让 shell 和 vim 并行运行).

The vim-ipython plugin lets you open an ipython window in vim. You may also be interested in tmux, which allows you to split your terminal in two, vertically (so you can have a shell and vim running in parallel).

有很多插件可以将 vim 变成一个非常好的 Python IDE.pyflakes"会自动突出显示语法错误,是我特别喜欢的.

There are plenty of plugins that can turn vim into a really good python IDE. "pyflakes", which automatically highlights syntax errors, is a particular favorite of mine.

这篇博文广泛地描述了 Python 的 vim 插件:

This blog post describes vim plugins for python extensively:

http://sontek/blog/细节/将vim-into-a-modern-python-ide

(*) 顺便说一句,您可能希望将此命令特定于 python 文件(在 python 解释器中执行 C++ 源代码实际上没有意义).这可以通过将它放在 .vim/ftplugin 目录中的特定 python.vim 文件中来完成,或者通过编写

(*) As an aside, you may want to make this command specific to python files (it doesn't really make sense to execute C++ source in a python interpreter). This can be done either by putting it in a specific python.vim file in your .vim/ftplugin directory, or by writing

autocmd FileType python nnoremap \ll :!python %<cr>

在你的 .vimrc 中.这样,您可以将 \ll 键盘快捷键重新绑定到不同类型文件的不同操作.

in your .vimrc. That way, you can rebind the \ll keyboard shortcut to different actions for different types of file.

另外,如果您只想执行当前文件的一部分,请在可视模式 (SHIFT+v) 中选择相关行并键入 :!python % 命令.选定的行将通过管道传输到 python 解释器!

As a second aside, if you just want to execute a section of the current file, select the relevant lines in visual mode (SHIFT+v) and type the :!python % command. The lines selected will get piped to the python interpreter!

这篇关于vim 作为 python ide的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-27 17:37:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1158563.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:vim   python   ide

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!