Golang — ทำ shortcut สำหรับ run test ใน VS Code

Mn
Yeeraf Co., Ltd.
Published in
Jul 26, 2021

โดยปกติพวกคำส่ังต่างใน VS Code สามารถทำการเซ็ต shortcut ได้เป็นปกติอยู่แล้ว แต่เคสของผมคือ

  • ต้องการ set shortcut: cmd + tสำหรับ run test ใน golang
  • แต่ shortcut นี้ถูกเซ็ตไว้แล้วกับ php (เพื่อ run phpunit) ไว้ก่อนแล้ว

ก็ไม่ใช่ปัญหาเพราะ VS Code สามารถใช้ shortcut เดียวกันเพื่อ run คนละคำสั่งได้ตาม condition ที่ต้องการ

สำหรับเคสผมคือจะให้

  • cmd + tในไฟล์ php ใช้คำส่ัง phpunit
  • cmd + tในไฟล์ go ใช้คำสั่ง Go Test Function At Cursor

ขั้นตอนสำหรับการทำ

  • กด cmd + shift + p
  • เลือก preferences: Open keyboard shortcut
  • ค้นหา Go Test Function At Cursor
  • set keybinding เป็น cmd + t
  • set When เป็น editorLangId == 'go'

--

--