pycharm Learning tips學習技巧html
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.python
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.app
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字體
一、編輯(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 關閉運行的選項卡
二、查找/替換(Search/Replace)
F3 下一個
Shift + F3 前一個
Ctrl + R 替換
Ctrl + Shift + F 全局查找
Ctrl + Shift + R 全局替換
三、運行(Running)
Alt + Shift + F10 運行模式配置
Alt + Shift + F9 調試模式配置
Shift + F10 運行
Shift + F9 調試
Ctrl + Shift + F10 運行編輯器配置
Ctrl + Alt + R 運行manage.py任務
四、調試(Debugging)
F8 跳過
F7 進入
Shift + F8 退出
Alt + F9 運行遊標
Alt + F8 驗證表達式
Ctrl + Alt + F8 快速驗證表達式
F9 恢復程序
Ctrl + F8 斷點開關
Ctrl + Shift + F8 查看斷點
五、導航(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顯示書籤
六、搜索相關(Usage Search)
Alt + F7/Ctrl + F7文件中查詢用法
Ctrl + Shift + F7文件中用法高亮顯示
Ctrl + Alt + F7顯示用法
七、重構(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提取參數
八、控制VCS/Local History
Ctrl + K提交項目
Ctrl + T更新項目
Alt + Shift + C查看最近的變化
Alt + BackQuote(’)VCS快速彈出
九、模版(Live Templates)
Ctrl + Alt + J當前行使用模版
Ctrl +J插入模版
十、基本(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