前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >[来稿]pycharm快捷键、tips、常用设置及版本控制 制

[来稿]pycharm快捷键、tips、常用设置及版本控制 制

作者头像
小小科
发布2018-05-03 11:41:18
1.8K0
发布2018-05-03 11:41:18
举报
文章被收录于专栏:北京马哥教育

在PyCharm安装目录 /opt/pycharm-3.4.1/help目录下可以找到ReferenceCard.pdf快捷键英文版说明 or 打开pycharm > help > default keymap ref

PyCharm3.0默认快捷键(翻译的)PyCharm Default Keymap

1、编辑(Editing)

Ctrl + Space 基本的代码完成(类、方法、属性) Ctrl + Alt + Space 快速导入任意类 Ctrl + Shift + Enter 语句完成 Ctrl + P 参数信息(在方法中调用参数) Ctrl + Q 快速查看文档

Shift + F1 外部文档

Ctrl + Shift + Z --> Redo 重做

Ctrl + 鼠标 简介 Ctrl + F1 显示错误描述或警告信息 Alt + Insert 自动生成代码 Ctrl + O 重新方法 Ctrl + Alt + T 选中 Ctrl + / 行注释 Ctrl + Shift + / 块注释 Ctrl + W 选中增加的代码块 Ctrl + Shift + W 回到之前状态 Ctrl + Shift + ]/[ 选定代码块结束、开始 Alt + Enter 快速修正 Ctrl + Alt + L 代码格式化 Ctrl + Alt + O 优化导入 Ctrl + Alt + I 自动缩进 Tab / Shift + Tab 缩进、不缩进当前行 Ctrl+X/Shift+Delete 剪切当前行或选定的代码块到剪贴板 Ctrl+C/Ctrl+Insert 复制当前行或选定的代码块到剪贴板 Ctrl+V/Shift+Insert 从剪贴板粘贴 Ctrl + Shift + V 从最近的缓冲区粘贴 Ctrl + D 复制选定的区域或行 Ctrl + Y 删除选定的行 Ctrl + Shift + J 添加智能线 Ctrl + Enter 智能线切割 Shift + Enter 另起一行 Ctrl + Shift + U 在选定的区域或代码块间切换 Ctrl + Delete 删除到字符结束 Ctrl + Backspace 删除到字符开始 Ctrl + Numpad+/- 展开/折叠代码块(当前位置的:函数,注释等) Ctrl + shift + Numpad+/- 展开/折叠所有代码块 Ctrl + F4 关闭运行的选项卡 2、查找/替换(Search/Replace) F3 下一个 Shift + F3 前一个 Ctrl + R 替换 Ctrl + Shift + F 全局查找 Ctrl + Shift + R 全局替换 3、运行(Running) Alt + Shift + F10 运行模式配置 Alt + Shift + F9 调试模式配置 Shift + F10 运行 Shift + F9 调试 Ctrl + Shift + F10 运行编辑器配置 Ctrl + Alt + R 运行manage.py任务 4、调试(Debugging) F8 跳过 F7 进入 Shift + F8 退出 Alt + F9 运行游标 Alt + F8 验证表达式 Ctrl + Alt + F8 快速验证表达式 F9 恢复程序 Ctrl + F8 断点开关 Ctrl + Shift + F8 查看断点 5、导航(Navigation) Ctrl + N 跳转到类 Ctrl + Shift + N 跳转到符号 Alt + Right/Left 跳转到下一个、前一个编辑的选项卡 F12 回到先前的工具窗口 Esc 从工具窗口回到编辑窗口 Shift + Esc 隐藏运行的、最近运行的窗口 Ctrl + Shift + F4 关闭主动运行的选项卡 Ctrl + G 查看当前行号、字符号 Ctrl + E 当前文件弹出 Ctrl+Alt+Left/Right 后退、前进 Ctrl+Shift+Backspace 导航到最近编辑区域 Alt + F1 查找当前文件或标识 Ctrl+B / Ctrl+Click 跳转到声明 Ctrl + Alt + B 跳转到实现 Ctrl + Shift + I查看快速定义 Ctrl + Shift + B跳转到类型声明 Ctrl + U跳转到父方法、父类 Alt + Up/Down跳转到上一个、下一个方法 Ctrl + ]/[跳转到代码块结束、开始 Ctrl + F12弹出文件结构 Ctrl + H类型层次结构 Ctrl + Shift + H方法层次结构 Ctrl + Alt + H调用层次结构 F2 / Shift + F2下一条、前一条高亮的错误 F4 / Ctrl + Enter编辑资源、查看资源 Alt + Home显示导航条F11书签开关 Ctrl + Shift + F11书签助记开关 Ctrl + #[0-9]跳转到标识的书签 Shift + F11显示书签 6、搜索相关(Usage Search) Alt + F7/Ctrl + F7文件中查询用法 Ctrl + Shift + F7文件中用法高亮显示 Ctrl + Alt + F7显示用法 7、重构(Refactoring) F5复制F6剪切 Alt + Delete安全删除 Shift + F6重命名 Ctrl + F6更改签名 Ctrl + Alt + N内联 Ctrl + Alt + M提取方法 Ctrl + Alt + V提取属性 Ctrl + Alt + F提取字段 Ctrl + Alt + C提取常量 Ctrl + Alt + P提取参数 8、控制VCS/Local History Ctrl + K提交项目 Ctrl + T更新项目 Alt + Shift + C查看最近的变化 Alt + BackQuote(’)VCS快速弹出 9、模版(Live Templates) Ctrl + Alt + J当前行使用模版 Ctrl +J插入模版 10、基本(General) Alt + #[0-9]打开相应的工具窗口 Ctrl + Alt + Y同步 Ctrl + Shift + F12最大化编辑开关 Alt + Shift + F添加到最喜欢 Alt + Shift + I根据配置检查当前文件 Ctrl + BackQuote(’)快速切换当前计划 Ctrl + Alt + S 打开设置页 Ctrl + Shift + A查找编辑器里所有的动作

Ctrl + Tab在窗口间进行切换

pycharm常用设置:

file -> Setting ->Editor

1. 设置Python自动引入包,要先在 >general > autoimport -> python :show popup

快捷键:Alt + Enter: 自动添加包

2. “代码自动完成”时间延时设置

> Code Completion -> Auto code completion in (ms):0 -> Autopopup in (ms):500

3. Pycharm中默认是不能用Ctrl+滚轮改变字体大小的,可以在〉Mouse中设置

4. 显示“行号”与“空白字符”

> Appearance -> 勾选“Show line numbers”、“Show whitespaces”、“Show method separators”

5. 设置编辑器“颜色与字体”主题

> Colors & Fonts -> Scheme name -> 选择"monokai"“Darcula”

说明:先选择“monokai”,再“Save As”为"monokai-pipi",因为默认的主题是“只读的”,一些字体大小颜色什么的都不能修改,拷贝一份后方可修改!

修改字体大小

> Colors & Fonts -> Font -> Size -> 设置为“14”

6. 设置缩进符为制表符“Tab”

File -> Default Settings -> Code Style

-> General -> 勾选“Use tab character”

-> Python -> 勾选“Use tab character”

-> 其他的语言代码同理设置

7. 去掉默认折叠

> Code Folding -> Collapse by default -> 全部去掉勾选

8. pycharm默认是自动保存的,习惯自己按ctrl + s 的可以进行如下设置: > General -> Synchronization -> Save files on frame deactivation 和 Save files automatically if application is idle for .. sec 的勾去掉

> Editor Tabs -> Mark modified tabs with asterisk 打上勾

9.>file and code template>python scripts

#!/usr/bin/env python # -*- coding: utf-8 -*- """ __title__ = "$Package_name" __author__ = "$USER" __mtime__ = "$DATE" # code is far away from bugs with the god animal protecting I love animals. They taste delicious. ┏┓ ┏┓ ┏┛┻━━━┛┻┓ ┃ ☃ ┃ ┃ ┳┛ ┗┳ ┃ ┃ ┻ ┃ ┗━┓ ┏━┛ ┃ ┗━━━┓ ┃ 神兽保佑 ┣┓ ┃ 永无BUG! ┏┛ ┗┓┓┏━┳┓┏┛ ┃┫┫ ┃┫┫ ┗┻┛ ┗┻┛ """

10 python文件默认编码

File Encodings> IDE Encoding: UTF-8;Project Encoding: UTF-8;

File -> Settings -> appearance

1. 修改IDE快捷键方案

> Keymap

1) execute selection in console : add keymap > ctrl + enter

系统自带了好几种快捷键方案,下拉框中有如“defaul”,“Visual Studio”,在查找Bug时非常有用,“NetBeans 6.5”,“Default for GNOME”等等可选项,

因为“Eclipse”方案比较大众,个人用的也比较多,最终选择了“Eclipse”。

还是有几个常用的快捷键跟Eclipse不一样,为了能修改,还得先对Eclipse方案拷贝一份:

(1).代码提示功能,默认是【Ctrl+空格】,现改为跟Eclipse一样,即【Alt+/】

Main menu -> code -> Completion -> Basic -> 设置为“Alt+/”

Main menu -> code -> Completion -> SmartType -> 设置为“Alt+Shift+/”

不过“Alt+/”默认又被

Main menu -> code -> Completion -> Basic -> Cyclic Expand Word 占用,先把它删除再说吧(单击右键删除)!

(2).关闭当前文档,默认是【Ctrl+F4】,现改为跟Eclipse一样,即【Ctrl+W】

Main menu -> Window -> Active Tool Window -> Close Active Tab -> 设置为 “Ctrl+F4”;

Main menu -> Window -> Editor -> Close -> 设置为 “Ctrl+W”;

2.设置IDE皮肤主题

> Theme -> 选择“Alloy.IDEA Theme”

或者在setting中搜索theme可以改变主题,所有配色统一改变

File > settings > build.excution

1 console > pyconsole

代码语言:javascript
复制
sys
# print("Python %s on %s" % (sys.version, sys.platform))
sys.path.extend([WORKING_DIR_AND_PYTHON_PATHS])
os
(, os.getcwd() )
numpy np
scipy sp
matplotlib

File > settings > Project : initial project

project dependencies > LDA > project depends on these projects > 选择sim_cluster就可以在LDA中调用sim_cluster中的包

[Configure PyCharm]

Pycharm实用功能:

[PyCharm中的那些实用功能]

pycharm中配置python脚本和console执行路径和当前工作目录

1 ctrl + shift + f10 / f10 执行python脚本

当前工作目录cwd为run/debug configurations 中的working directory

可在edit configurations > project or defaults中配置

2 python console中执行时

cwd为File > settings > build.excution > console > pyconsole中的working directory

并可在其中配置

pycharm版本控制

[不了解git版本控制的可以阅读这篇 - Git版本控制教程 - Git本地仓库]

Enabling version control开启版本控制

Click >clickVersion Control. By default, the only root is<project>, and it is not mapped to any version control system.

  • First, click . In the Add VCS Directory Mapping dialog, click the ellipsis(省略) button, and choose thedirectory you want to put under version control. From the VCS drop-down list, select a version control system you are going to use (in our example, let it be Git):

By the way, if you have several directories, you can map each of them to its own version control system, or leave some of them unversioned.

Note:

1. 如果python workspace已经在git版本控制下了,点击version control就会看到Directory下有提示unregistered roots:project_name,点击这个project,再点击+号就添加到版本控制中了。

2. 新建的包都最好先通过这种方式加入到git版本控制下,再进行下面的操作。

  • Next, apply your new version control settings, and close the Settings dialog.设置git:将git添加到pycharm版本管理中来:settings > version control > git > path to git excutable > D:Gitingit.exe 选择git.exe的安装路径就可以了。

How does it affect PyCharm"s appearance?上述操作完成后pycharm界面的变化

Something has changed. PyCharm now looks differently...Let"s explore the changes in PyCharm"s UI.

  • You see the new color code of the file Solver.py. Now it is brown, which means that the file exists, but is not yet added to the version control.
  • Changes tool window appears - you see its button along the lower border of PyCharm. Click this button to open the tool window, and see the list of unversioned files. Later we"ll see what to do with them.
  • The VCS menu, and the VCS operations pop-up now show more commands. In particular, you see the commands that allow checking your changes in therepository(贮藏室), and updating the entire project. These commands aredenoted(表示) with the icons and respectively.
  • Same icons appear on the main toolbar.
  • A Git node appeared on the VCS menu, and on the context menus of the Project tool window and the editor. Have we selected a different version control system to associate with a directory, this node would be different (Perforce, CVS, etc.). This node contains VCS-specific commands.
  • In the Status bar, you see the Git widget - this is a Git-specific modification(修改).

Putting a file under version control将某个文件加入到版本控制中(default中)(相当于git中添加到repository中的暂存区stage)

1. 在changes窗口中添加:

Look at the list of unversioned files in the Changes tool window:

Select Solver.py, and pressCtrl+Alt+Ato add this file to version control: you see that the color code of the file changed - now it is green, which means that the file is added to version control, but not yet committed to therepository(贮藏室). The file moved to the new changelist with the name Default.

2. 在左侧的project中添加:

指定某个文件夹(包、项目) 1. 右键 > git > + / Add 或者 2. ctrl + alt + a

Note: 1. 要将已添加到git版本管理中的文件删除(不是删除文件,只是不添加到repository中的暂存区stage): changes窗口 > default > 1. 右键文件 > revert 或者 2.ctrl + alt +z 2. 删除本地文件后:若添加到repository中的文件已push到远程,删除本地文件后,changes窗口会出现刚刚删除的改动,要push到远程才能将远程的文件也删除了。如果不push或者commit,那么删除的文件总在default文件list中,待commit状态。 3. 删除本地文件后:可以通过changes窗口中的ctrl+alt+z撤销修改(删除)

将文件提交到repository中(相当于git中提交到repository中的master) Now press Ctrl+K(or click button in the Changes tool window) to commit your changes:

Next, enter your check-in comment(相当于git中的git commit -m "comment"中的comment参数), and finally click theCommit button:

OK, the changes are checked in. The Default changelist is now empty, and the color code of the file nameSolver.py changed again - it becameblack, which means that there are nopending(在…期间) changes.

Note:

1. 上图中如果选择commit改为选择commit and push就可以在commit同时将代码提交到远程仓库github中。远程仓库设置见下面 pycharm版本远程控制 部分。注意push到哪个分支,在git中修改过当前分支可能反映到pycharm中也是那个分支。

2. 将修改过的files push的另一种方法: 在当前文件中 > 右键 > Git > Repository > push > 选择push的位置/分支

Files under .idea directory

There are more unversioned files left. If you click the button in the Changes tool window, you will see that all these filesreside(住) in the directory.idea under the project root. However, we don"t see this directory under the project root in the Project tool window.

The files under this directory are the settings files of your project.It is recommended to place all of them, except one, under version control. So, do it as described in the previous section.

Ignoring files要忽略的文件,不添加到版本控制中

This only file that should be ignored, stores your workspace preferences; its name isworkspace.xml. The fileworkspace.xml is ignored by default. Open theIgnored Files page of the Settings dialog (→Version Control→Ignored Files), and see the list of files ignored by version control by default:(相当于git中的.gitignore文件的作用)

If you want more files to be ignored by your version control system, click , and then enter specific file name, or a mask, or a directory name. Refer to the pageConfiguring Ignored Files for details.

Note:

1. 在changes窗口中也可以confige ignored files{同上面提到的“Ignoring files要忽略的文件,不添加到版本控制中”} / show ignored files

2. 在changes窗口 > unversioned files > 选择要ignore的文件 > 右键 > ignore也可以忽略文件

Viewing changes in the editor在编辑器中查看变化

Let"s edit the source code: for example, rename a variable, remove a line, add a line. All the changes are marked in the left gutter:

Click a line with a change - a pop-up window with a toolbar appears:修改代码后windows左边会出现一个pop-up,可以随时返回到修改前的状态。

As you see, this toolbar helps doing many useful things: navigate between changes, view differences, roll the changes back, and put the previous version toclipboard(剪贴板).

Refer to the page Using Change Markers to View and Navigate Through Changes in the Editor for details.

By the way, the color code of the file name changed again - it became blue, which means that there arepending(未决定的) changes not yet committed to yourrepository(贮藏室). Since you already know how to commit changes, do it now - and see that the change markers in the left guttervanished(消失).文件提交到repository中的master之后,左边的pop-up就消失了。

Getting up-to-date information from the repository从repository中获得最新的信息

Suppose somebody else is working on the same project. Now you want to get the external changes locally.

PyCharm, as usual, provides several ways to do it:

  • Press Ctrl+T
  • Click on the main toolbar
  • Choose VCS→Update Project...

The action per se is VCS-agnostic. However, the dialog box that shows up when youinvoke(调用) updating, is VCS-dependent. It will be different, for example, forGit update and forPerforce update - compare the dialog descriptions.

[pycarm中给某个文件的父目录创建新的repository、创建新分支]

pycharm版本远程控制

[不了解git远程版本控制的可以参考这篇 -Git版本控制教程 - Git远程仓库]

Two ways to share source code分享原代码的两种方法

To publish your source code, you need write access to a remote storage, for example, to theGitHub storage.

To initiate publishing, open the project described in the tutorial"Using PyCharm"s Git integration locally" if it is closed. Your further actions depend on the selected strategy, since PyCharm provides two ways of sharing your source code.

Note that all actions are performed with the current branch.

Sharing on GitHub在github上分享代码

On the main menu, choose VCS→Import into Version Control→Share project on GitHub:

If you have your GitHub account properly configured, you will see the dialog box, where you have tospecify the repository name and optional description:

Click Share - and behold your source code in a brand new remote repository.

commit到本地repository中

changes窗口 > local > 向上箭头标志commit changes.

Pushing your source code将代码push到github远程仓库中

Press Alt+` to show the VCS operations pop-up window, and then press8 to invoke thePushcommand:

选择要push的project, 然后在弹出的窗口中输入github账户名和密码

亲测成功,登录github查看文件,文件都更新了。ps:本地文件原来在a目录并提交到github上,后来本地移动到b目录后,再提交到远程,github上的文件也会移动到b中,很好用!

In the Git Push dialog box, you have to select specific revision to push. Note, however, that when doing the very first push of a branch, you have to select the check box below:

After pushing changes, PyCharm shows an information message in the balloon:

Again, if you go to your repository and choose the desired branch, you will see your source code successfully committed.

选择和合并分支

选择:菜单栏 > VCS > Git > Branches > 选择当前分支

合并:菜单栏 > VCS > Git > Merge changes > 选择要和当前分支合并的分支

根据上面讲到的本地Getting up-to-date information from the repository从repository中获得最新的信息

  • Press Ctrl+T
  • Click

on the main toolbar

  • Choose VCS→Update Project...

可以进行Pushing your source code将代码push到github远程仓库中反操作,就是将github上的项目update到本地中(可以是不同电脑)。表示没有在B电脑上输入github用户和密码就能进行这个操作,可能是pycharm登录的账户名相同吧??如果两个人使用同一个pycharm账户会怎样?

[PyCharm Tutorials]

在pycharm上打开github上的项目

pycharm > 所有project空白界面上 > 右键 > open on github就可以直接在浏览器中打开github上对应的项目了

pycharm简单数据库管理

[使用pycharm进行简单的数据库管理]

from:http://blog.csdn.net/pipisorry/article/details/39909057

ref:pycharm的一些设置和快捷键

pycharm 2.7 快捷键

pycharm Learning tips学习技巧

/pythoncharm/help/tip of the day: A special variant of the Code Completion feature invoked by pressing Ctrl+Space twice allows you to complete the name of any class no matter if it was imported in the current file or not. If the class is not imported yet, the import statement is generated automatically. You can quickly find all places where a particular class, method or variable is used in the whole project by positioning the caret at the symbol"s name or at its usage in code and pressing Alt+Shift+F7 (Find Usages in the popup menu). To navigate to the declaration of a class, method or variable used somewhere in the code, position the caret at the usage and press F12. You can also click the mouse on usages with the Ctrl key pressed to jump to declarations. You can easily rename your local variables with automatic correction of all places where they are used. To try it, place the caret at the variable you want to rename, and press Shift+F6 (Refactor | Rename). Type the new name in the popup window that appears, or select one of the suggested names, and press Enter.

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2015-04-20,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 马哥Linux运维 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • [不了解git版本控制的可以阅读这篇 - Git版本控制教程 - Git本地仓库]
  • How does it affect PyCharm"s appearance?上述操作完成后pycharm界面的变化
  • Files under .idea directory
  • Ignoring files要忽略的文件,不添加到版本控制中
  • Viewing changes in the editor在编辑器中查看变化
  • Getting up-to-date information from the repository从repository中获得最新的信息
  • Two ways to share source code分享原代码的两种方法
    • Pushing your source code将代码push到github远程仓库中
    • 根据上面讲到的本地Getting up-to-date information from the repository从repository中获得最新的信息
    相关产品与服务
    数据库智能管家 DBbrain
    数据库智能管家(TencentDB for DBbrain,DBbrain)是腾讯云推出的一款为用户提供数据库性能、安全、管理等功能的数据库自治云服务。DBbrain 利用机器学习、大数据手段、专家经验引擎快速复制资深数据库管理员的成熟经验,将大量传统人工的数据库运维工作智能化,服务于云上和云下企业,有效保障数据库服务的安全、稳定及高效运行。
    领券
    问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档