Vim Tips Wiki
Advertisement
Tip 733 Printable Monobook Previous Next

created 2004 · complexity basic · author Rene Aguirre · version 5.7


I just discovered Vim, I really liked 'split' capability, I'm so used to edit Python source code on SciTe editor, I really missed the default CTRL-1 to check the syntax and F5 to run the script...

So, this is my suggestion, add these lines to your vimrc file:

autocmd BufRead *.py set makeprg=python\ -c\ \"import\ py_compile,sys;\ sys.stderr=sys.stdout;\ py_compile.compile(r'%')\"
autocmd BufRead *.py set efm=%C\ %.%#,%A\ \ File\ \"%f\"\\,\ line\ %l%.%#,%Z%[%^\ ]%\\@=%m
autocmd BufRead *.py nmap <F5> :!python %<CR>

Make your that python is in your path, now when you open any python file just type ":make" to get the syntax errors, use ":cnext", to move to next error, check the help on make (":help make") for more info on how to navigate errors.

As you are checking now, <F5> is mapped to execute the current script. Also I suggest you to use add the following lines to vimrc:

autocmd BufRead *.py set tabstop=4
autocmd BufRead *.py set nowrap
autocmd BufRead *.py set go+=b

That will make to use a 4 spaces for you tabstop (only visually), it avoids wrapping your code and will add a bottom scrollbar. Now I like vim a litle bit more.

print ("You wake up in a dirty alley with a dog by your side. You know nothing of what happened or is happening. You see a knife to your left, and a dog tag.") command1 = input () dogtag = "pick up dog tag" or "pick up dogtag" knife = "pick up knife" if command1 == dogtag:

   print ("You picked up the dog tag. It says 'Corporal David J. Andrews, US Army federal enforcer'."

if command1 == knife:

   print ("You pick up the knife and notice the letters DJA engraved on the silver blade. You also notice that you're wearing US army uniform. There might be something in one of the pockets.")

else:

   print ("You can't do that right now.")
Advertisement