title: running python on vim
body: <p>Over on askubuntu.com I was told how to <a href="https://askubuntu.com/questions/273066/running-python-in-vim/273068?noredirect=1#comment344013_273068">run python on Vim</a>.  I am testing the set up which works with the code 1st or 2nd code python code at <a href="https://stackoverflow.com/questions/15649134/using-python-to-solve-a-nonlinear-equation/15652210?noredirect=1#15652210">using python to solve a non linear equation</a>.</p>
  
  <p>The only thing I have done different was added print(a) as the last line.  I ran this yesterday from the shell and it worked perfectly.  Could someone let me know what is going wrong?</p>
  
  <p>Ok so I corrected the vimrc with the appropriate question marks, </p>
  
  <pre><code>chmod +x ~/path/to/file/hw6problem2.py
  </code></pre>
  
  <p>Then from vim I ran </p>
  
  <pre><code>:Shell ./#
  </code></pre>
  
  <p>but I received the same syntax error again. <strong>(Does the file have to be saved as .sh because I can't get any .py files to run?)</strong></p>
  
  <pre><code>dustin@dustin:~$ vim /home/dustin/Documents/School/UVM/Engineering/OrbitalMechanics/hw6problem2.py
  
  File "hw6problem2.py", line 14
  a0 = max(s/2, (s - c)/2)
   ^
  SyntaxError: invalid syntax
  
  shell returned 1
  
  Press ENTER or type command to continue
  </code></pre>
  
  <p>vimrc</p>
  
  <pre><code>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&lt;CR&gt;:set columns=80&lt;CR&gt;
  :map g2 :set lines=50&lt;CR&gt;:set columns=80&lt;CR&gt;
  :map g3 :set lines=50&lt;CR&gt;:set columns=170&lt;CR&gt;
  :map &lt;F6&gt; :! firefox % &amp;&lt;CR&gt;
  :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'
  
  
  """""""""""""""""""""""""""""""""""""""
  " =&gt; Shell command
  """""""""""""""""""""""""""""""""""""""
  
  command! -complete=shellcmd -nargs=+ Shell call s:RunShellCommand(&lt;q-args&gt;)
  
  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[%#&lt;]'
      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
  </code></pre>