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.
...
在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
importsys# print('Python %s on %s' % (sys.version, sys.platform))sys.path.extend([WORKING_DIR_AND_PYTHON_PATHS])importosprint('current workdirectory : ', os.getcwd() )importnumpyasnpimportscipyasspimportmatplotlibasmpl
File > settings > Project : initial project
project dependencies > LDA > project depends on these projects > 選擇sim_cluster就可以在LDA中調用sim_cluster中的包
Pycharm實用功能:
pycharm中配置python腳本和console執行路徑和當前工作目錄
1 ctrl + shift + f10 / f10 執行python腳本時
當前工作目錄cwd為run/debug configurations 中的working directory
可在edit configurations > project or defaults中配置
2python console中執行時
cwd為File > settings > build.excution > console > pyconsole中的working directory
并可在其中配置
http://blog.csdn.net/pipisorry/article/details/39909057
pycharm中進行python包管理
pycharm中的項目中可以包含package、目錄(目錄名可以有空格)、等等
目錄的某個包中的某個py文件要調用另一個py文件中的函數,首先要將目錄設置為source root,這樣才能從包中至上至上正確引入函數,否則怎么引入都出錯:
SystemError: Parent module '' not loaded, cannot perform relative import
Note:目錄 > 右鍵 > make directory as > source root
from:http://blog.csdn.net/pipisorry/article/details/39909057
ref:pycharm的一些設置和快捷鍵