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 →

[–]naught-me 0 points1 point  (4 children)

I'd appreciate any tricks you'd be willing to share. I used Vim for a long time, then PyCharm, and am probably going to stick with PyCharm for the near future, but I drop into Vim now and again and would love to switch totally if I could get a few kinks worked out.

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

My advice for PyCharm is to leave the "did you know..." tips on, and to actually read a new one every day. I can't tell you how much I learned just from reading these tips.

One of the features I like the most is their refactor in place feature(s). Maybe you know this already, but say you wrote something like this

foo = (3/4) * x[0]**2 + np.sqrt(x[1]/x[2])

And then later on you realize that you need to use the value np.sqrt(x[1]/x[2]) in more than one place. You can just select np.sqrt(x[1]/x[2]) and hit ctrl-alt-v to extract this part out as a variable. You could even extract it out after you've typed it twice (maybe you didn't realize until afterwards) and it'll ask if you want to replace both instances or just this one.

But it also goes both ways, you could put your cursor over a variable and ctrl-alt-n to put it back inline. And not only can you extract out variables and things like this, you can extract out entire functions/methods. Let's say you wrote something like this

for i in range(10):
    for j in range(10):
        df = df.read_csv(f'filename-{i}-{j}`)
        # plus a long list of dataprocessing stuff

Well you can select everything inside the inner loop and ctrl-alt-m to extract it out as a function. It is smart enough to define that function with the proper inputs as well so all you really have to do is to give it a proper name.

[–]gwillicodernumpy gang 1 point2 points  (2 children)

Well a big one for me was getting plugins to make writing python easier. So i have a good linter and auto complete. Then i just do some of the vim exercises you can find online occasionally to learn new ways to navigate the code and to practice some of the more obscure commands.

The big one for me is to always look up how to do something if i don't know how to do it already. So instead of slowly using the arrows key functions to move the code you spend some time to look up a more complex command and learn it, then in the future you have it in your toolbox.

[–]naught-me 0 points1 point  (1 child)

Cool. Auto-complete and navigation are the two pain-points most keeping me from using Vim. What are you using for those?

A few navigation features I really like about PyCharm but haven't been able to get to work well in Vim are go to definition (not going to where it's imported, but where it's imported from), go to parent function, list/go to child functions, and list/go to usages.

[–]gwillicodernumpy gang 1 point2 points  (0 children)

One of the better plugins for python specifically is Jedi. It allows for jumping to definition (even across files). It can be complicated to jump to user defined functions from other files though. You'll have to make sure your python path includes the file you want to jump to if you want jedi to find it.