Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Ruby

Atom Editor สำหรับ Ruby: Top Plugins & Essential Shortcuts

Atom packages (plugins) ช่วยเพิ่ม productivity มีเยอะมาก ตัวไหนควรใช้? พร้อม keyboard shortcuts ที่มีประโยชน์

Best Atom Packages

ติดตั้งจาก Settings (Ctrl+,) → Install tab

1. Atom Runner

รันโค้ดใน editor เอง output แสดง split window ด้านขวา (หรือล่างใน Atom 1.17+) ติดตั้งค้นหา "atom runner" กด Alt+R (Ctrl+R Mac) ต้องตั้ง file type = Ruby

เพิ่ม font size output: เปิด stylesheet (Ctrl+Alt+P → "osty") เพิ่ม .stdout { font-size: 18px !important; }

2. Block Convert

แปลง do...end ↔ { ... } ใส่ cursor ในบล็อก → Command Palette (Ctrl+Alt+P) → "converter" → เลือก "to do end" หรือ "to curly brackets"

3. Toggle Quotes

สลับ single/double quotes ใส่ cursor ระหว่าง quotes กด Ctrl+" (Cmd+" Mac)

4. Linter Ruby

Linting ชี้ syntax errors หา error เร็วกว่ารัน tests ติดตั้ง "linter-ruby"

Other Packages

  • ruby-block
  • color-picker
  • teletype.atom.io (pair programming)

Atom Keyboard Shortcuts

ShortcutDescription
Ctrl+DMulti Selection
Ctrl+FSearch in file
Ctrl+PQuick open files
Ctrl+BSwitch open files
Ctrl+Alt+7Toggle comments
Ctrl+Up/DownMove line up/down
Ctrl+Shift+KDelete line

Atom Snippets เพิ่ม Productivity

พิมพ์ trigger + Enter → template โค้ด ตัวอย่าง built-in Ruby snippets:

SnippetDescription
ifif/end
ifeif/else/end
defdef/end
claclass/end
modmodule/end
eaeach { ... }
begbegin/rescue/end
rattr_reader
rwattr_accessor

ERB snippets: = → <%= %>, - → <% %>

สร้าง custom snippets: Command Palette → "osni" → แก้ไฟล์ snippets.cson

".source.ruby":
  "Initialize":
    prefix: "init"
    body: "def initialize\n\t$1\nend"

$1 = cursor position หลัง insert Tab ไป $2, $3...

Auto Indent

Select code → Command Palette → "auto" → Auto Indent

Built-In Git Integration

Atom 1.18+ มี Git integration กดมุมล่างขวา (นับไฟล์) → Git panel → stage, commit message, commit

Summary

เรียนรู้ packages, shortcuts, snippets ทำให้เป็น Ruby developer ที่ productive กว่า!