天天看點

pycharm 快捷鍵pycharm快捷鍵、常用設定、配置管理 pycharm學習技巧 Learning tipsPyCharm3.0預設快捷鍵(翻譯的)pycharm常用設定pycharm環境和路徑配置Pycharm實用拓展功能

pycharm快捷鍵、常用設定、配置管理

标簽: pycharm快捷鍵版本控制資料庫管理包管理 2014-10-08 23:47 147463人閱讀 評論(2) 收藏 舉報

pycharm 快捷鍵pycharm快捷鍵、常用設定、配置管理 pycharm學習技巧 Learning tipsPyCharm3.0預設快捷鍵(翻譯的)pycharm常用設定pycharm環境和路徑配置Pycharm實用拓展功能

分類: Python(41)

pycharm 快捷鍵pycharm快捷鍵、常用設定、配置管理 pycharm學習技巧 Learning tipsPyCharm3.0預設快捷鍵(翻譯的)pycharm常用設定pycharm環境和路徑配置Pycharm實用拓展功能
pycharm 快捷鍵pycharm快捷鍵、常用設定、配置管理 pycharm學習技巧 Learning tipsPyCharm3.0預設快捷鍵(翻譯的)pycharm常用設定pycharm環境和路徑配置Pycharm實用拓展功能

作者同類文章 X

版權聲明:本文為部落客皮皮http://blog.csdn.net/pipisorry原創文章,未經部落客允許不得轉載。

目錄(?)[+]

  1. pycharm學習技巧 Learning tips
  2. PyCharm30預設快捷鍵翻譯的
  3. pycharm常用設定
  4. pycharm環境和路徑配置
    1. python解釋器路徑
      1. python項目解釋器路徑
      2. pycharm中進行python包管理
      3. python腳本解釋路徑
      4. console執行路徑和目前工作目錄
    2. pycharm配置osenviron環境
      1. pycharm配置第三方庫代碼自動提示
  5. Pycharm實用拓展功能
    1. pycharm中清除已編譯pyc中間檔案
    2. pycharm設定外部工具
      1. 将上面的删除代碼改成外部工具
      2. 之後可以通過下面的方式直接執行
      3. 代碼品質
      4. python2轉python3最快方式
      5. 其它

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

本部落格一直在同步更新中!

内容包含:pycharm學習技巧 Learning tips、PyCharm3.0預設快捷鍵(翻譯的)、pycharm常用設定、pycharm環境和路徑配置、Pycharm實用拓展功能:pycharm中清除已編譯.pyc中間檔案、python2轉python3最快方式

[pycharm版本控制和資料庫管理][PyCharm中的那些實用功能]

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.

...

切換

Use Alt+Up and Alt+Down keys to quickly move between methods in the editor.

Use Ctrl+Shift+F7 (Edit | Find | Highlight Usages in File) to quickly highlight usages of some variable in the current file.

選擇

You can easily make column selection by dragging your mouse pointer while keeping the Alt key pressed.

補全

Working in the interactive consoles, you don't need to memorise the command line syntax or available functions. Instead, you can use the familiar code completion Ctrl+Space. Moreover, from within the lookup list, you can press Ctrl+Q to view the item's documentation.

顯示

Use F3 and Shift+F3 keys to navigate through highlighted usages.

Press Escape to remove highlighting.

曆史

Ctrl+Shift+Backspace (Navigate | Last Edit Location) brings you back to the last place where you made changes in the code.

Pressing Ctrl+Shift+Backspace a few times moves you deeper into your changes history.

Ctrl+E (View | Recent Files) brings a popup list of the recently visited files. Choose the desired file and press Enter to open it.

Use Alt+Shift+C to quickly review your recent changes to the project.

剪切闆

Use the Ctrl+Shift+V shortcut to choose and insert recent clipboard contents into the text.

If nothing is selected in the editor, and you press Ctrl+C, then the whole line at caret is copied to the clipboard.

run/debug

By pressing Alt+Shift+F10 you can access the Run/Debug dropdown on the main toolbar, without the need to use your mouse.

在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    快速檢視文檔

F1   外部文檔

Shift + F1    外部文檔,進入web文檔首頁

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  或者連續2次敲擊shift   全局查找{可以在整個項目中查找某個字元串什麼的,如查找某個函數名字元串看之前是怎麼使用這個函數的}

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    跳轉到下一個、前一個編輯的頁籤(代碼檔案)

Alt + Up/Down跳轉到上一個、下一個方法

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跳轉到父方法、父類

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 2.7 快捷鍵]

皮皮Blog

pycharm常用設定

lz提示一下,pycharm中的設定是可以導入和導出的,file>export settings可以儲存目前pycharm中的設定為jar檔案,重裝時可以直接import settings>jar檔案,就不用重複配置了。

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;

11. 代碼自動整理設定

pycharm 快捷鍵pycharm快捷鍵、常用設定、配置管理 pycharm學習技巧 Learning tipsPyCharm3.0預設快捷鍵(翻譯的)pycharm常用設定pycharm環境和路徑配置Pycharm實用拓展功能

這裡line breaks去掉√,否則bar, 和baz會分開在不同行,不好看。

皮皮Blog

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

每次打開python控制台時自動執行代碼

> console > pyconsole

import sys
# print('Python %s on %s' % (sys.version, sys.platform))
sys.path.extend([WORKING_DIR_AND_PYTHON_PATHS])
import  os
print('current workdirectory : ', os.getcwd() )
import  numpy as  np
import  scipy as sp
import  matplotlib as mpl      

如果安裝了ipython,則在pyconsole中使用更強大的ipython

> console

選中use ipython if available

這樣每次打開pyconsole就會打開ipython

Note: 在virtualenv中安裝ipython: (ubuntu_env) pika:/media/pika/files/mine/python_workspace/ubuntu_env$pip install ipython

File > settings > Languages & Frameworks

如果在項目設定中開啟了django支援,打開python console時會自動變成打開django console,當然如果不想這樣就關閉項目對django的支援:

pycharm 快捷鍵pycharm快捷鍵、常用設定、配置管理 pycharm學習技巧 Learning tipsPyCharm3.0預設快捷鍵(翻譯的)pycharm常用設定pycharm環境和路徑配置Pycharm實用拓展功能

如果打開支援就會在 settings > build.excution > console下多顯示一個django console:

pycharm 快捷鍵pycharm快捷鍵、常用設定、配置管理 pycharm學習技巧 Learning tipsPyCharm3.0預設快捷鍵(翻譯的)pycharm常用設定pycharm環境和路徑配置Pycharm實用拓展功能

Django console設定如下

import sys
print('Python %s on %s' % (sys.version, sys.platform))
import django
print('Django %s' % django.get_version())
sys.path.extend([WORKING_DIR_AND_PYTHON_PATHS])
if 'setup' in dir(django): django.setup()
import django_manage_shell; django_manage_shell.run(PROJECT_ROOT)      

File > settings > Project : initial project

project dependencies > LDA > project depends on these projects > 選擇sim_cluster就可以在LDA中調用sim_cluster中的包

[Configure PyCharm]

皮皮Blog

pycharm環境和路徑配置

python解釋器路徑

python項目解釋器路徑

用于配置python項目執行的python路徑

比如,有的項目是運作的是系統python2.7下的環境;有的是3.4;有的項目使用的是virtualenv的python環境[python虛拟環境配置 - pycharm中的項目配置]

在pycharm > file > settings > project:pythonworkspace > project interpreter > 選擇對應項目 > project interpreter中指定python解釋器

pycharm中運作configuration有一個選項add content roots to pythonpath

選中後sys.path中會多一整個項目project的路徑/media/pika/files/mine/python_workspace,裡面的目錄就被當成包使用,這樣就可以通過from SocialNetworks.SocialNetworks引入不是python包的目錄中的檔案了。

不過最好使用sys.path.append(os.path.join(os.path.split(os.path.realpath(__file__))[0],"../.."))來添加,這樣在pycharm外也可以運作不出錯 。

[python子產品導入及屬性:import ]

pycharm中進行python包管理

pycharm中的項目中可以包含package、目錄(目錄名可以有空格)、等等

目錄的某個包中的某個py檔案要調用另一個py檔案中的函數,首先要将目錄設定為source root,這樣才能從包中至上至上正确引入函數,否則怎麼引入都出錯:

SystemError: Parent module '' not loaded, cannot perform relative import

Note:目錄 > 右鍵 > make directory as > source root

python腳本解釋路徑

ctrl + shift + f10 / f10 執行python腳本時

目前工作目錄cwd為run/debug configurations 中的working directory

可在edit configurations > project or defaults中配置

console執行路徑和目前工作目錄

python console中執行時

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

并可在其中配置

pycharm配置os.environ環境

pycharm中os.environ不能讀取到terminal中的系統環境變量

pycharm中os.environ不能讀取.bashrc參數

使用pycharm,無論在python console還是在module中使用os.environ傳回的dict中都沒有~/.bashrc中的設定的變量,但是有/etc/profile中的變量配置。然而在terminal中使用python,os.environ卻可以擷取~/.bashrc的内容。

解決方法1:

在~/.bashrc中設定的系統環境隻能在terminal shell下運作spark程式才有效,因為.bashrc is only read for interactive shells.

如果要在目前使用者整個系統中都有效(包括pycharm等等IDE),就應該将系統環境變量設定在~/.profile檔案中。如果是設定所有使用者整個系統,修改/etc/profile或者/etc/environment吧。

如SPARK_HOME的設定[Spark:相關錯誤總結 ]

解決方法2:在代碼中設定,這樣不管環境有沒有問題了

# spark environment settings
import sys, os
os.environ['SPARK_HOME'] = conf.get(SECTION, 'SPARK_HOME')
sys.path.append(os.path.join(conf.get(SECTION, 'SPARK_HOME'), 'python'))
os.environ["PYSPARK_PYTHON"] = conf.get(SECTION, 'PYSPARK_PYTHON')
os.environ['SPARK_LOCAL_IP'] = conf.get(SECTION, 'SPARK_LOCAL_IP')
os.environ['JAVA_HOME'] = conf.get(SECTION, 'JAVA_HOME')
os.environ['PYTHONPATH'] = '$SPARK_HOME/python/lib/py4j-0.10.3-src.zip:$PYTHONPATH'      

pycharm配置第三方庫代碼自動提示

參考[Spark安裝和配置]

皮皮Blog

Pycharm實用拓展功能

pycharm中清除已編譯.pyc中間檔案

選中你的workspace > 右鍵 > clean python compiled files

還可以自己寫一個清除代碼

pycharm設定外部工具

[python小工具 ]針對目前pycharm中打開的py檔案對應的目錄删除其中所有的pyc檔案。如果是直接運作(而不是在下面的tools中運作),則删除E:\mine\python_workspace\WebSite目錄下的pyc檔案。

将上面的删除代碼改成外部工具

PyCharm > settings > tools > external tools > +添加

Name: DelPyc

program: $PyInterpreterDirectory$/python Python安裝路徑

Parameters: $ProjectFileDir$/Oth/Utility/DelPyc.py $FileDir$

Work directory: $FileDir$

Note:Parameters後面的 $FileDir$參數是說,DelPyc是針對目前pycharm中打開的py檔案對應的目錄删除其中所有的pyc檔案。

之後可以通過下面的方式直接執行

pycharm 快捷鍵pycharm快捷鍵、常用設定、配置管理 pycharm學習技巧 Learning tipsPyCharm3.0預設快捷鍵(翻譯的)pycharm常用設定pycharm環境和路徑配置Pycharm實用拓展功能

Note:再添加一個Tools名為DelPycIn

program: Python安裝路徑,e.g.     D:\python3.4.2\python.exe

Parameters: E:\mine\python_workspace\Utility\DelPyc.py

Work directory 使用變量 $FileDir$

參數中沒有$FileDir$,這樣就可以直接删除常用目錄r'E:\mine\python_workspace\WebSite'了,兩個一起用更友善

代碼品質

當你在打字的時候,PyCharm會檢查你的代碼是否符合PEP8。它會讓你知道,你是否有太多的空格或空行等等。如果你願意,你可以配置PyCharm運作pylint作為外部工具。

python2轉python3最快方式

/usr/bin/2to3 -wn $FileDir$

pycharm 快捷鍵pycharm快捷鍵、常用設定、配置管理 pycharm學習技巧 Learning tipsPyCharm3.0預設快捷鍵(翻譯的)pycharm常用設定pycharm環境和路徑配置Pycharm實用拓展功能

這樣在pycharm中打開某個檔案,右鍵external tools > py2topy3就可以瞬間将目前檔案所在目錄下的所有py2轉換成py3,是不是很機智!

[python2和python3的差別、轉換及共存 使用 2to3 工具對代碼進行檢查和轉換]

其它

[pycharm版本控制和資料庫管理]

[PyCharm中的那些實用功能]

[使用Pycharm打造高效Python IDE (下)]

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

ref:pycharm的一些設定和快捷鍵

33
2
  • 上一篇linux和windows下安裝python拓展包及requirement.txt安裝類庫
  • 下一篇python虛拟環境安裝和配置

  相關文章推薦

  • • pycharm快捷鍵及一些常用設定
  • • 【免費】搜狗機器翻譯技術分享
  • • 最全Pycharm教程(2)——代碼風格
  • • 深度學習在推薦領域的應用和實踐--吳岸城
  • • 整體代碼縮進
  • • Git和Github快速上手指南
  • • 最全Pycharm教程(9)——建立并運作一個基本的Python測試程式
  • • JFinal專題之模闆引擎知識集錦
  • • 最全Pycharm教程(8)——Django工程的建立和管理
  • • Spring Cloud 微服務實戰
  • • 最全Pycharm教程(5)——Python快捷鍵相關設定
  • • JDK9新特性解答
  • • Python實戰之KNN實作
  • • PyCharm使用技巧:Shift + Tab(向左縮進)
  • • 最全Pycharm教程(4)——有關Python解釋器的相關配置
  • • 最全Pycharm教程(3)——代碼的調試、運作