executing current python file in vim creates new file if current time is parsed
Question: I am executing python files from vim as described here: [How to execute file
I'm editing in Vi(m)](http://stackoverflow.com/questions/953398/how-to-
execute-file-im-editing-in-vim)

I observe the same behavior on Windows & Linux. For testing, I moved my .vim
so as to avoid other plugins interfering. Then I set:

    
    
    :set makeprg=python\ %
    

Now when I run an example file like this (called mini.py)

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

Now when I execute

    
    
    :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 kind of chokes on the datetime.now output and creates a new file with the
current date and instantly displays it.

Is this behavior to be expected?

If I comment out the .now() line (now().date() is not a problem apparently),
it works as expected and I more or less see the text output that I'd expect.


Answer: When you use `'makeprg'`, Vim parses the output according to `'errorformat'`
to retrieve error messages from the output. Your date output looks
conspicuously like a typical error message, and by default, `:make` jumps to
the first error location it encounters.

What you can do:

  * Use `:make!` (with bang); that will avoid the jump to the first error. Or:
  * In addition to setting `'makeprg'`, also clear the `'errorformat'` to avoid that Vim parses the output; unless you're only ever edit Python files with Vim; you should use `:setlocal`, not the global `:set`, and put that into `~/.vim/after/ftplugin/python.vim`:

    
    
    :setlocal makeprg=python\ %
    :setlocal errorformat=
    

