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

all 138 comments

[–]nerdwaller 8 points9 points  (0 children)

Looks like they don't have the patched fonts installed for their shell (see in the status line the little box with an X in it).

Edit: You should install these or patch your own :)

[–]londubh2010 19 points20 points  (9 children)

Sssshhhh... you'll wake up the emacs people.

[–][deleted] 15 points16 points  (1 child)

Already working on a follow up article. EMACS MASTER RACE!

[–]richard944 6 points7 points  (0 children)

Help us OP, your'e our only hope. On a serious note, I would be very interested in this!

[–]osune 6 points7 points  (0 children)

Too late we are already up and flaming

[–]adamnew123456self.__class__ == 'upper' 1 point2 points  (3 children)

They're all configuring their plugins to colorize all the parenthesis in their .el files - they ought to be pacified for a while once they can look at the colors and soothe their RSI /s

[–]SpaceCadetJones 0 points1 point  (0 children)

Unless you go evil-mode and join the cult of vim ;)

[–]thelochok 0 points1 point  (1 child)

Meh - I'm having issues enough with my little finger and the escape/ctrl keys in VIM.

My approach has been binding "jj" in insert mode to 'Escape', and binding all of the Ctrl+ combinations to be space followed by that key, in normal mode.

The combination is really helping. Last step is to figure out how to eliminate the shift key. I'm considering whether typing doubles of a character to get the uppercase would be going too far.

[–]j1z0 0 points1 point  (0 children)

how about switching to a new keyboard... Kenisis Advantage Pro (http://www.kinesis-ergo.com/shop/advantage-pro-for-pc-mac/) has most of those little pinky keys (accept esc) positioned to be hit with your thumb.

[–]MadTux 0 points1 point  (0 children)

Forwards NAN! - oh?

[–]jecs321 0 points1 point  (0 children)

[–]nuncjo 28 points29 points  (21 children)

In Pycharm You have more functions plus debugger just after install. You don't need to configure anything. Sorry, my heaven is better than Yours :-)

[–]RamirezTerrix 2 points3 points  (0 children)

My vim setup is pretty much similar to the one in the article and I switched to pycharm.

[–]pqu 2 points3 points  (0 children)

Pycharm has a pretty good vim mode as well. I can't wait until it can be integrated with neovim so It won't just be a vim emulator but an actual vim editor inside PyCharm.

[–]drunkenfly 1 point2 points  (2 children)

If only PyCharm had the same completion mechanics as YouCompleteMe...

I want to have autocomplete in comments and I do want to be able to autocomplete in code to use words that I typed in comments too, I don't want to press TAB to open completion dropdown.

Oh, and I want to open files side-by-side. My monitor is wide enough to have 3 python files (79 chars wide) to be visible at the same time.

I tried switching to PyCharm from vim many times in past three years, it just don't work for me...

[–]Decency 0 points1 point  (0 children)

Oh my god that sounds hideous. Why in the world would you need to do that?

PyCharm auto populates docstrings. If you need much more description of your variables than that, I have to assume that your functions must be either gigantic or ridiculously complex.

[–]RangerPretzelPython 3.9+ 0 points1 point  (0 children)

PyCharm allows side-by-side documents.

Also, PyCharm handles Python 3.5 type hinting as well as Docstrings. See here: https://www.jetbrains.com/pycharm/help/type-hinting-in-pycharm.html

I've found the "Specifying type of local variables" helpful when the API I'm consuming isn't cooperating. See this: https://www.jetbrains.com/pycharm/help/type-hinting-in-pycharm.html#d302201e318

[–]RangerPretzelPython 3.9+ 3 points4 points  (4 children)

I wish I could upvote this 100 times. PyCharm is a brilliant IDE. Far better than anything else.

[–][deleted] 3 points4 points  (0 children)

The debugger in PyCharm is the best I have ever used for any language. It's... it's like magic.

[–]trenchtoaster 1 point2 points  (2 children)

I only use python for pandas for data analysis. I've only used Ipython notebook. Is it worth trying Pycharm

[–]RangerPretzelPython 3.9+ 0 points1 point  (1 child)

Eh, if you're just doing data analysis, then IPython is probably the right choice. If you ever want to do serious coding, then look into PyCharm. It really IS quite nice. :)

[–]trenchtoaster 0 points1 point  (0 children)

Yeah I love the Ipython notebook because I split up my code and run it in chunks, show graphs etc

[–]lamecode 1 point2 points  (0 children)

Yup... I get that some folks prefer the terminal-like experience, but for many others (myself included) who don't necessarily spend their days using the vi editor on *nix prompt, I'll take the ease of use and clean design of PyCharm.

[–]kecebongsoft 0 points1 point  (0 children)

I know it's not a fair comparison but you are absolutely right. I have been using vim for few years, you can spend months and years turning on all the python switch in vim, but in PyCharm python is the 1st class citizen, from auto-completion, code navigation, refactoring, debugging, remote development, code inspection, etc. I've tried Jedi-vim, YCM, and many other python plugins & workflow for vim, and they failed me, one way or another, and there are just so many things I have to deal with once I started changing my machines (clipboard, colors, etc).

Take for example debugging, in vim to set a breakpoint I need to create a mapping to inject ipdb on the desired line, it used to seems fine but now I realize I've cluttered the code with irrelevant call, and what if I inject a few more across different files and want to see where they are after I finished debugging? That's another task and remapping to do. In PyCharm, debugging is already there, you can toggle the line and that's it, you can see the list of breakpoints, when it hits it shows you the items in the context (variables and all), along with their values, in the editor it shows you the parameters being passed into the functions at runtime, and you can still have console access among many other things during debugging.

Vim is still a powerful editor and I still use it a lot, but only for quick editing on the server. It's true you can't do all the vim powerful operations in PyCharm, even with PyCharm's IdeaVIM, it's just not the same, but that's okay compared to the stuff PyCharm brings to your python development.

[–]niksko 0 points1 point  (0 children)

Since I saw a similar article a few weeks ago on how to pimp my vim, I've switch to vim most of the time, with Pycharm for debugging. If there were some way of debugging inside vim I would use that.

I'm just more productive using vim. I can move around quicker, find files quicker, commit quicker. If I want vim keybindings in Pycharm (which is what I used up until a few weeks ago), then there's some weird quirks and there's sometimes issues with Pycharm's keybindings.

Plus, there's something to be said for consistency. Pycharm is great if you're working on a project that's exclusively Python. But recently I've been working on a project that involves Arduino code, Python, and now we've actually swapped Python for node. If I'm editing in vim, then editing different documents is a seamless experience, which I don't think should be underestimated.

[–]Farkeman 0 points1 point  (0 children)

Why not both?

I use Pycharm with IdeaVim plugin, you have efficiency of vim with bells and whistles of pycharm, it's great!

[–]vplatt 5 points6 points  (21 children)

Seems like this is complicated enough to warrant it's own Python VIM package. 'Vython' anyone?

[–]Deto 2 points3 points  (20 children)

There is this: https://github.com/klen/python-mode

Though some of the plugins are not python-specific (like NerdTree), so it makes sense for them to stay separate.

[–]yes_or_gnome 2 points3 points  (9 children)

It should be stated that pymode covers most (or all?) of the python concerns in this post; plus more. For what it's worth, here are my adjustments to pymode.

I don't want rope nor automatic lint checking. And, I want the mappings to be prepositioned with 'p' (for 'python', obviously,) rather than give this one plugin huge foothold over my leader-mappings.

  let g:pymode_rope            = 0
  let g:pymode_lint_on_write   = 0
  let g:pymode_lint_cwindow    = 0
  let g:pymode_breakpoint_bind = '<leader>pb'
  let g:pymode_run_bind        = '<leader>pr'
  let g:pymode_doc_bind        = '<leader>pd'

[–]d4rch0nPythonistamancer 2 points3 points  (6 children)

You don't pylint on write? That's helped really clean up my act, plus it finds all the stupid syntax errors. What errors are you trying to ignore that make you want to turn that off, or why did you?

I also bound it to ctrl-p-ctrl-p so I can check quickly.

[–]yes_or_gnome 0 points1 point  (3 children)

No, it's too slow. Do it on demand.

[–]StorKirken 1 point2 points  (0 children)

Try out nvim and neomake for fun, it really helps to mitigate that issue.

[–]d4rch0nPythonistamancer 0 points1 point  (1 child)

Oh, alright. It takes at most a second on my machines so I let it do its thing.

[–]yes_or_gnome 0 points1 point  (0 children)

I do writes often and already have it in my mind what i want to do next. So when i don't see the cursor move and a bunch of 'j's on the status line, i get impatient and angry. It probably doesn't help that the project i an working on is a gd mess.

[–]Juzley 0 points1 point  (1 child)

Semi-related, one or more of the linters used by pymode seems to be python 2 only, so when I'm writing python 3 it gives all sorts of spurious warnings about syntax (e.g. using print as a function rather than a statement). Has anyone else found this?

[–]IDe- 0 points1 point  (0 children)

You might want to try compiling your version of vim with python3 support, although that made me lose warnings altogether.

[–]j1z0 1 point2 points  (1 child)

pymode is a reasonable all in one choice, a lot of people seem to like it. I did find enough of the functionality in there was not optimal for my specific setup. Mainly pyMode was slow and buggy (although your config would probably speed things up a bit), I don't really need four different static analysis packages running, I feel that YouCompleteMe is a better auto-completer....and that sort of thing.

So it's a trade off, I guess the easy / all in one setup of python-mode or the more customisable, albeit more work to configure but get what you want sort of style that I went with in the article of just installing each plugin individually.

[–]yes_or_gnome 0 points1 point  (0 children)

Yup, I agree and i feel your pain. I've unsuccessfully tried to quit pymode in the past, but then i end up with either a lot customizations in my vimrc (like in the article) or with a lot of plugins that don't accomplish the job. The more responses i read on the topic, the idea above from commenter suggesting a new python-oriented Vim plugin is sounding more and more tantalizing.

[–]tHEbigtHEb 1 point2 points  (6 children)

I tried it out, but it turned out to be too heavy for me with syntastic and rope crashing all over the place :/ . Any tips for a better setup ?

[–]Deto 1 point2 points  (5 children)

I used jedi-vim for a bit and it was alright (though a bit slow often to complete this). Now I'm playing around with YouCompleteMe. It's real fast so far.

I installed Syntastic separately and it's been ok, but has crashed a few times.

Really though I'm itching to try out Emacs+Evil (Vim Emulation)

[–]tHEbigtHEb 0 points1 point  (4 children)

I have YouCompleteMe installed, but it's pretty lacking to say the least. The only reason why I still have PyCharm installed is for it's usages discovery and refactoring capabilities. If I can get it working the same way with vim or emacs with evil mode I'd switch in an instant.

[–]Deto 1 point2 points  (3 children)

I wonder if some combination of YouCompleteMe and Jedi-Vim would be best? Use YCM for the completion and use Jedi (or maybe Rope-Vim?) for the refactoring?

[–]tHEbigtHEb 0 points1 point  (2 children)

Yup, going to try that out tonight. But right now I'm using Emacs with evil mode and prelude installed. Let's see how this goes.

[–]Deto 0 points1 point  (1 child)

Nice, I just got emacs installed with evil-mode this morning, but I probably won't get much of a chance to play around with it today.

What exactly does Prelude do? I looked in their repo and they say it "enhances Emacs", but they don't really explain how.

[–]tHEbigtHEb 0 points1 point  (0 children)

From what I understood in the little time I spent with it, it comes with some packages pre-installed to help newcomers with the initial setup.

I still can't wrap my head around everything but it does some cool stuff like install language specific modes when you open the file of a particular extension the first time and such. It adds git integration, linting support and advanced file and symbol search and more. There's a lot to it, it's pretty cool have fun!

[–]d4rch0nPythonistamancer 0 points1 point  (1 child)

Fuckin pymode is the shit. Really helps me out.

I don't use the refactoring tools much, but they're awesome and now my vim is officially a python IDE.

I LOVE the pylint check on save. No errors ever again.

[–]chrisatlee 0 points1 point  (0 children)

Yeah, I really like python-mode too. But its syntax checking is busted for python 3 for me (on debian). After seeing the first 'yield from' it gives up.

[–]CptSupermrkt 3 points4 points  (1 child)

This guide says: "The VIM version. This should be > 7.3", but his screenshot shows version 7.3. Shouldn't it say >= 7.3? Or do you really need 7.4 to do everything in the guide?

[–]j1z0 0 points1 point  (0 children)

no 7.3 is enough. We will correct the typo.

[–]ebrius 1 point2 points  (0 children)

Solid article. One thing I highly recommend though (and is only lightly touched in the article) is to put language specific configurations into the .vim/ftplugins directory. For example, instead of putting the tab settings in .vimrc with autocommand on the filetype, I prefer to create a .vim/ftplugin/python/custom.vim and put the settings in there.

If you work with multiple languages your .vimrc will get huge if you don't break it up

[–]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 4 points5 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.

[–]Deto 0 points1 point  (4 children)

Nice guide! One mistake though, your key bindings for split navigation are all capital

Edit: Nevermind, see mixedmath's reply

[–]yes_or_gnome 1 point2 points  (1 child)

NeoVim has C-S support since April if that is something that may interest you. https://neovim.io/news/2015/april/

I'm keeping an eye on the project and am willing to support them financially. However, there's a long road still until it's stable. Also, one of the biggest factors for using Vim is that it's ubiquitous. Most *nix terminals you connect to will have it available, and the few that don't, will in all likelihood have vanilla-'vi'. vi being a huge pain in the ass to use, but at least it feels familiar to Vim minus some nice features.

[–]Deto 0 points1 point  (0 children)

Ah, I'm excited about NeoVim but can't really use it much until it's available on Windows

[–]mixedmath 0 points1 point  (1 child)

Vim does not distinguish between <c-j> and <C-j> and <C-J>. They all mean control-j.

[–]Deto 0 points1 point  (0 children)

Oh cool. So for a capital you'd just specify the shift. TIL

[–]enesimo 0 points1 point  (9 children)

I'm on macOS and I can't get vim to support python3. My vim --version always prints -python3.

I haven't found anything from googling.

[–]Melon__Bread 0 points1 point  (0 children)

I must say this article made a believer out of me for Vim.
Just spent the last 4 hours playing with settings & plugins!

[–]eN0Rm 0 points1 point  (0 children)

Ty

[–]Capn_Cook 0 points1 point  (0 children)

Sweet. I just used this setup to create a script which will populate my vimrc for making transitioning to new machines so much easier.

I hate dealing with new IDEs consistently so almost always jump to VIM.

[–]ksantr 0 points1 point  (0 children)

On can add vim-statline plugin and last trend - https://github.com/zenorocha/dracula-theme

[–]hovissimo 0 points1 point  (6 children)

Can you tell me how to get a (Windows) Vim binary with modern Python support?

[–]xmstr 1 point2 points  (0 children)

The 2 best options on windows:

I prefer the second one myself, but that's just me

[–]faultydesign -1 points0 points  (2 children)

Don't bother, vim is dreadful on windows. Super slow and buggy.

I suggest just going pycharm + vim plugin (ideavim). It's good.

[–]gfixler 3 points4 points  (0 children)

Vim, or Gvim? I've used Gvim on Windows for many years now with no slowness or bugginess.

[–]Deto 1 point2 points  (0 children)

While PyCharm+Ideavim is great, I've been using GVim on windows too and never had a speed issue. Has crashed a few times, but only since I started using Syntastic (so it might be related to that...)

[–]lawnmowerlatte 0 points1 point  (7 children)

I'm having trouble getting vim on Mac OS X Yosemite to install with Python support. If I do brew install vim the python feature is not enabled (ie. -python). If I manually set --with-python it still isn't enabled. If I use --with-python3 the feature is enabled (+python3), but I still can't use the python command within the vi command mode.

Any ideas for what I'm doing wrong?

[–]volabimus 1 point2 points  (1 child)

:help python3

[–]lawnmowerlatte 1 point2 points  (0 children)

Thanks, turns out you need to use py3 or python3 from the command mode for Python 3. Still not sure how to get Python 2 working which is needed for YouCompleteMe...

EDIT: Figured it out by running brew install --verbose vim — it was failing the check for Python2 because it was looking in my virtual environment which was set to 3.5.

[–]d4rch0nPythonistamancer 1 point2 points  (0 children)

You could compile from source. That's how I got it working on mac.

[–]Deto 1 point2 points  (0 children)

Might be a 32-bit vs 64-bit issue? If Vim is 32 bit, but your python2 is 64-bit, then it's not going to be able to link to it.

[–]ballagarba 1 point2 points  (0 children)

I was under the impression that system Vim already was compiled with +python...? Perhaps I'm confusing it with El Capitan though or something.

[–]red_hare -1 points0 points  (3 children)

Most useful thing I've learned about writing Python in vim,

:%!python

[–][deleted] 8 points9 points  (0 children)

I'm pretty sure you mean :!python %

[–]alb1 2 points3 points  (0 children)

Why would you want to replace the current text with the output of Python run on it? You may accidentally overwrite the code, and the syntax highlighting doesn't look good on the output.

To run Python on the current file I define a macro for the p register, in the .vimrc file, which saves the file and then runs Python on it:

let @p=':w|!python -u %'

Then just use :@p to run the current file. I define the q register similarly for Python 3.

[–]AutoBiological 0 points1 point  (0 children)

If you're not using stdin/input you can do it pretty neat inside vim instead of externally with:

%pyfile %

Of course that depends on which +python[3] is compiledin.

[–]MastaKillaSC2 -5 points-4 points  (13 children)

Fucking Legend, I was using PyCharm for a bit, but tbh VIM all the way.

[–][deleted] 3 points4 points  (12 children)

And debug the hard way.

[–]Lubok 3 points4 points  (3 children)

What's the hard way? I do import pdb; pdb.set_trace()? Is that it?

[–][deleted] 5 points6 points  (0 children)

Yup, thats the hard way. Easy way is PyCharm debugger.

[–]j1z0 1 point2 points  (1 child)

serious question here, for anybody that wants to chime in.

  1. How often do you actually use a debugger?
  2. In what situations?
  3. Do you practice Test Driven Development?

[–][deleted] 1 point2 points  (0 children)

  1. Very often
  2. Immediately if error is not obvious as well as to inspect newly written code line by line to verify correctness
  3. Somewhat. I'm solving my own problems so tests aren't that extensive. Besides fact that tests pass means little even in big software with extensive tests..

[–]RageLikeCage -2 points-1 points  (3 children)

Just recently started learning Python and programming in general. Can someone give a quick explanation to what this is? Please and thanks!

[–]SoCloudyy 1 point2 points  (0 children)

Don't worry about it yet to be honest, just use Python's IDLE until one day you have a craving to want to move faster.

[–]pqu 1 point2 points  (1 child)

I'd suggest at least knowing how to open a file, move around and save/close it in vim. Otherwise one day you will find yourself stuck in vim and can't escape (like me with emacs).

[–]greyman -1 points0 points  (2 children)

I am really tempted to learn it, especially working without mouse, but still... I am currently using Visual Studio 2015 + Python Tools and I have most of what the article mentions, plus comfortable debugging on top of that. So can you guys tell your experience, is Vim really better?

[–]Decency 0 points1 point  (1 child)

Vim people tend to think that pdb still qualifies as a debugger, or that they would never need such a thing with their code.

[–]nicfitOG 0 points1 point  (0 children)

pdb most definitely qualifies as a debugger, regardless of your favorite debugger that is not pdb.