Ubuntu下安装sublime
sublime-text常用来写代码,它的代码高亮,自动补全功能着实很迷人,还有很多拓展包,觉得大家可以尝试一下。如果您想采用sublime-text2,则可访问 http://www.sublimetext.com/2 下载,若想采用sublime-text3,则可访问http://www.sublimetext.com/3 下载。下载之后的文件格式为deb。Ubuntu对于deb有以下常见操作
Ubuntu软件包格式为deb,安装方法如下:
sudo dpkg -i package.deb
dpkg的详细使用方法,网上有很多,下面简单列了几个:
指令 | 操作 |
---|---|
dpkg -i package.deb | 安装包 |
dpkg -r package | 删除包 |
dpkg -P package | 删除包(包括配置文件) |
dpkg -L package | 列出与该包关联的文件 |
dpkg -l package | 显示该包的版本 |
dpkg –unpack package.deb | 解开 deb 包的内容 |
dpkg -S keyword | 搜索所属的包内容 |
dpkg -l | 列出当前已安装的包 |
dpkg -c package.deb | 列出 deb 包的内容 |
dpkg –configure package | 配置包 |
安装Jedi
sublime可以下载拓展包丰富其功能,其中笔者认为Python代码自动补全较为实用的包为Jedi。我们可以通过以上步骤进行下载
1.为了防止出错先做这一步。打开控制台(ctrl+`),在控制台中输入以下代码:
若为sublime2,则
import urllib2,os; pf='Package Control.sublime-package'; ipp = sublime.installed_packages_path(); os.makedirs( ipp ) if not os.path.exists(ipp) else None; urllib2.install_opener( urllib2.build_opener( urllib2.ProxyHandler( ))); open( os.path.join( ipp, pf), 'wb' ).write( urllib2.urlopen( 'http://sublime.wbond.net/' +pf.replace( ' ','%20' )).read()); print( 'Please restart Sublime Text to finish installation')
若为sublime3,则
import urllib.request,os; pf = 'Package Control.sublime-package'; ipp = sublime.installed_packages_path(); urllib.request.install_opener( urllib.request.build_opener( urllib.request.ProxyHandler()) ); open(os.path.join(ipp, pf), 'wb').write(urllib.request.urlopen( 'http://sublime.wbond.net/' + pf.replace(' ','%20')).read())
2.在sublime的菜单中选择Preferences->Packages Control,在下来菜单中选择Install Package,键入Jedi,选择 Jedi - Python autocompletion,则开始下载并安装Jedi
3.安装结束后,关闭并重新打开sublime,进行下一步的工作。
配置Jedi
Jedi的代码补全是可以深入到包中的函数的自动补全,因此是需要指定路径让Jedi去搜读取该路径下的包的内容,我们要做的就是设置路径。
1.在sublime的菜单中选择Preferences->Package settings->Jedi->Settings-Default,会打开一个设置文件
2.找到python所在的文件夹。笔者所使用的为Anaconda2,路径为/home/horcham/anaconda2,anaconda2所在的包则存在这个路径里面,笔者查了一下,包存在以下两个路径
/home/horcham/anaconda2/pkgs
/home/horcham/anaconda2/lib/python2.7/site-packages
将这两个路径填入到设置文件中的“python_interpreter” 和 “python_package_paths”,笔者填入后为:
{
// Used to get the `PYTHONPATH`.
// You can set a path to your python interpreter,
// for example `/home/user/.virtualenvs/myenv/bin/python)`.
"python_interpreter": "/home/horcham/anaconda2/bin/python",
// Additional python package paths.
"python_package_paths": [
"/home/horcham/anaconda2/pkgs",
"/home/horcham/anaconda2/lib/python2.7/site-packages"
],
// Which function arguments to insert in autocompletion:
// "all" - all
// "required" - those with no default value (that are required)
// "" - none
"auto_complete_function_params": "required",
// "debug", "error", "info", "warn"
"logging_level": "warn",
// Which completions to show:
// "all" - both jedi's and sublime's
// "jedi" - only jedi's
// "default" - only jedi's if it has something to show, otherwise sublime's
"sublime_completions_visibility": "default",
// how to open goto definition result with ability to show it transient
// variation (preview only. it won't have a tab assigned it until modified):
// "single-panel" - opens a file in same layout (default)
// "single-panel-transient" - same as above but in transient mode
// "two-panel" - opens a file in a split to two columns layout
// "two-panel-transient" - same as above but in transient mode
"sublime_goto_layout": "single-panel"
}
修改之后保存该配置文件即可,重新打开sublime就可以使用。