sublime text 配置python环境
之前一直用pycharm来写python,但是感觉启动太慢了,并且电脑配置不是很好,所以换成了sublime,但是如何打造一套适合自己的python环境呢,让我们用伟大的插件来实现吧。
首先要下载sublime text;
1.下载好了之后,安装package Control插件,安装方法参照:https://packagecontrol.io/installation
2.安装SublimeREPL插件
SublimeREPL支持各种语言解释器,方便我们在编辑器上编写完代码进行调试。
具体安装步骤如下:
Step1.Cmd+Shift+P调出快捷命令窗口,输入install,选择 Package Control:Install Package;
Step2.输入sublimerepl,点击选中,然后它就会在后台安装;
Step3.安装完之后,查看 Tools->SublimeREPL。若有这个菜单,则说明安装成功。
3.添加自定义快捷键
Step1.回到SublimeText3,点击菜单Preferences->Key Bindings,会弹出两个框,左边是Default(Windows).sublime-keymap —— Default,右边是Default(Windows).sublime-keymap —— User。
在右边输入即可:
{
"keys": ["f5"],
"caption": "SublimeREPL: Python - RUN current file",
"command": "run_existing_window_command",
"args":
{
"id": "repl_python_run",
"file": "config/Python/Main.sublime-menu"
}
}
这样,按下f5,就能直接运行当前*.py脚本了。运行结果如下图示。

设置python的代码分析工具
这个工具有以下功能:
- 分析语法错误
- 分析代码结构问题,如:使用没有定义的变量
- 分析不符合规范和美观的代码
所以当这个工具被很好的集成在Sublime中的时候,对自己写代码会有非常大帮助
下面通过把Flake8和Sublime集成起来,而Flake8是非常好的一个工具在python中
速度非常快,误报率低,用它来做代码分析检查是非常合适的
Flake8是一个需要独立安装的命令行工具
在安装Flake8之后,再为Sublimean安装SublimeLinter和SublimeLinter-flake8插件
Install Flake8
pip install flake8
安装完成之后通过flake8 --help可以看到如图所示:

如果后面需要升级这个插件只需要通过命令:
pip install --upgrade flake8
Install SublimeLinter
SublimeLinter是Sublime的代码框架,它可以集成Flake8这样的linter引擎来检查我们的代码,
并可以把它们的消息转换成Sublime Text然后把它们显示在我们代码旁边。
SublimeLinter 可以让Flake8和Sublime Text成为一个非常完美的搭档,可以直接在代码编辑器里看到Flake8的消息。
所以首先我们需要安装SublimeLinter,然后我们将安装连接Flake8和SublimeLinter的SublimeLinter-flake8
1.通过ctrl+shift+p 进入如下图,并输入 install Package,然后回车

初次会慢点,然后提示如下图:

输入我们要安装的:SublimeLinter,选择如图所示进行安装:

提示如下图所示表示安装完成

Install SublimeLinter-flake8
现在需要将SublimeLinter和Flake8集成连接起来,这里就通过SublimeLinter-flake8插件来完成
同样的,和上一个插件安装方法类似也是通过ctrl+shift+p 进入如下图,并输入Flake8


当出现如上图提示是表示安装完成,这个时候需要我们Sublime重启后生效,然后我们打开可以写一个py文件
写了一个打印hello,World,我们从右下角就可以看出

从上图的提示我们可以看出,我们的插件已经在起作用了,提示的错误是:在这个文件没有回车到新的一行
虽然现在已经生效了,但是为了让它更好用我们还需要对
SublimeLinter-flake8做一些简单的配置
配置SublimeLinter-flake8
先看一下当出现错误的时候的提示:

其实这种错误提示可能不是很友好,会在错误部分外面有个框,在其他IDE中可以能是在错误代码下有
红色下划线表示的,如果习惯了那种显示方式可以通过下面方法配置


看到如上图所示时,把左边的配置全部拷贝到右边的配置里并把开头的default更改为user
然后把配置中 "mark_style": "outline",更改为:"mark_style":“squiggly underline”
更改后的效果如下:

在配置中找到"lint_mode": "background"更改为:"lint_mode": "load/save"
代码自动补全功能
很多程序员选择IDE工具的时候都希望他的自动补全功能能好用点,而Sublime 一开始并没有非常好用的插件,直到出现了Anaconda插件
它提供了一下功能:
1. 代码的自动补全
2. 显示python类,方法或者函数的使用方法
3. 检查导入模块是否有效
4. 按照PEP8规范自动化格式我们的代码
5. 可以跳转到函数的定义或者类的定义
6. .....
Install the Anaconda Package
和上面安装讲的安装插件的方法一样


出现如上图提示表示安装完成,重启生效
当然我们还是需要进行一些简单配置:

配置如下图所示内容

{
"anaconda_linting": false,
"pep8": false
}
上述的配置是因为这个插件和flake8插件的功能相互冲突,这里最好使用flake8的配置就可以了
我们可以测试它的一些功能:
当我们输入print的时候就会显示出参数及文档

这里还包括了很多功能不再一一演示,功能使用都在:

这个插件有很多实用的功能可以自己详细看看并使用
配置git环境
首先要确保自己的电脑已经安装了git
如果没有安装,需要去这里下载:https://git-scm.com/download/win
安装过程如下:










对自己的git环境进行基本的配置:
git config --global user.email "yourname@yourdomain.com"
git config --global user.name "Firstname Lastname"
git config --global --list 命令可以查看上面的配置
安装git插件GitGutter
安装过程和之前安装其他插件的方法一样:


安装这个插件的作用是为了让我们更好的和git联合在一起,如:在公司里你从git上拉了同时的代码,然后你在上面做更改,这个时候当然你可以过git diff命令查看你修改了哪些地方,但是如果我们通过这个插件直接可以在代码里体现出来,如下图,图一是我从git上随便clone了一个代码,然后操作修改

从上图中我们能够很清楚的知道我们添加了哪些代码,同样的删除哪些代码,修改哪些代码都会有相应的提示
让这个功能不止这些,通过下面例子演示:
git init test-repo
cd test-repo
echo hello world > myfile.txt git add myfile.txt
通过上面命令添加一个test-repo仓库,然后写了一个文件
正常如果我们提交肯定是git add .然后git commit出现如下图:


这里可以通过Esc然后:q键退出
其实这里我们可以让每次commit的时候打开sublime,在sublime编辑里写提交信息,这样会更加方便,配置如下:
git config --global core.editor “‘C:\Program Files\Sublime Text 3\subl.exe’ –wait –new-window”
这样当我们再次commit的时候就是如下图效果:

现在如果信息过长就会看起非常不方便
Git Commit Message Syntax 插件安装

这个插件安装好后不会有提示,重启一下sublime
外观的配置
关于字体
在如下图所示的地方下载字体


可以选择字体之后直接右键安装
配置内容如下:
修改Preferences中的settings

添加内容有:
"font_face": "Ubuntu Mono",
"font_size":14,
"font_options": [
"directwrite",
"subpixel_antialias"
],
"font_options": [
"directwrite",
"subpixel_antialias",
"no_bold", "no_italic"
],
"caret_style": "solid",
"wide_caret": true,
"highlight_line": true,
"draw_white_space": "all",
"indent_guide_options": [
"draw_active"
],
"line_padding_bottom": 1,
"line_padding_top": 2,
"fold_buttons": false,
"scroll_past_end": true,
"shift_tab_unindent": true,
上面这些修改之后还有一个重要的修改,让你的ide看起更加好看
安装Tomorrow Color Schemes插件

安装SoDaReloaded插件

安装完成后配置Preferences → Settings
配置如下:
"theme": "SoDaReloaded Dark.sublime-theme",
然后做如下操作:


选择标注的主题色,最后效果如下:

配置PEP8规范

配置内容如下:
"tab_size": 4,
"translate_tabs_to_spaces": true,
"trim_trailing_white_space_on_save": true,
"ensure_newline_at_eof_on_save": true,
"rulers": [
72,
79
],
"word_wrap": true,
"wrap_width": 80
这样配置好后,我们写代码的长度就有限制,超过了就会自定换行,如下图:

关于文件管理插件安装
默认情况下如果我们在左边的文件直接右键只能看到如此简陋的操作,如果想要更加丰富,则需要安装插件


当安装完成后:

需要配置perferences -> settings
"file_exclude_patterns":[
".pyc",
".pyo",
".exe",
".dll",
".obj",
".o",
".a",
".lib",
".so",
".dylib",
".ncb",
".sdf",
".suo",
".pdb",
".idb",
".DS_Store",
".class",
".psd",
".db",
"*.sublime-workspace"
],
"folder_exclude_patterns": [
".svn",
".git",
".hg",
"CVS",
"pycache"
]
安装Zen Tabs插件

安装完成后做做如下配置:

配置内容为:
"open_tab_limit": 5,
"hightlight_modified_tabs": true,
"show_full_path": false,
到此所有的配置完成!
----- 非原创---------
转自 https://www.cnblogs.com/zhaof/p/8126306.html