Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在vim上运行python_Vim_Python 2.7_Numpy_Ubuntu 12.04_Ipython - Fatal编程技术网

在vim上运行python

在vim上运行python,vim,python-2.7,numpy,ubuntu-12.04,ipython,Vim,Python 2.7,Numpy,Ubuntu 12.04,Ipython,在askubuntu.com上,有人告诉我怎么做。我正在测试一个设置,该设置与python的第1或第2代码代码一起工作 我所做的唯一不同的事情是添加了print(a)作为最后一行。我昨天从shell运行了这个,它工作得非常好。有人能告诉我出了什么问题吗 我用适当的问号纠正了vimrc chmod +x ~/path/to/file/hw6problem2.py 然后我从维姆跑过来 :Shell ./# 但是我又收到了同样的语法错误(是否因为无法运行任何.py文件而必须将文件另存为.sh? v

在askubuntu.com上,有人告诉我怎么做。我正在测试一个设置,该设置与python的第1或第2代码代码一起工作

我所做的唯一不同的事情是添加了print(a)作为最后一行。我昨天从shell运行了这个,它工作得非常好。有人能告诉我出了什么问题吗

我用适当的问号纠正了vimrc

chmod +x ~/path/to/file/hw6problem2.py
然后我从维姆跑过来

:Shell ./#
但是我又收到了同样的语法错误(是否因为无法运行任何.py文件而必须将文件另存为.sh?

vimrc

上的语法 au BufWinLeave*mkview“记录设置 au BufWinter*静默加载视图“重新加载设置 设置nu“将行号置于 set ic“不区分大小写 为latex套件设置foldmethod=syntax” 设置autoread“当缓冲区中的文件被修改时自动加载 设置autochdir“自动更改目录 “包起来 自动换行 “设置行=50列=80列 “调整窗口大小 :map g1:设置行=20:设置列=80 :map g2:设置行=50:设置列=80 :map g3:设置行=50:设置列=170 :地图:!firefox%& :地图E Ea “设置自动缩进 设置tabstop=4 设置shiftwidth=2 设置扩展选项卡 智能对齐 " “乳胶套装的材料 “需要。这使得vim在打开tex文件时调用Latex套件。 “它还允许您为不同的文件类型设置不同的操作 “在~/.vim/after/ftplugin/*.vim中 上的文件类型插件 设置shellslash 重要提示:如果您需要,grep有时会跳过显示文件名 “搜索单个文件。这将使Latex套件混淆。设置你的grep “始终生成文件名的程序。 设置grepprg=grep \-nH\$* “可选:这将在键入时启用自动缩进。 文件类型缩进 可选:从Vim 7开始,空.tex文件的文件类型默认为 “‘plaintex’而不是‘tex’,这会导致未加载vim乳胶。 “以下内容将默认文件类型更改回“tex”: 让g:tex_flavor='latex' 设g:Tex_ViewRule_pdf='okular' """"""""""""""""""""""""""""""""""""""" “=>Shell命令 """"""""""""""""""""""""""""""""""""""" 命令-complete=shellcmd-nargs=+Shell调用s:RunShellCommand() 功能!s:RunShellCommand(cmdline) 让isfirst=1 让单词=[] 对于拆分中的单词(a:cmdline) 如果是第一个 让isfirst=0“不更改第一个单词(shell命令) 其他的
如果单词[0]=~'\v[%#这可能是python的问题

另一方面,还有一个很棒的shell函数,用于执行脚本和将输出重定向到vim缓冲区(拆分窗口)

执行当前脚本的语法(应该有chmod+x和shebang行):

要添加该功能,请将其添加到
.vimrc

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)
  rightbelow new
  setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile nowrap
  call setline(1, 'You entered:  ' . a:cmdline)
  call setline(2, 'Expanded to:  ' . expanded_cmdline)
  call append(line('$'), substitute(getline(2), '.', '=', 'g'))
  silent execute '$read !'. expanded_cmdline
  1
endfunction
command!-complete=shellcmd-nargs=+Shell调用s:RunShellCommand()
函数!s:RunShellCommand(cmdline)
让isfirst=1
让单词=[]
对于拆分中的单词(a:cmdline)
如果是第一个
让isfirst=0“不更改第一个单词(shell命令)
其他的

如果单词[0]=~'\v[%#您能在第14行附近发布一些代码吗?这可能与Vim无关。这一行Python也没有问题。请发布整个Python文件(如果文件很大,请链接到它的要点),或更多的上下文。我怀疑你只是在介绍一个打字错误或其他东西。@PavelAnossov代码在第二行link@JimStewart代码在第二个链接中链接中的代码是第13行,而不是第14行。我将上述内容添加到vimrc中,然后使用#!/usr/bin/env python的shebang行运行代码,但收到以下错误:error在处理“*”的BufWinter自动命令时检测到:E32:无文件名按ENTER或键入command可在
bin/
env
!/usr/bin/env python
。尝试执行
:Shell./%
这是一个打字错误。现在它显示在处理“*”的BufWinter自动命令时检测到错误:E32:处理函数7_runshell时未检测到文件名错误命令:第20行:E499:“%”或“#”的空文件名,仅适用于“:p:h”:$read!。/%按ENTER键或键入命令continue@dustin您确定
.vimrc
中没有其他条目干扰工作流吗?@dustin,您的
.vimrc
的第2行和第3行,将
*
替换为
?*
,然后再次点击
:Shell./#
syntax on
au BufWinLeave * mkview "records settings
au BufWinEnter * silent loadview "reloads settings


set nu "puts line numbers on
set ic "case insensitive
set foldmethod=syntax "for the latex-suite
set autoread "autoload when files in the buffer have been modified
set autochdir "autochange directory


"set wrap
set wrap
" set lines=50 columns=80

" resizes window
:map g1 :set lines=20<CR>:set columns=80<CR>
:map g2 :set lines=50<CR>:set columns=80<CR>
:map g3 :set lines=50<CR>:set columns=170<CR>
:map <F6> :! firefox % &<CR>
:map E Ea

"set autoindent

set tabstop=4
set shiftwidth=2
set expandtab
set smartindent
"
" Stuff for latex-suite 

" REQUIRED. This makes vim invoke Latex-Suite when you open a tex file.
" It also allows you to set different actions for different filetypes
" in ~/.vim/after/ftplugin/*.vim
filetype plugin on

set shellslash

" IMPORTANT: grep will sometimes skip displaying the file name if you
" search in a singe file. This will confuse Latex-Suite. Set your grep
" program to always generate a file-name.
set grepprg=grep\ -nH\ $*

" OPTIONAL: This enables automatic indentation as you type.
filetype indent on

" OPTIONAL: Starting with Vim 7, the filetype of empty .tex files defaults to
" 'plaintex' instead of 'tex', which results in vim-latex not being loaded.
" The following changes the default filetype back to 'tex':
let g:tex_flavor='latex'
let g:Tex_ViewRule_pdf = 'okular'


"""""""""""""""""""""""""""""""""""""""
" => Shell command
"""""""""""""""""""""""""""""""""""""""

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)
rightbelow new
setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile nowrap
call setline(1, 'You entered:  ' . a:cmdline)
call setline(2, 'Expanded to:  ' . expanded_cmdline)
call append(line('$'), substitute(getline(2), '.', '=', 'g'))
silent execute '$read !'. expanded_cmdline
1
endfunction
:Shell ./#
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)
  rightbelow new
  setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile nowrap
  call setline(1, 'You entered:  ' . a:cmdline)
  call setline(2, 'Expanded to:  ' . expanded_cmdline)
  call append(line('$'), substitute(getline(2), '.', '=', 'g'))
  silent execute '$read !'. expanded_cmdline
  1
endfunction