Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stop PyCharm's Autocomplete from Overwriting Code in front of my Cursor

I am using PyCharm to write some python code and notice that I run into the following problem quite often:

I write a line of code like this

for item in myList:

Later, I realize that I would like the index of item as well, so I try to turn that line into this:

for i,item in enumerate(myList):

In order to turn the first line into the second, I put the cursor to the left of item and type i,. Then, I put the cursor to the left of myList and type enu; by this time, the code-completer suggests that I might want to type enumerate, which is exactly the behavior that I'm after. When I hit tab to implement the suggested enumerate, I notice that my line turns into

for i,item in enumerate:

The myList has been overwritten!
The behavior that I expect is this:

for i,item in enumerate(myList):

with the cursor immediately to the right of either the myList or the :.

Is there any way that I could make Pycharm behave according to my expectations?

Just in case it matters, my dev environment is Mac OSX 10.7.5 (Lion)

like image 713
inspectorG4dget Avatar asked Oct 18 '13 19:10

inspectorG4dget


People also ask

How do I turn off auto completion in PyCharm?

You can disable certain postfix completion templates in the Editor | General | Postfix Completion page of the IDE settings Ctrl+Alt+S .

How do I get idle suggestions in Python?

In IDLE 1.2, you can use the key combination of 'CTRL' and 'space' to invoke the built-in auto-completion feature. (In Python Shell window, you can use TAB key besides the key combination of 'CTRL' and 'space' to invoke the built-in auto-completion feature.)

Why Autocomplete is not working in PyCharm?

You need to go into the project settings and configure the interpreter to point at the virtualenv. PyCharm will then index the interpreter and allow you to autocomplete. The virtualenv may be auto-detected in the dropdown menu on the left.


2 Answers

This behavior is by design when you complete using Tab. Please use Enter instead of Tab to insert the completion variant instead of overwriting.

Code completion settings dialog also has an option to insert variant by typing dot, space, etc.

like image 150
CrazyCoder Avatar answered Sep 28 '22 00:09

CrazyCoder


This is default behaviour in PyCharm, if you press TAB while being connected to another word like so en|myList, then myList will get deleted.

What you can do is this, double-click myList, press CRTL+ALT+T, press ENTER, and then press <-. Then just type in enumerate.

If you do this regularly, then you can just make a live template that surrounds.

like image 33
Games Brainiac Avatar answered Sep 27 '22 23:09

Games Brainiac