本文介绍Atom编辑器在GNU/Linux中的安装、配置。

Download

Atom是一款跨平臺的編輯器,官網地址 https://atom.io/

Atom releases page.

下載選擇

  • Windows:AtomSetup.exeatom-windows.zip
  • Linux
    • rpm包:atom.x86_64.rpm
    • 源碼包:Source Code(zip)Source Code(tar.gz)

Install

主要講RHEL/CentOS/Fedora下安裝方式,以下操作需要使用sudo獲取管理員權限

Install Required Packages

安裝需要的依賴包

1
sudo yum -y install make gcc gcc-c++ glibc-devel git-core libgnome-keyring-devel rpmdevtools

RPM Install

rpm包安裝

推薦使用sudo yum localinstall命令安裝

Source Code Compile Install

源碼包安裝(需要使用Node.js)

Install Node.js

安裝Node.js,不太建議使用源碼包編譯安裝,太耗時

The npm command-line tool is bundled with Node.js. If you have it installed, then you already have npm too.

建議使用 Enterprise Linux and Fedora提供的方式安裝

源碼包編譯安裝Node.js 可參考本人博文 「Compile and Install Node.js on CentOS7

Decompress

解壓源碼包

  • zip
    v1.3.2.zip爲例

    1
    2
    3
    4
    5
    6
    #查看文件類型
    file v1.3.2.zip
    #需要通過unzip命令解壓
    sudo yum install -y unzip
    unzip -q v1.3.2.zip
    cd atom-1.3.2/
  • tar.gz
    v1.3.2.tar.gz爲例

    1
    2
    3
    file v1.3.2.tar.gz
    tar xf v1.3.2.tar.gz 或 tar zxf v1.3.2.tar.gz
    cd atom-1.3.2/

Build Atom

1
./script/build

This will create the atom application at $TMPDIR/atom-build/Atom.

如果想自定義install dir可使用

1
./script/build --build-dir /build/atom/here

Install Atom

Install the atom and apm commands to /usr/local/bin

1
sudo script/grunt install

To use the newly installed Atom, quit and restart all running Atom instances.

如果想自定義build directory,可使用

1
sudo script/grunt install --install-dir /install/atom/here

Configuration

調出Settings設置界面

  • 通過快捷鍵Ctrl+,
  • 通過窗口欄Packages–>Setting View–>Open

Concrete Options

  1. “Font Family”項填入DejaVu Sans Mono,文泉驿正黑,解決中文無法正常顯示;
  2. “Tab Length”項選擇”4”,解決tab4個空格;
  3. 選中”Soft Wrap”,解決換行問題;

Concrete Plugins & Packages

可通過安裝插件提高Atom的使用效率

調出Install Packages界面

  • 通過快捷鍵Ctrl+,,點擊Install
  • 通過窗口欄Packages–>Setting View–>Install Packages/Themes

注意: Atom安裝完成後,界面中間偏右的地方有一條豎線,可在Settings->Packages中將名爲wrap-guide的安裝包設置爲disable(禁用)即可。

Common Packages

  1. Minimap:A preview of the full source code. link
  2. Highlight Selected: Double click on a word to highlight it throughout the open file. link
  3. file-icons 給不同文件類型賦予不同的圖標 link
  4. platformio-ide-terminal: Shell命令行終端 link
  5. Markdown Preview Plus (MPP): Markdown預覽 link
    • 禁用內置的markdown-preview
  6. atom-beautify 代碼排版美化 link
  7. atom-runner 运行代码并在新窗口显示结果 link (Alt + R)

Web Development

  1. emmet 用於HTML代碼快速編寫 link
  2. atom-bootstrap4 快速編寫bootstrap代碼 link
  3. jQuery Snippets 用於jQuery代碼提示 link
  4. color-picker 顏色汲取器 link

Programming Language

PHP

  1. autocomplete-php package 用於PHP代碼提示 link
  2. atom-autocomplete-php link
  3. PHP-twig 用於Twig模板引擎 link

Python

  1. autocomplete-python link
  2. python-autopep8 link
  3. python-jedi link
  4. python-tools link

Golang

  1. go-plus golang套件 link

Golang Configuration

Golang安裝目錄/opt/go,代碼保存目錄~/golang

創建環境變量文件/etc/profile.d/golang.sh,內容如下

1
2
3
export GOROOT=/opt/go
export PATH=$PATH:$GOROOT/bin
export GOPATH=$HOME/golang

執行 . /etc/profile.d/golang.sh是設置生效

Atom插件go-plus設置,根據軟件保存位置、代碼存放位置設置

Paras Value
Format tool gofmt
Go Installation /opt/go/bin
Go Path ~/golang

Configurations Backup

爲方便快速配置Atom,可通過備份配置文件實現。

config.scon

Atom的配置文件路徑爲

1
~/.atom/config.cson

內容如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
"*":
"autocomplete-python":
showTooltips: true
useSnippets: "all"
core:
autoHideMenuBar: true
disabledPackages: [
"github"
"wrap-guide"
"php-twig"
"atom-autocomplete-php"
"autocomplete-php"
"markdown-preview"
"atom-bootstrap4"
]
telemetryConsent: "no"
editor:
fontSize: 18
softWrap: true
tabLength: 4
"exception-reporting":
userId: "816448ac-4595-40c1-82f8-840b23b640df"
"markdown-preview-plus":
enableLatexRenderingByDefault: true
"platformio-ide-terminal":
core:
mapTerminalsTo: "File"
workingDirectory: "Active File"
style:
fontSize: "18"
theme: "novel"
toggles:
autoClose: true
welcome:
showOnStartup: false

package lists

通過如下命令可備份、恢復插件信息。

1
2
3
4
5
# export packages info
apm list --installed --bare > ~/.atom/package.txt

# import packages info
apm install --packages-file ~/.atom/package.txt

已安裝對插件信息如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# apm list --installed --bare
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]

Regular Errors

  • /usr/bin/env: node: No such file or directory
  • npm 1.4 is required to build Atom (Eoor: spawn ENOENT) occured when checking the version
    • 沒有安裝npm
  • npm v1.4+ is required to build Atom. Version 1.3.6 was detected
    • 安裝的npm版本過低,通過sudo yum -y install npm安裝會出現此問題

References


Further Reading


Change Log

  • 2016.01.07 11:38 Thu Asia/Beijing
    • 第一版完稿
  • 2016.01.25 22:30 Mon Asia/Beijing
    • 勘誤,上傳至lempstacker部落格
  • 2016.02.23 14:54 Tue Asia/Beijing
    • 添加插件file-iconsgo-plus
  • 2016.03.20 18:57 Sun Asia/Beijing
    • 添加插件 atom-bootstrap4color-pickerterminal-plus
  • 2016.03.26 09:03 Sat Asia/Beijing
    • 添加Golang Configuration
  • 2016.09.08 10:02 Thu Asia/Shanghai
    • Concrete Packages插件分類整理
  • 2017.02.03 11:27 Fri America/Boston
    • 添加插件atom-beautify
  • 2017.03.07 09:34 Tue Asia/Shanghai
    • 添加插件atom-runnerpython-autopep8python-jedipython-tools
  • 2017.04.21 10:00 Fri Asia/Shanghai
    • 添加插件Markdown Preview Plus (MPP)
  • 2017.05.03 10:28 Wed America/Boston
    • 添加Configurations Backup