2013-05-07 37 views
2

我從VIM執行此處描述Python文件的新文件: How to execute file I'm editing in Vi(m)執行當前的Python文件創建,如果當前時間解析

我看到在Windows &的Linux相同的行爲。 爲了測試,我移動了我的.vim以避免其他插件干擾。然後,我設置:

:set makeprg=python\ % 

現在,當我運行像這樣(被稱爲mini.py)的示例文件

import datetime 

print "hello" 

def foo1(): 
    print "foo" 
    print "str: " + str(datetime.datetime.now()) 
    print "str: " + str(datetime.datetime.now().date()) 

foo1() 

現在,當我執行

:make 
"mini.py" 10L, 173C written 
:!python mini.py 2>&1| tee /tmp/vew33jl/9 
hello 
foo 
str: 2013-05-07 17:01:47.124149 
str: 2013-05-07 
"str: 2013-05-07 17" [New File] 
(3 of 4): 47.124149 

VIM樣的扼流圈上datetime.now輸出並使用當前日期創建一個新文件並立即顯示它。

這是行爲嗎?如果我註釋掉.now()行(now().date()顯然不是問題),它會按預期工作,我或多或少地看到我期望的文本輸出。

回答

1

當您使用'makeprg'時,Vim根據'errorformat'解析輸出以從輸出中檢索錯誤消息。日期輸出看起來很像典型的錯誤消息,默認情況下,:make跳轉到遇到的第一個錯誤位置。

你可以做什麼:

  • 使用:make!(與爆炸);這將避免跳轉到第一個錯誤。或者:
  • 除了設置'makeprg'之外,還要清除'errorformat'以避免Vim解析輸出;除非你只用Vim編輯Python文件;你應該使用:setlocal,而不是全球:set,並將它放入~/.vim/after/ftplugin/python.vim
:setlocal makeprg=python\ % 
:setlocal errorformat= 
+0

所以基本上我會設置: AU文件類型蟒蛇SETLOCAL makeprg =蟒蛇\% AU文件類型蟒蛇SETLOCAL錯誤格式運用於= 這是等同的,對吧? – 2013-05-07 11:49:53

+0

是的,這是等價的,但是我的解決方案在很多這樣的設置中縮放比較好(但是需要':filetype plugin on')。 – 2013-05-07 12:33:58