Vim as python ideal

Python support is integrated in the latest versions of emacs. For example, it C-c C-zprovides me with an interpreter, but C-c C-cautomatically interprets the file that I am working on without moving to another buffer. (Although there are some drawbacks to the emacs approach)

Is it possible in vim or just as easy to do as in emacs in just two keystrokes? I know that I can evaluate the expression with :python, but that’s not quite what I want.

+5
source share
3 answers

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

The vim-ipython plugin allows you to open the 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 parallel shell and vim).

There are many plugins that can turn vim into a really good python development environment. "pyflakes", which automatically highlights syntax errors, is one of my favorites.

This blog post describes vim plugins for python:

http://sontek.net/blog/detail/turning-vim-into-a-modern-python-ide


(*) , python ( ++ python). , python.vim .vim/ftplugin

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

.vimrc. , \ll .

, , (SHIFT + v) :!python %. python!

+11

, . vim.

0

, Vim, . subversion. vim.

Vim can also be compiled with the built-in Python interpreter, which you can use to evaluate lines of code in a buffer or add new functions using Python. Try :help pythonfor more information.

I use X Windows, so most of them work in this environment and invoke a shell wrapper from Vim that looks like this:

1 $ cat bin / xpython

#!/bin/sh

if [ $# -gt 0 ] ; then
    urxvt -title Python2 -name Python -e python -i "$@"
else
    urxvt -title Python2 -name Python -e bpython
fi

So, from Gvim you can run xpython instead of plain python being mapped to a key (see source). This will open a new terminal window with a new Python instance with your code.

0
source

All Articles