Sublime Text是廣為流行的輕量級編輯器。當(dāng)我們想要聚焦于編程而非調(diào)試時,使用輕量級編輯器無疑是一種享受。關(guān)于Sublime Text3特性的介紹,請參考其官方(http://www.sublimetext.com/)。
本文簡單介紹Sublime Text3一些插件的安裝和Python,R快捷鍵的定制。
安裝Sublime Text3直接上前面的官網(wǎng)地址下載相應(yīng)的版本進(jìn)行安裝,然后百度注冊碼輸入激活即可。
插件安裝請參考實(shí)用的sublime插件集合 – sublime推薦必備插件與為 Sublime Text 3 設(shè)置 Python 的全棧開發(fā)環(huán)境兩篇博文。因?yàn)檫@些插件并非全都需要,請按照自己的需要進(jìn)行安裝,這里我推薦一些必要的插件:
Emmet
Anaconda
ColorSublime (這里選擇自己喜歡的主題安裝)
SideBarEnhancements
Djaneiro
SublimeLinter
SublimeREPL (這個必須安裝,不然就不能設(shè)置運(yùn)行腳本的快捷鍵了)
在設(shè)置Python與R的腳本運(yùn)行快捷鍵之前需要安裝好它們。你可以自己去相應(yīng)的網(wǎng)址安裝下載,我是用的Anaconda,然后在里面安裝Rstudio,這樣R和Python都有了。Sublime Text會自動尋找程序的路徑,所以兩種方式都應(yīng)該沒問題。(第一種沒驗(yàn)證)
參考Sublime Text3配置SublimeREPL快捷鍵的方法(Python)設(shè)置快捷鍵:
點(diǎn)擊菜單欄Preferences-->Key Bindings User,在里面輸入
[
{
"keys": ["f5"],//這是自己設(shè)運(yùn)行python的快捷鍵
"command": "run_existing_window_command",
"args":
{
"id": "repl_python_run",
"file": "config/Python/Main.sublime-menu"
}
},
{
"keys": ["ctrl+alt+r"],//這是自己設(shè)的運(yùn)行R腳本快捷鍵
"command": "run_existing_window_command",
"args":
{
"id": "repl_r_run",
"file": "config/R/Main.sublime-menu"
}
}
]
這里需要注意,我寫這篇文章時(2017-10-21),R的設(shè)置文件中還沒有叫“repl_r_run”的“id”。所以我參考python的設(shè)置進(jìn)行理解和自定義。
按照以下操作打開R設(shè)置文件:Preferences-->Browse Packages-->SublimeREPL文件夾-->config文件夾-->R文件夾-->Main.sublime-menu(以文本格式打開)
將里面的內(nèi)容改成
[
{
"id": "tools",
"children":
[{
"caption": "SublimeREPL",
"mnemonic": "R",
"id": "SublimeREPL",
"children":
[
{"command": "repl_open",
"caption": "R",
"id": "repl_r",
"mnemonic": "R",
"args": {
"type": "subprocess",
"external_id": "r",
"additional_scopes": ["tex.latex.knitr"],
"encoding": {
"windows": "$win_cmd_encoding",
"linux": "utf8",
"osx": "utf8"
},
"soft_quit": "\nquit(save=\"no\")\n",
"cmd": {"linux": ["R", "--interactive", "--no-readline"],
"osx": ["R", "--interactive", "--no-readline"],
"windows": ["Rterm.exe", "--ess", "--encoding=$win_cmd_encoding"]},
"cwd": "$file_path",
"extend_env": {"osx": {"PATH": "{PATH}:/usr/local/bin"},
"linux": {"PATH": "{PATH}:/usr/local/bin"},
"windows": {}},
"cmd_postfix": "\n",
"suppress_echo": {"osx": true,
"linux": true,
"windows": false},
"syntax": "Packages/R/R Console.tmLanguage"
}
},
{"command": "repl_open",
"caption": "R - RUN current file",
"id": "repl_r_run",
"mnemonic": "R",
"args": {
"type": "subprocess",
"encoding": {
"windows": "$win_cmd_encoding",
"linux": "utf8",
"osx": "utf8"
},
"cmd": ["Rscript","--vanilla", "$file_basename"],
"cwd": "$file_path",
"syntax": "Packages/R/R Console.tmLanguage",
"external_id": "R",
"extend_env": {"osx": {"PATH": "{PATH}:/usr/local/bin"},
"linux": {"PATH": "{PATH}:/usr/local/bin"},
"windows": {}}
}
}
]
}]
}
]
這里主要對內(nèi)容插入了一個子項(xiàng):
{"command": "repl_open",
"caption": "R - RUN current file",
"id": "repl_r_run",
"mnemonic": "R",
"args": {
"type": "subprocess",
"encoding": {
"windows": "$win_cmd_encoding",
"linux": "utf8",
"osx": "utf8"
},
"cmd": ["Rscript","--vanilla", "$file_basename"],
"cwd": "$file_path",
"syntax": "Packages/R/R Console.tmLanguage",
"external_id": "R",
"extend_env": {"osx": {"PATH": "{PATH}:/usr/local/bin"},
"linux": {"PATH": "{PATH}:/usr/local/bin"},
"windows": {}}
}
}
如果你想讓文件設(shè)置更規(guī)范,可以修改該文檔同一目錄下文件Default.sublime-commands,把它的內(nèi)容改為:
[
{
"caption": "SublimeREPL: R",
"command": "run_existing_window_command", "args":
{
"id": "repl_r",
"file": "config/R/Main.sublime-menu"
}
},
{
"caption": "SublimeREPL: R - RUN current file",
"command": "run_existing_window_command", "args":
{
"id": "repl_r_run",
"file": "config/R/Main.sublime-menu"
}
}
]
最后驗(yàn)證一下是否成功,我隨便寫了一個簡單的用R和python都能執(zhí)行的腳本,內(nèi)容為
a = 3
b = 4
a - b
print(a)
先按f5
測試Python
按ctrl+alt+r
測試R