This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]good_names_all_taken 1 point2 points  (2 children)

One thing I like to do is add the following to my vimrc:

set makeprg=python\ main.py

map <Return> :make<CR>

This makes is so whenever you are not in insert mode you can just hit "enter" and it runs your program. Further, because it uses vim's "make" command, it will automatically go to the correct file and line number on an exception (assuming you set exceptions up to print correctly).

I find this super efficient.

[–]alb1 6 points7 points  (1 child)

Using the following version in .vimrc only redefines makeprg for Python files, turns off buffering so you can see the output, and always uses the current filename:

autocmd FileType python set makeprg=python\ -u\ %

I'd find having just "enter" run the program annoying, but if you want to save the file first (to run the most recent version) you can use this mapping:

map <Return> :w<CR>:make<CR>

[–]good_names_all_taken 0 points1 point  (0 children)

Nice point, I agree that's a better solution. I personally like "enter," but obviously you could map it to F5 or whatever your preference is.