Vim YouCompleteMe (自動完成) 外掛工具

Vim 想要一邊打字一邊出現提醒?自動完成?可以使用此 YouCompleteMe(YCM) 外掛工具來達成。

Vim YouCompleteMe (自動完成) 外掛工具

Vim 預設內建的自動完成(OmniCompletion),可以於打字首後,按 c-x c-o (c = ctrl) 來出現,YCM 則是類似 IDE 的邊打邊出現的方式。

YCM 官方網站

YCM 的安裝步驟

下述是搭配 Pathogen (Pathogen 安裝步驟可見:Vim 使用 Pathogen 來管理 Plugin 套件外掛)

  1. apt-get install build-essential cmake python-dev
  2. cd ~/.vim/bundle/
  3. git clone https://github.com/Valloric/YouCompleteMe.git
  4. cd ~/.vim/bundle/YouCompleteMe
  5. git submodule update --init --recursive
  6. ./install.py
  7. ./install.py --help
  8. ./install.py --clang-completer # c
  9. ./install.py --gocode-completer # go
  10. 到此進 Vim 寫 Code 就會有自動完成的效果出現囉~
    • 問題排解
    • apt-get install vim-nox # 出現錯誤訊息 YouCompleteMe unavailable: requires Vim compiled with Python 2.x support 安裝此套件
    • 註:YCM 是 Client / Server 架構,所以開啟 Vim 同時會啟動 ycmd (YCM Daemon)

問題排除

若更新後遇到下述錯誤訊息:

raceback (most recent call last):
  File "<string>", line 19, in <module>
  File "/home/user/.vim/bundle/YouCompleteMe/autoload/../python/ycm/setup.py", line 38, in SetUpSystemPaths
    su.AddNearestThirdPartyFoldersToSysPath( DIR_OF_CURRENT_SCRIPT )
AttributeError: 'module' object has no attribute 'AddNearestThirdPartyFoldersToSysPath'
YouCompleteMe unavailable: 'module' object has no attribute 'AddNearestThirdPartyFoldersToSysPath'

解法

  1. cd ~/.vim/bundle/YouCompleteMe/
  2. git submodule update --init --recursive # 更新 submodule

相關網頁

作者: Tsung

對新奇的事物都很有興趣, 喜歡簡單的東西, 過簡單的生活.

發表迴響

這個網站採用 Akismet 服務減少垃圾留言。進一步了解 Akismet 如何處理網站訪客的留言資料