使用python2.7和python3.x的Vim源代码编译选项

时间:2015-09-24 03:00:40

标签: python-2.7 python-3.x vim

我想用vim编写Python2 / 3代码,我想知道如何从编辑器编译和运行?有没有人有任何好的建议,谢谢?

2 个答案:

答案 0 :(得分:0)

Pymode可以使用<leader>r运行代码。这是一个例子: enter image description here

如果你正在使用vim编写Python 2和Python 3,也许你应该用+python2编译一个vim,用+python3编译另一个vim(然后使用第一个编写python 2代码,第二个写python 3代码),

因为Pymode和python的其他插件需要+python2/3,但问题是vim无法用它们编译。

答案 1 :(得分:0)

我使用一个简单的脚本来运行python程序。它只需要在机器上安装python。它的作用是运行程序并在Vim的覆盖框中显示它的输出。问题是:如果您的程序是交互式的,它将无法工作。它只是在程序结束后显示其输出

我的工作是:

command! -complete=shellcmd -nargs=+ Shell call s:RunShellCommand(<q-args>)
function! s:RunShellCommand(cmdline)
    let isfirst = 1
    let words = []
    for word in split(a:cmdline)
        if isfirst
            let isfirst = 0  " don't change first word (shell command)
        else
            if word[0] =~ '\v[%#<]'
                let word = expand(word)
            endif
            let word = shellescape(word, 1)
        endif
        call add(words, word)
    endfor
    let expanded_cmdline = join(words)
    botright new
    setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile nowrap
    "call setline(1, 'You entered:  ' . a:cmdline)
    call setline(1, 'CMD:  ' . expanded_cmdline)
    call append(line('$'), substitute(getline(2), '.', '=', 'g'))
    silent execute '$read !'. expanded_cmdline
    1
endfunction

这个RunShellCommand运行一个命令并在vim中的弹出窗口中显示它。将其粘贴到您的vimrc中。

对于python,我使用这个

nnoremap <silent> <leader>r :Shell python %:p<cr>
<vimdir>/ftplugin/python.vim

中的

这一切我要做的就是使用,r(我的<leader>,)并运行当前打开的python文件并显示其输出。