vim as a python ide

后端 未结 3 713
野趣味
野趣味 2021-02-04 20:04

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 f

相关标签:
3条回答
  • 2021-02-04 20:18

    Yes, I've spend some time extending Vim to do exactly that. Most of my attempts are available in a subversion repository. See the vim tree.

    Vim can also be compiled with an embedded Python interpreter, which you can use to evaluate lines of code in the buffer, or add new functionality using Python. Try :help python for details.

    I use X Windows, so most of these work in that 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 just python, mapped to a key (see the source). This will open a new terminal window with a new Python instance running your code.

    0 讨论(0)
  • 2021-02-04 20:24

    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).

    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).

    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.

    This blog post describes vim plugins for python extensively:

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


    (*) 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>
    

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

    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!

    0 讨论(0)
  • 2021-02-04 20:42

    In order to using keystrokes see mapping keys in vim.

    0 讨论(0)
提交回复
热议问题