2015年6月21日 星期日

VIM - 建構golang的編輯環境



中斷了好幾年的更新, 讓新的篇章從vim + go 開始


  • VIM 相關
    • Homebrew 套件管理工具

      http://brew.sh/index_zh-tw.html

      透過brew安裝的軟體都會被放到 /usr/local/Cellar目錄中,

      未來如果要更新版本, 可以使用 update 先跟新清單之後再進行upgrade
    • vim 最新版
      brew  install vim
      會安裝完成 vim 7.4
  • go 安裝
    • 透過 homebrew
      brew install go
    • 官網下載
      https://golang.org/
  • 安裝 Vundle
    • https://github.com/gmarik/Vundle.vim
      git clone https://github.com/gmarik/vundle.git ~/.vim/bundle/vundle
    • 設定 .vimrc
    • 
      " vundle 設定
      set nocompatible              " be iMproved, required
      filetype off                  " required
      " set the runtime path to include Vundle and initialize
      set rtp+=~/.vim/bundle/vundle/
      call vundle#rc()
      " alternatively, pass a path where Vundle should install plugins
      "let path = '~/some/path/here'
      "call vundle#rc(path)
      
      " let Vundle manage Vundle, required
      Plugin 'gmarik/vundle'
      " The following are examples of different formats supported.
      " Keep Plugin commands between here and filetype plugin indent on.
      " scripts on GitHub repos
      filetype plugin indent on     " required
      " To ignore plugin indent changes, instead use:
      "filetype plugin on
      " Brief help
      " :PluginList          - list configured plugins
      " :PluginInstall(!)    - install (update) plugins
      " :PluginSearch(!) foo - search (or refresh cache first) for foo
      " :PluginClean(!)      - confirm (or auto-approve) removal of unused plugins
      "
      " see :h vundle for more details or wiki for FAQ
      " NOTE: comments after Plugin commands are not allowed.
      " Put your stuff after this line
      
      
      
    • 新增Plugin
      在.vimrc中加入 Plugin '套件'
      執行 vim +PluginInstall +qall
      或是開啟檔案輸入 :PluginInstall
  • 安裝自動補齊功能
    • https://github.com/Valloric/YouCompleteMe
    • 在.vimrc中輸入
      Plugin 'Valloric/YouCompleteMe'
      Plugin 'fatih/vim-go'
    • 執行 :PluginInstall
      這邊會執行很久, 之後你可能會看到現這個錯誤
      ycm_client_support.[so|pyd|dll] and ycm_core.[so|pyd|dll] not detected; you need to compile YCM
      before using it. Read the docs!
      沒錯, 這邊就是要你自己去使用cmake編譯ycm
      先安裝cmake ( brew install cmake)
      然後執行 ~/.vim/bundle/YoucompleteMe/install.sh
    • 安裝需要的go binary
      打開隨便一個go檔案, 輸入 :GoInstallBinaries
      便會開始安裝需要的套件
以上都安裝完成後, 就可以開始使用自動補完功能囉


©Yichen

沒有留言: