Good enough for a lifetime of efficient PyCharm tips

Starting from today PyCharm, write can significantly improve the development efficiency of the use of skills, once learned, good enough for a lifetime. The following code demonstrates the environment under Mac, Windows is similar, Command key is equivalent to the Control key on Windows.

1. Code typesetting, automatic PEP8

pep8 is a code written in the Python language specification. Should you are a novice, just want to quickly grasp the current basis, and do not want to go too much emphasis on the writing style code (although this is important), then you can try this tool - autopep8

First of all (do not install in a virtual environment) in the global environment, install about this tool.

sudo pip install autopep8

Then import this tool Pycharm years.

Name: AutoPep8

Description: autopep8 your code

Program: autopep8

Arguments: --in-place --aggressive --aggressive

Working directory:

Output filters: :::.*

13717038-56fff990f0adf654
image

I am free to write a piece of code that does not meet specifications pep8.

13717038-4504f20f84df547e
image

Right click and select External Tools -> AutoPep8

13717038-57afa1de6c8e8fad
image

Look at the results, it is still quite obvious.

13717038-37b99912f453bd01
image

You might say, Pycharm itself comes with this feature Yeah, shortcut Command + Option + L, you can achieve a key pep8 up. You can compare, Pycharm own code pep8 capabilities did not come like this autopep8 completely. I believe your final choice is definitely the latter.

2. accidentally deleted files, one second back

Last week, because of their misuse, without any backup case, wrote a two-week project to delete. After I came back to God, I can not remember even when the delete operation is performed.

As an old driver, of course, it is the courage to open the Recycle Bin, search for some months not cleaned up the trash, really a mess, what jpg, avi have, unsightly ah.

我用一分钟快速浏览了一下,没有发现我要找的那几个 py 文件,我心想,应该是文件太多了,看叉掉了。由于项目是最近写的,文件名我还清楚地记得,既然有文件名,那就利用windows 自带的搜索功能,结果还是没有,这下我才开始意识到事态的严重性,文件可能真的「没了」。

我已经很久没有清理过回收站了,为什么回收站里会没有我的文件呢?

我想这可能是一次非同寻常的 delete,会不会是在 Pycharm 里的 发起删除操作,不会往回收站里丢呢?经过一番测试,在回收站还真的找不着,但是这次尝试也无意中发现了 Pycharm 的隐藏的一个功能 Local History,它会保存你对文件的所有操作记录。

就拿我的刚刚测试的文件来举例,我先是新建了一个文件,然后对在这个文件里添加了几行代码。最后我将这个文件删除了。

此时你可以在你的项目目录里,点击右键,有个 Local History 的选项,再点击子选项 Show History,你可以看到这里有个记录板。如果你想恢复删除的文件,就在删除的记录项点击右键,选择 Revert 即可恢复。

13717038-23a3116f121bd305
image

3. 拥抱Vim,远离鼠标

在大多数场景之下,使用鼠标的效率和精准度,是远不如键盘快捷键的(前提是你已经相当熟练的掌握了快捷键),这个你得承认吧。

Vi 可以满足你对文本操作的所有需求,比可视化界面更加效率,更加 geek。如果你和我一样,是忠实的 vim 粉。在安装完 Pycharm 完后,肯定会第一时间将 ideaVim这个插件也装上,它可以让我们在 Pycharm 中 使用 vim 来编辑代码。

安装方法如下,安装完后需要重启 Pycharm 生效。

13717038-4869d2cf4592f315
image

4. 代码模板,效率编码

Pycharm 提供的这个代码模板,可以说是相当实用的一个功能了。它可以在你新建一个文件时,按照你预设的模板给你生成一段内容,比如解释器路径,编码方法,作者详细信息等

13717038-53511f8f218d304a
image

按照上图模板,生成的效果如下。

In addition to the initialization file when creating a new document in the development of writing code, use Pycharm also comes with useful code templates to improve your coding efficiency.

When you type in the keyboard Command + J, it brings up a panel that can be seen from the figure there are a number of preset templates.

13717038-b6b04197474d2773
image

If we want to select the last main, can continue typing the main, then you can generate code that directly follows this usually have manually typed.

13717038-901fd3de6b100257
image

Here another example, for circulation can write.

13717038-130c922a94dfa677
image

5. Use bookmarks to quickly access

When I look at all the source code framework, the most commonly used Command + B (that is, command + left mouse button) layer by layer depth look inside, but when more source code, the entire event may a process involving 10 a few files, complex function calls for a huge project, it may be useful on several key functions every time you want to find these functions, we must re-head function from the source and then layer by layer to find it, so it too much trouble, therefore I often put myself to see faint.

It was only later I found Pycharm the bookmark function.

Use the bookmark function, I can be marked bookmarks in a critical position, we want to see, when to call a bookmark, you can quickly locate.

Use it, you need to remember a few shortcuts below under

Command + F11 marked bookmarks

Shift + F11 to show all bookmarks

F11 Delete bookmark (valid only been tested on Windows)

In the position you want to make bookmarks, press Command + F11, you can add a number to this position, can be a number can also be letters, plus 1 if this number in the following position, next time you can use Control + 1 jump directly to this location.

13717038-0f8a1e7feff7b756
image

Of course, you can not add, without words is anonymous bookmarks. You can use Shift + F11 to show all the bookmarks, and then jump.

This week's PyCharm efficient technique, which is five, and you learn it?

Reproduced in: https: //www.jianshu.com/p/c92dcbcb89b8

Guess you like

Origin blog.csdn.net/weixin_34223655/article/details/91310328