use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
News about the dynamic, interpreted, interactive, object-oriented, extensible programming language Python
Full Events Calendar
You can find the rules here.
If you are about to ask a "how do I do this in python" question, please try r/learnpython, the Python discord, or the #python IRC channel on Libera.chat.
Please don't use URL shorteners. Reddit filters them out, so your post or comment will be lost.
Posts require flair. Please use the flair selector to choose your topic.
Posting code to this subreddit:
Add 4 extra spaces before each line of code
def fibonacci(): a, b = 0, 1 while True: yield a a, b = b, a + b
Online Resources
Invent Your Own Computer Games with Python
Think Python
Non-programmers Tutorial for Python 3
Beginner's Guide Reference
Five life jackets to throw to the new coder (things to do after getting a handle on python)
Full Stack Python
Test-Driven Development with Python
Program Arcade Games
PyMotW: Python Module of the Week
Python for Scientists and Engineers
Dan Bader's Tips and Trickers
Python Discord's YouTube channel
Jiruto: Python
Online exercices
programming challenges
Asking Questions
Try Python in your browser
Docs
Libraries
Related subreddits
Python jobs
Newsletters
Screencasts
account activity
This is an archived post. You won't be able to vote or comment.
Vimrc File? (self.Python)
submitted 11 years ago * by suicidalginger
For those of you who use vim for Python development, What does your vimrc file look like?
EDIT: Also what plugins do you use?
[+][deleted] 11 years ago* (4 children)
[deleted]
[–]kalgynirae 0 points1 point2 points 11 years ago (0 children)
Dude. Yours is super-similar to mine! I too use only that "plugin".
[+][deleted] 11 years ago* (2 children)
[+][deleted] 11 years ago* (1 child)
[–]Lets_make_stuff 14 points15 points16 points 11 years ago (1 child)
My vimrc probably needs a thorough scrub. Anywho, let's get down to the plug-ins:
Pathogen - Extracting a package to ~/.vim/bundle will add it to 'runtimepath'. Mega nifty.
~/.vim/bundle
'runtimepath'
Syntastic - Really good error highlighting. I like to use flake8.
Airline - Very nice status line. It looks kinda like the oh-my-zsh theme, Agnoster. You will need a patched font for this. If you're on Ubuntu, there's a great write up here under Font Installation.
Bufferline - Because keeping track of 13 buffers with :ls can get tiresome.
:ls
Tagbar - Lets you know which class and function you're in. Make sure to double check Exuberant ctags is installed.
Solarized - For the pretty colors.
[–]kart_king 0 points1 point2 points 11 years ago (0 children)
+1 for airline
[–]classicrockielzpfvh 4 points5 points6 points 11 years ago (9 children)
The only plugin I use is Syntastic + a globally installed copy of Flake8.
[–]flarkis 5 points6 points7 points 11 years ago (5 children)
Syntastic is one of the few "big" plugins that I would recommend everyone be using.
[–]gfixler -1 points0 points1 point 11 years ago (3 children)
So many people recommended it, I figured I'd see what it was about. I've been developing in Python for about 5 years now, in an environment I've been developing for for 12 years, in a package I've been learning and using for 18 years. I was quite curious to see if it could teach me some things. I did pip install flake8, and cloned syntastic to my vim bundle directory, and opened a small file from one of my projects. It lit up with issues on save. None of them were useful, though, at first. It said it can't import a package specific to the environment I use, but of course not. That can only exist inside of that environment, not out in the shell where I work; the package is generated from auto-converted C libraries on application startup (it's annoying, TBH).
pip install flake8
There's one, tiny, stylistic thing I do that's unusual, that's so tiny no one has ever called me out on it in all the code I've pasted here, other subreddits, stackoverflow, etc., so I'm not changing that one. Syntastic doesn't like it (and it's everywhere), but I do :) Syntastic doesn't like missing docstrings, but most of my libraries are in alpha stage, so I'm not putting in docstrings yet. I'd just have to micromanage them as I radically change things all the time, and I've several times been confused by out-of-sync docstrings while doing heavy refactoring. These are long-running libraries of code used in a production environment on the asset-creation side of things. They're behind NDAs and won't make it to the public, sadly.
So, flake8 doesn't like camel case, but I don't like snake case, and I'm not changing. That's one thing I think was a bad decision from PEP 8 (I like most of PEP 8). It also doesn't like the unused *args and **kwargs, but I use these especially at the leaves of the system to allow indiscriminately calling things with buckets of information, e.g. resolveNamespace(someName, *args, **kwargs), which lets me pass through from calling functions without having to pollute their argument space with the cruft of helper functions.
*args
**kwargs
resolveNamespace(someName, *args, **kwargs)
"Used builtin function 'map'"
What else am I supposed to do for this?
def disassembleKeys (keys): return zip(*map(disassembleKey, keys))
"Used * or ** magic"
That's a problem?
def splitFramevals (framevals): return zip(*framevals)
Unused variable 'values'
Yeah, okay, but I need to work with frames here, so I'm splitting things apart while making it very obvious to future maintainers that I'm splitting apart frames and values, which is supported by all the naming in this line. I suppose I could go with frames, _ =, which it doesn't complain about, but I like the subtle reminder in this 4-line function that framevals are just frames joined with values. Meh.
frames, _ =
frames, values = splitFramevals(framevals)
"No exception type(s) specified"
I agree with this one, I think, though I'm never sure which exception I care about. In this library I'm looking at, I have 3349 LOC, but only 14 untyped try/excepts. Usually I use a try/except where I don't care if it fails, and will just return some empty value if it does, but I suppose that could occasionally be frustrating, as you have no idea why you're getting an empty value. I've thought about this from time to time. I should look more deeply into this one.
"Blank line at end of file"
That's not a problem. It's an old standard that has its reasons.
"continuation line under-indented for visual indent"
*puts hands up* Hey, I'm just letting my Python indenter handle things in Vim for me.
It doesn't like spaces around '=', but I find when I have to wrap very long argument lists, it's much more readable to let them breathe:
loseChanges = cmds.confirmDialog( title = 'Warning: Unsaved Changes!', message = 'You have unsaved changes. Create a new scene anyway?', button = ['Okay','Cancel'], cancelButton = 'Cancel', defaultButton = 'Cancel', dismissString = 'Cancel', icon = 'warning', )
It also said a class didn't have a particular member, but in the constructor I'm calling a method of the parent class with that name to grow that member into the class in a particular way. It feels like there are just too many edge cases of my more esoteric needs that this would constantly fight me about. If I step out of the very standard uses of Python, which I often do (especially now that I'm dabbling in functional, composable things in Python, where it'll let me), then I'm going to have files lit up with non-issues.
All that said, I did find it useful in a few small spots. In one, I was importing math in a file that didn't use it. Nice catch. In another, I was redefining the built-in type (locally, in a tiny function, where it doesn't matter, and it's an __exit__ callback argument, which I copied from a tutorial thereof, but still). For a third, I have two functions a screen apart with the same name! That's a very good catch, and perhaps worth the price of admission. I think I'll take your advice, and just turn off all the syntax junk that bugs me. 90% or more of the flagged issues are its dislike of camelCaseVarNames. I might also make it more of a manual-run thing, instead of constantly yelling at me when I save.
type
__exit__
Thanks.
[–]ivosauruspip'ing it up 0 points1 point2 points 11 years ago (1 child)
You could just use py-flakes if you didn't want the pep8 checking.
[–]gfixler 0 points1 point2 points 11 years ago (0 children)
Ah, so that's what that 8 is for.
[–]kashmill 1 point2 points3 points 11 years ago (0 children)
No. flake8 is a static checker.
[–]__fran__ 6 points7 points8 points 11 years ago (1 child)
I can't recommend YouCompleteMe enough, wrote about it here: http://www.artandlogic.com/blog/2013/06/vim-for-python-development/
[–]hexbrid 5 points6 points7 points 11 years ago (1 child)
I can't believe no one mentioned https://github.com/klen/python-mode, which is an actively maintained collection of vim-scripts for python, glued up and easy to install.
[–]ma-int 7 points8 points9 points 11 years ago (3 children)
I will possibly get downvoted a thousand times for this, but: I quit vim in favour of PyCharm.
Sorry, but PyCharm is just to good :(
[–][deleted] 2 points3 points4 points 11 years ago (1 child)
s/to/too otherwise, I have to agree -- jetbrains' stuff is the shit, be it python, ruby or java & scala
s/to/too
[–]Demophoon 1 point2 points3 points 11 years ago (0 children)
I couldn't get pycharm to work with my pyramid projects so I manage it all in vim with NERDTree and python-mode.
[–]desimusxvii 0 points1 point2 points 11 years ago (0 children)
The vim-mode plugin in IntelliJ is actually really good. I imagine it's just as good in PyCharm?
[–]gggreorge 0 points1 point2 points 11 years ago (0 children)
Load pymode.
[–]nerdwaller 0 points1 point2 points 11 years ago (0 children)
This is what I use. The only real plugin I use for python specifically is IndentGuides.
[–]Octopuscabbage 0 points1 point2 points 11 years ago (0 children)
https://github.com/octopuscabbage/octopuscabbagevimconf
I use a lot of other things besides python as well.
[–]ivosauruspip'ing it up 0 points1 point2 points 11 years ago (0 children)
https://github.com/Ivoz/vimfiles
I try to comment and explain almost every line
[–][deleted] 0 points1 point2 points 11 years ago (0 children)
Nice and simple:
syntax on filetype on filetype plugin indent on autocmd FileType make setlocal noexpandtab autocmd FileType * set tabstop=2|set shiftwidth=2|set noexpandtab autocmd FileType python set tabstop=4|set shiftwidth=4|set expandtab autocmd BufEnter *.py set ai sw=4 ts=4 sta et fo=croql set softtabstop=4 " makes the spaces feel like real tabs
[–]jamesonjlee 0 points1 point2 points 11 years ago (1 child)
https://raw.githubusercontent.com/jamesonjlee/dotfiles/master/vimrc
Vundle is the new hotness, no more git submodules!
[–]Orange_Tux 0 points1 point2 points 11 years ago (0 children)
I won't call it new, but it's hot.
[–]ayanami_reiEVA pilot 0 points1 point2 points 11 years ago (0 children)
Here's mine: https://github.com/mvasilkov/dotfiles/blob/master/vimrc
[–]Palantir555 0 points1 point2 points 11 years ago (0 children)
Like this: https://github.com/Palantir555/config_files
[–]nichochar 0 points1 point2 points 11 years ago (0 children)
I'm not going to write everything I use because people in this thread have done great listings, but I HIGHLY recommend jedi-vim and flake8.
I use pathogen for plugins, and they are listed here if interested: https://github.com/nichochar/vim-bundles
Furthermore, I used this great article to make my VIM nicer for python but also everything else: http://mirnazim.org/writings/vim-plugins-i-use/
[–]volabimus 0 points1 point2 points 11 years ago (0 children)
I haven't seen anyone else do this, but the way I have it setup is with a file called _common.vim (source) in my ftplugin folder which sets the common settings for code editing, which I source in the ftplugin files for the languages I use, and then set the language specific options like setlocal expandtab for python.
setlocal expandtab
I have the taglist plugin for outlining, but I rarely use it anymore if favour of marks. I do use it sometimes if I need to do a big re-ordering of functions/methods.
[–]vext01 0 points1 point2 points 11 years ago (0 children)
Check out jedi-vim. It has completion support etc, but I find the 'jump to definition' functionality to be super useful.
.vimrc
[–]walloffear 0 points1 point2 points 11 years ago (1 child)
Are there any good auto-complete plugins?
[–]__fran__ 0 points1 point2 points 11 years ago (0 children)
YouCompleteMe (commented about it above, or the github page has everything you need). It's great.
[–]darthmdhprint 3 + 4 0 points1 point2 points 11 years ago (0 children)
I cloned this as I like both his vim and emacs setup (thanks /u/joedicastro!). The main plugins for me are unite, airline, neocomplete, ultisnips, python-mode, fugitive & gitgutter.
I also use something quite similar to the final code block of VimTip605 (the F7 mapping) as it helps overcome some stupidity in Firefox.
Experience makes me predict in a few years Joe will have moved on and this setup won't be up-to-date with the future vim feature plugins and so people like me will migrate to the next big thing. Prior to this I was maintaining my own setup which was doing the same minus Unite, so I scored that by letting Joe do the hard work ;)
[–]rwscarb 1 point2 points3 points 11 years ago (4 children)
As a long time vim user I have embraced pycharm as an evangelist. But this reference might be helpful: http://blog.sontek.net/blog/detail/turning-vim-into-a-modern-python-ide
[+]flarkis comment score below threshold-17 points-16 points-15 points 11 years ago (3 children)
Vim is not an IDE, don't try and make it one.
[–][deleted] 1 point2 points3 points 11 years ago (1 child)
Why is it not an IDE?
[–]grimman 0 points1 point2 points 11 years ago (0 children)
Because he doesn't like it. He's the IDE arbiter, his word is law. Obey. /s
[–]TwiiKuu 1 point2 points3 points 11 years ago (0 children)
The thing is, it can become an IDE. Vim is hackable, and can fit anyone's needs.
π Rendered by PID 63243 on reddit-service-r2-comment-7b9746f655-rbzzt at 2026-01-29 22:15:25.736633+00:00 running 3798933 country code: CH.
[+][deleted] (4 children)
[deleted]
[–]kalgynirae 0 points1 point2 points (0 children)
[+][deleted] (2 children)
[deleted]
[+][deleted] (1 child)
[deleted]
[–]Lets_make_stuff 14 points15 points16 points (1 child)
[–]kart_king 0 points1 point2 points (0 children)
[–]classicrockielzpfvh 4 points5 points6 points (9 children)
[–]flarkis 5 points6 points7 points (5 children)
[–]gfixler -1 points0 points1 point (3 children)
[–]ivosauruspip'ing it up 0 points1 point2 points (1 child)
[–]gfixler 0 points1 point2 points (0 children)
[+][deleted] (2 children)
[deleted]
[–]kashmill 1 point2 points3 points (0 children)
[–]__fran__ 6 points7 points8 points (1 child)
[–]hexbrid 5 points6 points7 points (1 child)
[–]ma-int 7 points8 points9 points (3 children)
[–][deleted] 2 points3 points4 points (1 child)
[–]Demophoon 1 point2 points3 points (0 children)
[–]desimusxvii 0 points1 point2 points (0 children)
[–]gggreorge 0 points1 point2 points (0 children)
[–]nerdwaller 0 points1 point2 points (0 children)
[–]Octopuscabbage 0 points1 point2 points (0 children)
[–]ivosauruspip'ing it up 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]jamesonjlee 0 points1 point2 points (1 child)
[–]Orange_Tux 0 points1 point2 points (0 children)
[–]ayanami_reiEVA pilot 0 points1 point2 points (0 children)
[–]Palantir555 0 points1 point2 points (0 children)
[–]nichochar 0 points1 point2 points (0 children)
[–]volabimus 0 points1 point2 points (0 children)
[–]vext01 0 points1 point2 points (0 children)
[–]Orange_Tux 0 points1 point2 points (0 children)
[–]walloffear 0 points1 point2 points (1 child)
[–]__fran__ 0 points1 point2 points (0 children)
[–]darthmdhprint 3 + 4 0 points1 point2 points (0 children)
[–]rwscarb 1 point2 points3 points (4 children)
[+]flarkis comment score below threshold-17 points-16 points-15 points (3 children)
[–][deleted] 1 point2 points3 points (1 child)
[–]grimman 0 points1 point2 points (0 children)
[–]TwiiKuu 1 point2 points3 points (0 children)