Skip to content

Instantly share code, notes, and snippets.

@iporsut
Last active June 8, 2017 15:23
Show Gist options
  • Save iporsut/4656c2bbad06ad74e296d00fb57aa41c to your computer and use it in GitHub Desktop.
Save iporsut/4656c2bbad06ad74e296d00fb57aa41c to your computer and use it in GitHub Desktop.
Vim Go Setup

Setep

  1. ลง vim ใหม่โดยให้ enable lua
  2. เลือกตัวช่วยในการจัดการ plugins ผมใช้ Pathogen.vim ใช้ง่ายดี https://github.com/tpope/vim-pathogen
  3. ลง neocomplete.vim plugin
  4. ลง vim-go
  5. ใช้คำสั่งใน vim-go เพื่อติดตั้ง go tool ที่เหลือ

ลง Vim โดย enable lua

macOS

สำหรับ macOS ผมใช้ brew ช่วย แล้วสั่งแค่ brew install vim --with-lua หรือถ้าใครมี vim อยู่แล้วก็เปลี่ยนเป็น reinstall แทน

Linux

ให้ลง vim แบบ full โดยผ่าน package อันใดอันหนึ่งในนี้ก็ได้

  • vim-nox
  • vim-gtk
  • vim-gnome
  • vim-athena

ลง Pathogen.vim

จาก readme ของ https://github.com/tpope/vim-pathogen ให้สั่งแค่ 2 คำสั่งต่อไปนี้

mkdir -p ~/.vim/autoload ~/.vim/bundle && \
curl -LSso ~/.vim/autoload/pathogen.vim https://tpo.pe/pathogen.vim

หลังจากนั้นเพิ่ม config นิดหน่อยเข้าไปที่ ~/.vimrc ดังนี้

execute pathogen#infect()

ถ้ายังไม่เปิด syntax on กับ indent on ก็เปิดด้วยโดยเพิ่มเข้าไปอีกแบบนี้

syntax on
filetype plugin indent on

เท่านี้ต่อไปถ้าอยากลง plugin อื่นๆ ก็แค่โหลดเอาไปไว้ใน ~/.vim/bundle

ลง neocomplete

ทีนี้จะลง neocomplete ก็แค่

git clone https://github.com/Shougo/neocomplete.vim.git ~/.vim/bundle/neocomplete.vim

ส่วนการ config มันมี option เยอะครับ ดูใน https://github.com/Shougo/neocomplete.vim เพิ่มเติม แต่เริ่มแรกต้องการแค่นี้ เพิ่มเข้าไปใน .vimrc

let g:neocomplete#enable_at_startup = 1

ลง vim-go และ go tool

ทีนี้ให้ลง vim go เมื่อใช้ pathogen ก็ทำง่ายๆตามนี้

git clone https://github.com/fatih/vim-go.git ~/.vim/bundle/vim-go

แค่นี้เมื่อเข้า vim อีกรอบก็ลง go tool (อันนี้ต้องติดตั้ง go ให้เรียบร้อยก่อนนะ ตั้ง GOPATH อะไรให้เรียบร้อยด้วย) แค่สั่ง

:GoInstallBinaries

เท่านี้เป็นอันเสร็จพิธี สามารถใช้ autocomplete แบบลิสต์ function หรือของใน package เช่นพิมพ์ fmt.P ก็จะขึ้นลิสต์มาให้เลย :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment