尋找幫助,建議或支持?有問題讓YCM上班嗎?
首先,請仔細閱讀操作系統的安裝說明。我們建議您使用提供的install.py
“完整”安裝指南適用於稀有的高級用例,大多數用戶應使用install.py
。
如果服務器沒有啟動,並且您會遇到“ youCompleteme不可用”錯誤,請檢查故障排除指南。
接下來,檢查您正在使用的語義完成器上的用戶指南部分。對於C/C ++/Objective-C/Objective-C ++/CUDA,您必須閱讀本節。
最後,檢查常見問題解答。
如果在閱讀了安裝和用戶指南並檢查常見問題解答後,您仍然遇到麻煩,請檢查下面的聯繫人部分,以了解如何取得聯繫。
請不要在FreeNode上#vim進行支持。請使用下面的聯繫方式直接與YouCompleteme維護人員聯繫。
請注意,以下說明建議使用vundle。當前,Vundle存在問題,因此這裡有一些使用VIM軟件包的替代說明。
YouCompleteme是一個快速,您的類型,模糊搜索代碼的完成,理解和重構引擎的VIM。
它具有內置的多個完成引擎,並支持任何符合協議的語言服務器,因此幾乎可以使用任何語言。 YouCompleteme包含:
這是上面GIF演示中發生的情況的解釋。
首先,請意識到,不必按任何鍵盤快捷鍵即可在演示中的任何時刻獲取候選人的列表。用戶只是類型,並自行彈出建議。如果用戶沒有找到相關的完成建議和/或只是想輸入,則可以這樣做;完成引擎不會干擾。
當用戶看到提供了有用的完成字符串時,他們會按下選項卡鍵接受它。這插入完成字符串。在所提供的完成過程中重複按下鍵週期。
如果所提供的完成不夠相關,則用戶可以繼續鍵入以進一步過濾不需要的完成。
要注意的關鍵是,完成過濾不是基於輸入是完成的字符串前綴(但也有效)。輸入需要是完成的子序列。這是一種奇特的方式,即以填寫字符串以出現在輸入中的順序中,都需要以任何輸入字符存在。因此, abc
是xaybgc
的子序列,但不是xbyxaxxc
的子序列。過濾器後,複雜的排序系統對完成字符串進行排名,以使最相關的字符串上升到菜單頂部(因此通常只需按一下選項卡)即可。
由於基於標識符的完成引擎,所有上述所有編程語言都可以使用任何編程語言。它收集當前文件和您訪問的其他文件(和您的標籤文件)中的所有標識符,並在輸入時搜索它們(標識符將其放入每組型組中)。
演示還顯示了使用的語義引擎。當用戶按下時.
, ->
或::
在插入模式時(對於C ++;其他語言使用不同的觸發器)時,觸發語義引擎(也可以用鍵盤快捷鍵觸發;請參見其余文檔)。
您在演示中看到的最後一件事是YCM的診斷顯示功能(顯示在左邊的X中顯示的小紅色X;受語法的啟發),如果您正在編輯C-Family File。當完成器引擎編譯您的文件並檢測到警告或錯誤時,它們將以各種方式呈現。您無需保存文件或按任何鍵盤快捷鍵即可觸發此內容,它在後台“發生”。
那不是全部...
YCM可能是唯一具有正確Unicode支持的VIM完成引擎。儘管我們確實在任何地方都假設UTF-8。
YCM還提供多種語言的語義IDE般特徵,包括:
例如,這是一個簽名幫助的演示:
在下面,我們可以看到YCM能夠做一些事情:
auto
FixIt
提供重構GoToImplementation
和GoToType
。這是在懸停彈出窗口中顯示的一些文檔:自動和手動:
功能因文件類型而異,因此請確保查看文件類型功能摘要和完整子命令的完整列表,以找出您喜歡的語言可用的內容。
您還會發現YCM具有FILEPATH完成器(嘗試在文件中輸入./
)和與Ultisnips集成的完整器。
運行時 | 最小版 | 推薦版本(全部支持) | Python |
---|---|---|---|
vim | 9.1.0016 | 9.1.0016 | 3.8 |
Neovim | 0.5 | VIM 9.1.0016 | 3.8 |
我們的政策是支持Ubuntu最新LTS中的VIM版本。
VIM必須有一個工作的Python 3運行時間。
對於Neovim用戶,我們的政策是需要最新發布的版本。目前,需要Neovim 0.5.0。請注意,Neovim不可用某些功能,而Neovim不受正式支持。
YCM有兩個組件:服務器和客戶端。服務器和客戶端都需要Python 3.8或更高版本的3.x版本。
對於VIM客戶端,必須使用--enable-shared
(或MacOS上的--enable-framework
)編譯。您可以檢查是否可以使用:py3 import sys; print( sys.version)
。它應該說3.8.2 (...)
。
對於Neovim,您必須有一個Python 3.8運行時和Neovim Python擴展。請參閱Neovim的:help provider-python
有關如何進行設置。
對於服務器,您必須使用Python 3.8(或更高版本)運行時運行install.py
腳本。不支持Anaconda等。 YCM會記住您用來運行install.py
運行時,並在啟動服務器時會使用它,因此,如果您通常使用Anaconda,請確保將完整的路徑使用到真實的CPYTHON3,例如/usr/bin/python3 install.py --all
等等等等
我們的政策是支持最新的Ubuntu LTS中可用的Python3版本(類似於我們的VIM版本策略)。但是,我們不會沒有理由增加Python運行時版本。通常,當我們使用的當前python版本不受支持時,我們會這樣做。當時,我們通常會選擇一個多年來支持的版本。
為了提供最佳的性能和穩定性,YCMD已將其代碼更新為C ++ 17。這需要最低支持編譯器的版本顛簸。新要求是:
編譯器 | 當前最小 |
---|---|
海灣合作委員會 | 8 |
鐺 | 7 |
MSVC | 15.7(vs 2017) |
YCM需要CMAKE 3.13或更高。如果您的cmake太舊了,您也許可以簡單地pip install --user cmake
即可獲得一個真正的新版本。
在為特定語言提供語言支持時,可能會有運行時要求,例如需要最近的Java開發套件來支持Java支持。通常,YCM無法控制下游編譯器所需的版本,儘管我們會盡力發出我們知道它們的位置。
$ brew install cmake python go nodejs
從Mono Project安裝單聲道(注意:在Intel Mac上,您也可以brew install mono
。在ARM Mac上,您可能需要Rosetta)
對於Java支持,您必須安裝JDK,一種方法是與Homebrew一起使用:
$ brew install java
$ sudo ln -sfn $(brew --prefix java)/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk
預裝的MacOS系統VIM不支持Python 3。因此,您需要安裝支持Python 3或使用Homebrew的MacVim的VIM:
brew install vim
brew install macvim
編譯YCM。
對於Intel和ARM64 Mac,捆綁的Libclang/Clangd工作:
cd ~/.vim/bundle/YouCompleteMe
python3 install.py --all
如果您在查找系統框架或C ++標準庫時遇到麻煩,請嘗試使用Homebrew LLVM:
brew install llvm
cd ~/.vim/bundle/YouCompleteMe
python3 install.py --system-libclang --all
並編輯您的VIMRC以添加以下行以使用Homebrew LLVM的Clangd:
" Use homebrew's clangd
let g: ycm_clangd_binary_path = trim ( system ( ' brew --prefix llvm ' )). ' /bin/clangd '
對於使用任意LSP服務器,請檢查相關部分
這些說明(使用install.py
)是安裝YouCompleteme的最快方法,但是它們可能並不適合所有人。如果以下說明對您不起作用,請查看完整的安裝指南。
需要使用Python 3的支持的VIM版本。 MacVim是一個不錯的選擇,即使您僅使用終端。 YCM不會與Apple的預裝VIM一起使用,因為其Python的支持被打破了。如果您尚未使用支持Python 3或MacVim的VIM,請與Homebrew一起安裝。也安裝Cmake:
brew install vim cmake
或者
brew install macvim cmake
使用Vundle安裝YouCompleteme。
請記住: YCM是帶有編譯組件的插件。如果您使用Vundle更新YCM,並且ycm_core
庫API已更改(很少發生),YCM會通知您重新編譯它。然後,您應該重新運行安裝過程。
注意:如果要C-家庭完成,則必須安裝最新的Xcode以及最新的命令行工具(首次運行clang
時,它們是自動安裝的,或者通過運行xcode-select --install
)
通過clangd編譯YCM對C家族語言的語義支持:
cd ~/.vim/bundle/YouCompleteMe
./install.py --clangd-completer
編譯YCM沒有語義支持C-家庭語言:
cd ~/.vim/bundle/YouCompleteMe
./install.py
以下其他語言支持選項可用:
--cs-completer
來安裝install.py
。install.py
時安裝go and添加--go-completer
。--ts-completer
在調用install.py
時。install.py
時添加--rust-completer
。--java-completer
撥打install.py
時。要簡單地啟用所有內容,都有一個--all
標誌。因此,要使用所有語言功能安裝,請確保安裝xbuild
, go
, node
和npm
工具並在您的PATH
中,然後只需運行:
cd ~/.vim/bundle/YouCompleteMe
./install.py --all
就是這樣。你完成了。請參閱有關如何使用YCM的用戶指南部分。不要忘記,如果您希望C-家庭語義完成引擎可以正常工作,則需要為您的項目提供彙編標誌。這全都在用戶指南中。
YCM的選項帶有Sane默認值,但您仍然可能想查看可用於配置的內容。默認情況下,您可能需要打開一些有趣的選項。
以下假設您正在使用Ubuntu 24.04。
apt install build-essential cmake vim-nox python3-dev
apt install mono-complete golang nodejs openjdk-17-jdk openjdk-17-jre npm
cd ~/.vim/bundle/YouCompleteMe
python3 install.py --all
這些說明(使用install.py
)是安裝YouCompleteme的最快方法,但是它們可能並不適合所有人。如果以下說明對您不起作用,請查看完整的安裝指南。
確保您擁有帶有Python 3支持和支持編譯器的VIM的支持版本。 Ubuntu的最新LTS是簡單安裝的最低平台。對於較早的版本或其他分佈,您可能必須做一些工作來獲得依賴項。
如果您的VIM版本太老了,則可能需要從源中編譯VIM(不用擔心,很容易)。
使用Vundle安裝YouCompleteme。
請記住: YCM是帶有編譯組件的插件。如果您使用vundle更新YCM,並且ycm_core
庫API已更改(這種情況很少發生),則YCM將通知您重新編譯它。然後,您應該重新運行安裝過程。
安裝開發工具,Cmake和Python標題:
sudo dnf install cmake gcc-c++ make python3-devel
sudo apt install build-essential cmake3 python3-dev
通過clangd編譯YCM對C家族語言的語義支持:
cd ~/.vim/bundle/YouCompleteMe
python3 install.py --clangd-completer
編譯YCM沒有語義支持C-家庭語言:
cd ~/.vim/bundle/YouCompleteMe
python3 install.py
以下其他語言支持選項可用:
install.py
時安裝單聲道並添加--cs-completer
。install.py
時安裝go and添加--go-completer
。--ts-completer
在調用install.py
時。install.py
時添加--rust-completer
。--java-completer
撥打install.py
時。要簡單地啟用所有內容,都有一個--all
標誌。因此,要使用所有語言功能安裝,請確保安裝xbuild
, go
, node
和npm
工具,然後在您的PATH
中,然後只需運行:
cd ~/.vim/bundle/YouCompleteMe
python3 install.py --all
就是這樣。你完成了。請參閱有關如何使用YCM的用戶指南部分。不要忘記,如果您希望C-家庭語義完成引擎可以正常工作,則需要為您的項目提供彙編標誌。這全都在用戶指南中。
YCM的選項帶有Sane默認值,但您仍然可能想查看可用於配置的內容。默認情況下,您可能需要打開一些有趣的選項。
cd YouCompleteMe
python3 install.py --all
set encoding=utf-8
添加到您的VIMRC這些說明(使用install.py
)是安裝YouCompleteme的最快方法,但是它們可能並不適合所有人。如果以下說明對您不起作用,請查看完整的安裝指南。
重要:我們假設您正在使用cmd.exe
命令提示符,並且您知道如何在路徑環境變量中添加可執行文件。
確保您具有Python 3支持的支持VIM版本。您可以通過鍵入:version
來檢查版本,並支持哪個python。查看包括:python 3的+python3/dyn
功能。請注意VIM體系結構,即32或64位。選擇Python安裝程序時,這將很重要。我們建議使用64位客戶端。提供32位和64位VIM的每日更新的安裝程序,並提供32位支持。
如果尚未存在,將以下行添加到您的VIMRC中。
set encoding = utf - 8
YCM要求此選項。請注意,它不能阻止您在UTF-8以外的其他編碼中編輯另一個編碼中的文件。您可以通過將++enc
參數指定到:e
命令來做到這一點。
使用Vundle安裝YouCompleteme。
請記住: YCM是帶有編譯組件的插件。如果您使用Vundle更新YCM,並且ycm_core
庫API已更改(很少發生),YCM會通知您重新編譯它。然後,您應該重新運行安裝過程。
下載並安裝以下軟件:
:version
,查看編譯器標誌列表的頁面底部。查找看起來類似於-DDYNAMIC_PYTHON3_DLL="python36.dll"
的標誌。這表明VIM正在尋找Python 3.6。您需要安裝一個或另一個,與版本編號完全匹配。通過clangd編譯YCM對C家族語言的語義支持:
cd %USERPROFILE%/vimfiles/bundle/YouCompleteMe
python install.py --clangd-completer
編譯YCM沒有語義支持C-家庭語言:
cd %USERPROFILE%/vimfiles/bundle/YouCompleteMe
python install.py
以下其他語言支持選項可用:
--cs-completer
調用install.py
。確保構建實用程序msbuild
在您的路徑中。install.py
時安裝go and添加--go-completer
。--ts-completer
在調用install.py
時。install.py
時添加--rust-completer
。--java-completer
撥打install.py
時。要簡單地啟用所有內容,都有一個--all
標誌。因此,要使用所有語言功能安裝,請確保已安裝msbuild
, go
, node
和npm
工具,然後在您的PATH
中,然後僅運行:
cd %USERPROFILE%/vimfiles/bundle/YouCompleteMe
python install.py --all
您可以使用--msvc
選項指定Microsoft Visual C ++(MSVC)版本。 YCM正式支持MSVC 15(2017),MSVC 16(Visual Studio 2019)和MSVC 17(Visual Studio 17 2022)。
就是這樣。你完成了。請參閱有關如何使用YCM的用戶指南部分。不要忘記,如果您希望C-家庭語義完成引擎可以正常工作,則需要為您的項目提供彙編標誌。這全都在用戶指南中。
YCM的選項帶有Sane默認值,但您仍然可能想查看可用於配置的內容。默認情況下,您可能需要打開一些有趣的選項。
完整的安裝指南已移至Wiki。
GoTo
等)GoToAlternateFile
)GoToSymbol
)GoToDocumentOutline
),帶有交互式搜索GetDoc
)GetType
)FixIt
)FixIt
)GoToReferences
)RefactorRename <new name>
)Format
)GoTo
等)GoToImplementation
)GoToSymbol
)GetDoc
)GetType
)FixIt
)FixIt
)RefactorRename <new name>
)Format
)GoTo
)GoToSymbol
)GoToReferences
)GetDoc
)GetType
)RefactorRename <new name>
)GoTo
等)GoToType
)GoToImplementation
)GoToDocumentOutline
),帶有交互式搜索FixIt
)FixIt
)GetDoc
)GetType
)Format
)gopls
服務器實例的管理GoTo
, GoToDefinition
和GoToDeclaration
是相同的)GoToType
)GoToImplementation
)GoToSymbol
)GoToReferences
)GetDoc
)GetType
)FixIt
)FixIt
)RefactorRename <new name>
)Format
)OrganizeImports
)TSServer
服務器實例的管理GoTo
等)GoToImplementation
)GoToReferences
)GoToDocumentOutline
),帶有交互式搜索GetDoc
)FixIt
)FixIt
)GetType
)RefactorRename <new name>
)Format
)rust-analyzer
服務器實例的管理GoTo
, GoToDefinition
和GoToDeclaration
是相同的)GoToType
)GoToImplementation
)GoToSymbol
)GoToReferences
)GoToDocumentOutline
),帶有交互式搜索GetDoc
)GetType
)FixIt
)RefactorRename <new name>
)Format
)OrganizeImports
)ExecuteCommand <args>
)jdt.ls
服務器實例的管理如果所提供的完成太寬,請繼續打字字符; YCM將根據您的意見繼續完善所提供的完成。
過濾是“智能案例”和“智能雜誌”敏感的;如果您僅鍵入小寫字母,則對情況不敏感。如果您的輸入包含大寫字母,則查詢中的大寫字母必須與完成字符串中的大寫字母匹配(小寫字母仍然與兩者匹配)。最重要的是,沒有任何間隙標記的字母將與有或沒有標記的字母匹配:
比賽 | foo | Fôo | foo | Fôo |
---|---|---|---|---|
foo | ✔️ | ✔️ | ✔️ | ✔️ |
Fôo | ✔️ | ✔️ | ||
foo | ✔️ | ✔️ | ||
Fôo | ✔️ |
使用選項卡鍵接受完成,然後繼續按下選項卡以循環完成完成。使用Shift-Tab向後循環。請注意,如果您使用控制台vim(即GVIM或MacVim),則很可能將換檔綁定綁定起作用,因為控制台不會將其傳遞給VIM。您可以重新啟動鑰匙;請參閱下面的選項部分。
了解YCM在內部的工作方式有所了解將防止混亂。 YCM有多個完成引擎:一個基於標識符的完成器,該完成器收集當前文件和您訪問的其他文件(和您的標籤文件)中的所有標識符,並在輸入時搜索它們(標識符將其放入每個模型型組中)。
YCM也有幾個語義引擎。有基於Libclang的基於Libclang的完成者,可為C家族語言提供語義完成。 Python有一個基於絕地武士的完成者。還有一個基於Omnifunc的完成者,它使用VIM的OMNICOMPLETE系統中的數據在YCM中沒有該語言的本機完成者時提供語義完成。
還有其他完成引擎,例如Ultisnips Pertoser和Filepath完成器。
YCM自動檢測到哪種完成引擎在任何情況下都是最好的。有時,它會一次查詢其中幾個,將輸出合併並給您提供結果。
YCM具有客戶端服務器架構; YCM的VIM部分只是一個與YCMD HTTP+JSON Server進行對話的稀薄客戶端,該服務器具有絕大多數YCM邏輯和功能。當您啟動並停止VIM時,該服務器將自動啟動並自動停止。
子序列過濾器刪除了與輸入不匹配的任何完成,但分類系統開始啟動。它實際上非常複雜並且使用了許多因素,但是足以說“ Word Boundare”(WB)子序列字符匹配“值得” “不僅僅是非WB匹配。實際上,這意味著給出“ GUA”的輸入,完成的“ getUserAccount”在列表中的排名將高於“ fooguxa”的完成(這兩個都是子序列匹配)。單詞邊界字符都是所有資本字符,在字符之前的字符和完成字符串中的第一個字母字符。
有效的簽名顯示在第二個彈出菜單中,當前簽名與當前參數一起突出顯示。
當啟用g:ycm_auto_trigger
時,會自動觸發簽名幫助,並在未啟用時不支持它。
當沒有匹配的簽名或離開插入模式時,簽名彈出窗口就會隱藏。如果要在可見的何時手動控制它,則可以將某些內容映射到<plug>YCMToggleSignatureHelp
(見下文)。
有關此功能和一些演示的更多詳細信息,請查看提出的PR。
簽名幫助彈出窗口有時會阻礙。您可以通過映射切換其可見性。 YCM為此提供了“插頭”映射<Plug>(YCMToggleSignatureHelp)
。
例如,通過在插入模式下按CTRL+L,隱藏/顯示簽名幫助彈出窗口: imap <silent> <Cl> <Plug>(YCMToggleSignatureHelp)
。
注意:沒有提供默認映射,因為插入映射在不破壞或覆蓋某些現有功能的情況下很難創建。 CTRL-L不是一個建議,只是一個例子。
語義突出顯示是根據單詞的基本語義類型對緩衝文本進行著色的過程,而不是基於正則表達式的經典語法突出顯示。這可能是我們可以很快處理的功能強大數據。
此功能僅在VIM中支持。
例如,這是一個具有經典突出顯示的函數:
這是同一功能,具有語義突出顯示:
如您所見,正確識別功能調用,宏等。
可以通過設置b:ycm_enable_semantic_highlighting
,通過let g:ycm_enable_semantic_highlighting=1
或每次緩衝區啟用Global啟用。
YCM使用文本屬性(請參閱:help text-prop-intro
)進行語義突出顯示。為了自定義著色,您可以定義所使用的文本屬性。
如果定義一個名為YCM_HL_<token type>
的文本屬性,則將代替默認值。 <token type>
定義為LSP規格中定義的語言服務器協議語義令牌類型。
一些服務器還使用自定義值。在這種情況下,YCM會打印一個警告,包括您可以自定義的令牌類型名稱。
例如,要使用Normal
高光組渲染parameter
令牌,您可以做到這一點:
call prop_type_add ( ' YCM_HL_parameter ' , { ' highlight ' : ' Normal ' } )
更一般而言,此模式對於自定義組很有用:
let MY_YCM_HIGHLIGHT_GROUP = {
' typeParameter ' : ' PreProc ' ,
' parameter ' : ' Normal ' ,
' variable ' : ' Normal ' ,
' property ' : ' Normal ' ,
' enumMember ' : ' Normal ' ,
' event ' : ' Special ' ,
' member ' : ' Normal ' ,
' method ' : ' Normal ' ,
' class ' : ' Special ' ,
' namespace ' : ' Special ' ,
}
for tokenType in keys ( MY_YCM_HIGHLIGHT_GROUP )
call prop_type_add ( ' YCM_HL_ ' . tokenType,
{ ' highlight ' : MY_YCM_HIGHLIGHT_GROUP[ tokenType ] } )
endfor
注意:高度實驗的特徵,需要VIM 9.0.214或更高版本(Neovim不支持)。
當g:ycm_enable_inlay_hints
(全球)或b:ycm_enable_inlay_hints
(對於特定的緩衝區)設置為1
時,ycm將插入inlay inalay inalay sine提示,並在語言語義上的支持下。
鑲嵌提示是在屏幕上渲染的文本,該文本不是緩衝區的一部分,通常用於標記參數,參數等的類型或名稱,可幫助開發人員了解代碼的語義。
這裡有一些例子:
默認情況下,YCM會呈現與NonText
突出顯示組的嵌體提示。要覆蓋這一點,請定義YcmInlayHint
突出顯示自己,例如在.vimrc
中:
hi link YcmInlayHint Comment
與上面的語義突出顯示相似,您可以通過定義以鑲嵌提示命名的文本屬性來覆蓋不同含量提示類型的特定突出顯示:例如:
call prop_type_add ( ' YCM_INLAY_Type ' , #{ highlight : ' Comment ' } )
鑲嵌提示的列表可以在python/ycm/inlay_hints.py
中找到
g:ycm_enable_inlay_hints
或b:ycm_enable_inlay_hints
啟用/禁用全球或本地緩衝區g:ycm_clear_inlay_hints_in_insert_mode
設置為1
在輸入插入模式時刪除所有插件提示並在離開插入模式時恢復它們鑲嵌提示可以在屏幕上添加很多文本,並且可能會分散注意力。您可以通過將某些內容映射到<Plug>(YCMToggleInlayHints)
,立即打開/關閉它們,例如:
nnoremap <silent> <localleader> h <Plug> (YCMToggleInlayHints)
由於映射的個人性質,因此沒有為此提供默認映射。
您可以使用CTRL+空間來觸發任何地方的完成建議,即使沒有字符串前綴。這很有用,可以查看哪些頂級功能可供使用。
注意: YCM最初是為C-Family使用的基於libclang
引擎,但用戶應遷移到Clangd,因為它提供了更多功能和更好的性能。依靠其.ycm_extra_conf.py
中override_filename
的用戶將需要留在舊的libclang
引擎上。 Wiki上有有關如何留在舊引擎上的說明。
Clangd的一些特徵:
#include
插入。在支持的體系結構上, install.py
腳本將為您下載合適的clangd( --clangd-completer
)或libclang( --clang-completer
)。支持的體系結構是:
clangd :
通常,clangd由YCM安裝程序安裝(with --all
或--clangd-completer
)。這為您的體系結構下載了預製的clangd
二進製文件。如果您的操作系統或體系結構不受支持或太舊,則可以安裝兼容的clangd
並使用g:ycm_clangd_binary_path
指向它。
libclang :
也可以使用--all
或--clang-completer
啟用libclang
。與clangd
一樣,YCM將嘗試下載適合您環境的libclang
版本,但是如果無法支持您的環境,您可以自己構建或獲取libclang
並在構建時指定它,例如:
$ EXTRA_CMAKE_ARGS='-DPATH_TO_LLVM_ROOT=/path/to/your/llvm' ./install.py --clang-completer --system-libclang
請注意,如果使用自定義clangd
或libclang
則必須匹配YCM所需的版本。目前YCM需要叮噹聲17.0.1 。
為了執行語義分析,例如代碼完成, GoTo
和診斷,YouCompleteme使用clangd
,它使用Clang編譯器,有時也稱為LLVM。像任何編譯器一樣,Clang還需要一組編譯標誌才能解析您的代碼。簡單地說:如果Clang無法解析您的代碼,則您的completeme將無法提供語義分析。
有兩種方法可用於為Clang提供編譯標誌:
獲取YCM編譯代碼的最簡單方法是使用編譯數據庫。通常由您的構建系統(例如CMake
)生成編譯數據庫,並包含項目中每個編譯單元的編譯器調用。
有關如何生成彙編數據庫的信息,請參見clang文檔。簡而言之:
set( CMAKE_EXPORT_COMPILE_COMMANDS ON )
上添加-DCMAKE_EXPORT_COMPILE_COMMANDS=ON
on CMakeLists.txt
),然後將生成的數據庫複製或符號鏈接到項目的根部。compdb
工具( -t compdb
)。.ycm_extra_conf.py
。如果未找到.ycm_extra_conf.py
,則YouCompleteme會自動嘗試加載編譯數據庫,如果有。
YCM在打開文件的目錄或層次結構中上方的任何目錄中查找名為compile_commands.json
的文件(遞歸);當在本地.ycm_extra_conf.py
之前找到文件時,youCompleteme停止搜索目錄,並讓Clangd接管並處理標誌。
如果您沒有編譯數據庫或無法生成一個數據庫,則必須告訴YouCompleteme如何以其他方式編譯代碼。
每個C家族項目都不同。 YCM不可能猜測為您的項目提供什麼編譯器標誌。幸運的是,YCM為您提供了一種具有任意複雜性的特定文件的標誌的機制。這是通過要求您提供一個實現瑣碎函數的Python模塊來實現的,該模塊以文件名作為參數返回用於編譯該文件的編譯器標誌的列表。
YCM在打開文件的目錄或層次結構中上方的任何目錄中查找一個.ycm_extra_conf.py
文件(遞歸);找到文件時,將其作為Python模塊加載(僅一次!)。 YCM調用該模塊中的Settings
方法,該方法應為其提供編譯當前文件所需的信息。您還可以使用g:ycm_global_ycm_extra_conf
選項提供全局配置文件的路徑,該選項將用作後備。為了防止從文件中執行惡意代碼,您未編寫.ycm_extra_conf.py
會問您一次。這可以禁用,您可以白色/黑名單文件。請參閱g:ycm_confirm_extra_conf
和g:ycm_extra_conf_globlist
選項。
該系統是通過這種方式設計的,以便用戶可以執行任何任意操作順序,以產生YCM應將其交給Clang的彙編標誌列表。
注意:強烈建議將-x <language>
標誌包含到libclang。這是為了檢測到正確的語言,尤其是對於標頭文件。對於C ++的C, -x c++
共同值為-xc
,c ++, -x objc
對於objective -c,cuda的-x cuda
。
為了給您留下深刻的印象,如果您的C ++項目很瑣碎,並且您通常的彙編命令是: g++ -Wall -Wextra -Werror -o FILE.o FILE.cc
,那麼以下.ycm_extra_conf.py
足以從中獲得語義分析。 YouCompleteme:
def Settings ( ** kwargs ):
return {
'flags' : [ '-x' , 'c++' , '-Wall' , '-Wextra' , '-Werror' ],
}
從微不足道的示例中可以看到,YCM調用Settings
方法,該方法返回帶有單個元素'flags'
字典。此元素是用於當前文件的libclang的編譯器標誌list
。該文件的絕對路徑可在kwargs
詞典的filename
密鑰下訪問。就是這樣!實際上,對於大多數項目來說,這已經足夠了,但是對於復雜的項目而言,使用Python語言的全部功能直接與現有的構建系統進行集成並不少見。
有關更詳細的示例,請參見YCMD自己的.ycm_extra_conf.py
。您應該能夠將其用作起點。不要只是在某個地方復制/粘貼該文件,並期望事情能神奇地工作;您的項目需要不同的標誌。提示:只需將flags
變量中的字符串替換為項目所需的彙編標誌即可。對於99%的項目,這應該足夠。
您也可以考慮使用YCM-generator生成ycm_extra_conf.py
文件。
如果Clang在編譯文件包含的標頭文件時會遇到錯誤,那麼可能需要很長時間才能完成。當完成菜單最終出現時,它將具有大量無關的完成字符串(實際上不是成員的類型/函數名稱)。這是因為如果包含的標題中有任何錯誤,則Clang無法為您的文件構建預編譯的序言,並且該序言是獲得快速完成的關鍵。
致電:YcmDiags
命令,查看文件中是否檢測到任何錯誤或警告。
確保您啟用了Java完成器。有關詳細信息,請參見“安裝指南”。
按照以下說明,在Java項目的根目錄中創建項目文件(Gradle或Maven)文件。
(可選)配置LSP服務器。可以在其代碼庫中找到JDT.LS配置選項。
如果您以前將Eclim或語詞用於Java,請禁用Java。
從您的項目中編輯Java文件。
為了提供語義分析,Java完成引擎需要了解您的項目結構。特別是,在編譯代碼時,它需要了解使用類路徑。幸運的是,JDT.LS支持Eclipse項目文件,Maven Projects和Gradle Projects。
注意:我們的建議是使用Maven或Gradle項目。
對Java的本機支持包括YCM的本機實時診斷顯示。這可能會與其他診斷插件(例如語法機構)衝突,因此在啟用Java支持時,請手動禁用語法Java診斷。
將以下內容添加到您的vimrc
:
let g: syntastic_java_checkers = []
對Java的本機支持包括YCM的本機實時診斷顯示。這可能會與其他診斷插件(例如ECLIM)衝突,因此在啟用Java支持時,請手動禁用Eclim Java診斷。
將以下內容添加到您的vimrc
:
let g: EclimFileTypeValidate = 0
注意:我們建議在用YCM的本地Java支持編輯Java時完全禁用Eclim。這可以暫時完成:EclimDisable
。
Eclipse風格的項目需要兩個文件:.project和.classPath。
如果您的項目已經在Eclipse內部設置了以前已有這些文件,則不需要設置。 JDT.LS應該可以加載項目(畢竟它基本上是Eclipse)。
但是,如果不是,儘管不建議這樣做,但可以手動製作它們(實際上很容易)。最好使用Gradle或Maven(見下文)。
簡單的Eclipse樣式項目示例可以在YCMD測試目錄中找到。通常所需的只是將這些文件複製到項目的根源,並編輯.classpath
以添加其他庫,例如:
< classpathentry kind = " lib " path = " /path/to/external/jar " />
< classpathentry kind = " lib " path = " /path/to/external/java/source " />
也可能有必要更改源文件所在的目錄(路徑相對於.project文件本身):
< classpathentry kind = " src " output = " target/classes " path = " path/to/src/ " />
注意:Eclipse項目和類Path文件不是公共接口,強烈建議使用Maven或Gradle項目定義,如果您尚未使用Eclipse來管理項目。
Maven需要一個名為pom.xml的文件。再次可以在YCMD源中找到一個簡單的pom.xml。
pom.xml文件的格式超出了本文檔的範圍,但是如果您還不熟悉它們,我們建議使用可以為您生成它們的各種工具。
Gradle項目需要一個構建。同樣,YCMD的測試中有一個微不足道的例子。
build.gradle文件的格式超出了本文檔的範圍,但是我們建議使用各種工具,如果您還不熟悉它們,則可以為您生成它們。
一些用戶在使用Groovy語言為其build.gradle時遇到了JDT.LS的問題。因此,嘗試使用Kotlin。
如果您沒有完成或診斷,請檢查服務器健康:
:YcmDebugInfo
。確保存在以下幾行: -- jdt.ls Java Language Server running
-- jdt.ls Java Language Server Startup Status: Ready
:YcmToggleLogs
方式檢查JDT.LS和YCMD日誌文件。 jdt.ls日誌文件稱為.log
(由於某種原因)。如果您收到有關“ classpath不完整”的消息,請確保正確配置了項目文件。
如果您收到有關未解決的導入的消息,請確保已正確配置了項目文件,特別是檢查classPath是否正確設置了。
YCM依靠Omnisharp-Roslyn提供完成和代碼導航。 Omnisharp-Roslyn需要一個用於C#項目的解決方案文件,有兩種讓YCM了解您的解決方案文件的方法。
YCM將掃描當前正在編輯的文件的所有父目錄,並查找具有.sln
擴展名的文件。
如果YCM加載包含CSharpSolutionFile
函數的.ycm_extra_conf.py
,則YCM將嘗試使用它來確定解決方案文件。當一個人想覆蓋默認行為並指定不在當前編輯文件的任何父目錄中的解決方案文件時,這很有用。例子:
def CSharpSolutionFile ( filepath ):
# `filepath` is the path of the file user is editing
return '/path/to/solution/file' # Can be relative to the `.ycm_extra_conf.py`
如果CSharpSolutionFile
返回的路徑不是實際文件,則YCM將落後於查找文件的另一種方式。
YCM基於單聲道運行時的舊版本Omnisharp-Roslyn發貨。可以將其與.NET 6.0及更新一起使用,但需要手動設置。
g:ycm_roslyn_binary_path
到未包裝的可執行OmniSharp
dotnet new sln
dotnet sln add <project1.csproj> <project2.csproj> ...
對於所有項目:YcmRestartServer
YCM依靠絕地引擎提供完成和代碼導航。默認情況下,它將選擇運行YCMD服務器的Python版本並使用其sys.path
。雖然這對於簡單的項目很好,但是在使用虛擬環境或具有第三方軟件包的項目中,這需要配置。下一節解釋瞭如何做到這一點。
在Python項目上工作時的一種常見做法是將其依賴項安裝在虛擬環境中,並在該環境中開發項目。為了支持這一點,YCM需要了解虛擬環境的解釋器路徑。您可以通過以下內容在項目根部創建一個.ycm_extra_conf.py
文件來指定它:
def Settings ( ** kwargs ):
return {
'interpreter_path' : '/path/to/virtual/environment/python'
}
這裡, /path/to/virtual/environment/python
是您正在使用的虛擬環境使用的python的路徑。通常,可執行文件可以在Windows和bin
上的虛擬環境目錄的Scripts
文件夾中找到可執行文件其他平台上的文件夾。
如果您不喜歡在項目根部創建.ycm_extra_conf.py
文件,並且寧願使用VIM選項指定解釋器路徑,請通過VIM選項部分讀取配置。
另一個常見的做法是將依賴項直接放入項目中,並在運行時添加其sys.path
的路徑,以便導入它們。需要告知YCM有關此路徑操縱的信息,以支持這些依賴性。這可以通過在項目根部創建.ycm_extra_conf.py
文件來完成。該文件必須定義一個Settings( **kwargs )
函數,該功能返回詞典,其中包含在sys_path
鍵下的sys.path
列表中列出的路徑列表。例如,以下.ycm_extra_conf.py
在sys.path
開始時添加路徑/path/to/some/third_party/package
and /path/to/another/third_party/package
。
def Settings ( ** kwargs ):
return {
'sys_path' : [
'/path/to/some/third_party/package' ,
'/path/to/another/third_party/package'
]
}
如果您寧願使用VIM選項預處sys.path
的路徑,請通過VIM選項部分閱讀配置。
如果您需要進一步控制如何將路徑添加到sys.path
,則應在.ycm_extra_conf.py
文件中定義PythonSysPath( **kwargs )
函數。它的關鍵字參數是sys_path
,其中包含默認的sys.path
和interpreter_path
,這是通往python解釋器的途徑。這是一個瑣碎的示例,該示例將/path/to/third_party/package
路徑在sys.path
的第二個位置:
def PythonSysPath ( ** kwargs ):
sys_path = kwargs [ 'sys_path' ]
sys_path . insert ( 1 , '/path/to/third_party/package' )
return sys_path
可以在YCM自己的.ycm_extra_conf.py
中找到一個更高級的示例。
您可能會發現必須在每個項目的根部創建一個.ycm_extra_conf.py
文件,以便將路徑設置為Python Instrymer和/或添加路徑到sys.path
,並且更願意能夠通過VIM選項配置這些。不用擔心,通過使用g:ycm_extra_conf_vim_data
選項並創建全局額外的配置文件,這是可能的。讓我們舉個例子。假設您要使用g:ycm_python_interpreter_path
選項設置解釋器路徑,並預先將路徑送至sys.path
g:ycm_python_sys_path
選項。還假設您要命名全局額外配置文件global_extra_conf.py
,並且要將其放入主文件夾中。然後,您應該在VIMRC中添加以下幾行:
let g: ycm_python_interpreter_path = ' '
let g: ycm_python_sys_path = []
let g: ycm_extra_conf_vim_data = [
' g:ycm_python_interpreter_path ' ,
' g:ycm_python_sys_path '
]
let g: ycm_global_ycm_extra_conf = ' ~/global_extra_conf.py '
然後,使用以下內容創建~/global_extra_conf.py
文件:
def Settings ( ** kwargs ):
client_data = kwargs [ 'client_data' ]
return {
'interpreter_path' : client_data [ 'g:ycm_python_interpreter_path' ],
'sys_path' : client_data [ 'g:ycm_python_sys_path' ]
}
就是這樣。你完成了。請注意,設置一個選項之一時,您無需重新啟動服務器。 YCM將自動選擇新值。
YCM使用Rust-Analyzer進行生鏽的語義完成。
注意:以前,YCM使用RLS進行生鏽。這不再得到支持,因為生鏽社區已決定將Rust-Analyzer作為生鏽工具的未來。
當前板條箱及其依賴項內的完整和goto命令應在沒有其他配置的情況下進行操作(前提是您將YCM構建為使用--rust-completer
標誌;有關詳細信息,請參見“安裝”部分) 。安裝腳本負責安裝Rust源代碼,因此無需配置。
rust-analyzer
支持無數的選擇。這些是使用LSP配置配置的,並在此處記錄。
完成和goto命令應開箱即用(前提是您使用--go-completer
標誌構建YCM;有關詳細信息,請參見“安裝部分”)。該服務器僅適用於具有“規範”佈局的項目。
gopls
還具有許多記錄的選項。
您可以在.ycm_extra_conf.py
中設置這些設置。例如,設置構建標籤:
def Settings ( ** kwargs ):
if kwargs [ 'language' ] == 'go' :
return {
'ls' : {
'build.buildFlags' : [ '-tags=debug' ] }
}
}
注意: YCM最初將Tern Engine用於JavaScript,但由於其主要作者不再維護Tern,而TSServer引擎提供了更多功能,因此YCM搬到了TSServer。如果您已經使用了Tern,這不會影響您,但是鼓勵您通過刪除YCM文件夾中的third_party/ycmd/third_party/tern_runtime/node_modules
目錄。如果您是新用戶,但仍然想使用Tern,則應在安裝過程中將--js-completer
選項傳遞給install.py
腳本。 Wiki上有有關如何使用Tern設置YCM的進一步說明。
所有JavaScript和TypeScript功能均由TSServer引擎提供,該引擎包含在Typescript SDK中。要啟用這些功能,請安裝node.js 18+和npm,然後使用--ts-completer
標誌調用install.py
腳本。
TSServer依靠jsconfig.json
文件用於JavaScript和tsconfig.json
文件用於分析您的項目。確保文件存在於項目的根源上。
要在JavaScript中獲取診斷,請在jsconfig.json
文件中將checkJs
選項設置為true
:
{
"compilerOptions" : {
"checkJs" : true
}
}
C-family, C#, Go, Java, Python, Rust, and JavaScript/TypeScript languages are supported natively by YouCompleteMe using the Clang, OmniSharp-Roslyn, Gopls, jdt.ls, Jedi, rust-analyzer, and TSServer engines, respectively.檢查安裝部分以獲取說明,如果需要,可以啟用這些功能。
與其他LSP客戶端類似,YCM可以藉助g:ycm_language_server
選項使用任意LSP服務器。此選項值的一個示例是:
let g: ycm_language_server =
[
{
' name ' : ' yaml ' ,
' cmdline ' : [ ' /path/to/yaml/server/yaml-language-server ' , ' --stdio ' ],
' filetypes ' : [ ' yaml ' ]
},
{
' name ' : ' csharp ' ,
' cmdline ' : [ ' OmniSharp ' , ' -lsp ' ],
' filetypes ' : [ ' csharp ' ],
' project_root_files ' : [ ' *.csproj ' , ' *.sln ' ]
},
{
' name ' : ' godot ' ,
' filetypes ' : [ ' gdscript ' ],
' port ' : 6008 ,
' project_root_files ' : [ ' project.godot ' ]
}
]
每個字典都包含以下鍵:
name
(字符串,強制性):配置LSP服務器時, name
鍵的值將用作kwargs[ 'language' ]
。可以是您喜歡的任何東西。filetypes
(字符串列表,強制性):該服務器應使用的VIM Filetypes列表。project_root_files
(字符串列表,可選):試圖確定項目根目錄時要搜索的文件名列表。使用Python的Pathlib進行匹配。cmdline
(字符串列表,可選):如果提供,則使用此命令行啟動服務器(每個列表元素都是命令行字)。通常,服務器應從STDIO通信開始。如果不提供,則必須提供port
。port
(數字,可選):如果提供,YCMD將通過localhost:<port>
使用TCP(不支持遠程服務器)。capabilities
(dict,可選):如果提供,這是與報告給語言服務器的LSP客戶端功能合併的字典。這可用於啟用或禁用某些功能,例如對配置部分的支持( workspace/configuration
)。有關配置PHP,Ruby,Kotlin和D之類的更多示例,請參見LSP示例項目。
許多LSP服務器允許一定程度的用戶配置。 YCM在.ycm_extra_conf.py
文件的幫助下啟用了此功能。這是JDT.LS用戶示例配置PHP,Ruby,Kotlin,D和許多更多內容的示例。
def Settings ( ** kwargs ):
if kwargs [ 'language' ] == 'java' :
return {
'ls' : {
'java.format.onType.enabled' : True
}
}
ls
密鑰告訴YCM,該字典應傳遞給LSP服務器。對於每種LSP服務器的配置,您應該查找相應的服務器的文檔。
一些服務器請求從任意“截面”的配置請求設置。 VIM中沒有配置部分的概念,因此您可以指定附加的config_sections
詞典,該字典將部分映射到服務器要求的配置字典。例如:
def Settings ( ** kwargs ):
if kwargs [ 'language' ] == 'java' :
return {
'ls' : {
'java.format.onType.enabled' : True
},
'config_sections' : {
'some section' : {
'some option' : 'some value'
}
}
這些部分和選項/值是完全特定於服務器的,很少有記錄的。
omnifunc
進行語義完成YCM將使用您的omnifunc
(請參閱:h omnifunc
在VIM中)作為語義完成的來源,如果它沒有用於文件的Filetype的本機語義完成引擎。 VIM帶有各種語言(例如Ruby,PHP等)的Omnifuncs。這取決於語言。
您可以和Eclim一起獲得Ruby的恆星Omnifunc。只需確保您安裝和配置了最新的ECLIM(這意味著Eclim >= 2.2.*
和Eclipse >= 4.2.*
)。
安裝Eclim後,請記住在您的應用程序中創建一個新的Eclipse項目,通過鍵入:ProjectCreate <path-to-your-project> -n ruby
在VIM中,不要忘記let g:EclimCompletionMethod = 'omnifunc'
在您的VIMRC中。這將使YCM和Eclim的表現不錯。 YCM將使用ECLIM的OmniFuncs作為語義完成的數據源,並在其頂部提供自動觸發和基於子序列的匹配(以及其他YCM功能)。
您在這裡有兩個選項:為VIM的OMNICOMPLETE系統編寫omnifunc
,然後將YCM通過其Omni-Commenter使用,或使用完整的API使用YCM的自定義完成器。
這是兩種方法之間的區別:
如果要使用omnifunc
系統,請參見具有:h complete-functions
的相關VIM文檔。有關完成者API,請參見API文檔。
如果您想在YCM的源中上游,則應使用完整的API。
YCM將顯示C家族,C#,GO,Java,JavaScript,Rust和TypeScript語言的診斷通知。由於YCM在輸入時會不斷地重新編譯您的文件,因此您會盡快通知文件中的錯誤和警告。
這是診斷UI的各種部分:
gvim
中的紅色波浪下劃線和vim
中的紅色背景)。下次您按鍵盤上的任何鍵時,將顯示新的診斷(如果有)。因此,如果您停止鍵入並等待新的診斷來進來,那將不起作用。您需要按一些鍵供GUI更新。
不幸的是,必須按鍵以獲取更新是不幸的,但是由於VIM內部設備的運行方式無法更改;背景任務在運行完成後無法更新VIM的GUI。您必須按鍵。這將使YCM檢查是否有任何待處理的診斷更新。
您可以使用:YcmForceCompileAndDiagnostics
命令強制一個完整的阻止彙編週期(您可能需要將該命令映射到鍵;嘗試將nnoremap <F5> :YcmForceCompileAndDiagnostics<CR>
放置在vimrc中)。調用此命令將迫使YCM立即重新編譯您的文件並顯示其遇到的任何新診斷。請注意,使用此命令重新編譯可能需要一段時間,在此期間,VIM GUI將被阻止。
當您將光標移至行中時,YCM將顯示一個簡短的診斷消息。您可以通過<leader>d
鍵映射(可以在選項中更改)獲得詳細的診斷消息,而YCM在光標與診斷線上列入時提供了YCM。
您還可以查看VIM locationlist
中當前文件中所有診斷的完整診斷消息,可以使用:lopen
和:lclose
命令打開(確保您已經設置let g:ycm_always_populate_location_list = 1
在VIMRC中)。通過單個鍵映射切換locationlist
顯示的一種好方法,由另一個(非常小的)VIM插件(稱為ListToggle)提供(這也使您可以更改locationlist
窗口的高度),也可以真正由您的真正編寫。
您可以更改突出顯示組YCM使用的樣式。對於VIM天溝中的標誌,相關組是:
YcmErrorSign
,它屬於SyntasticErrorSign
,然後如果存在error
YcmWarningSign
,它落到了族SyntasticWarningSign
, todo
如果它們存在您還可以為這些組帶有警告/錯誤的行樣式:
YcmErrorLine
,如果存在的話SyntasticErrorLine
它會返回到群YcmWarningLine
,如果存在的話, SyntasticWarningLine
落到了群最後,您還可以使用組YcmErrorPopup
來設置詳細診斷的彈出式彈出窗口(顯示為g:ycm_show_detailed_diag_in_popup
),該組將倒回ErrorMsg
。
請注意,直線突出顯示組僅在設置g:ycm_enable_diagnostic_signs
選項時工作。如果您想要突出顯示的線路,但在VIM天溝中沒有標誌,請在VIMRC中將signcolumn
選項設置為no
:
set signcolumn = no
語法組用於突出顯示帶有錯誤/警告的文本區域:
YcmErrorSection
,如果存在的話,它會歸還到群的SyntasticError
上,然後SpellBad
YcmWarningSection
,如果存在的話,它會落後於組的SyntasticWarning
然後SpellCap
這是您改變小組樣式的方式:
highlight YcmErrorLine guibg = # 3 f0000
此功能需要VIM,並且在Neovim中不支持
YCM提供了一種使用支持語言時在當前項目或文檔中搜索並跳到符號的方法。
當支持GoToSymbol
請求時,您可以在當前工作區中搜索符號,並且在支持GoToDocumentOutline
時的當前文檔。
這是一個快速演示:
如您所見,您可以在鍵入時鍵入和YCM過濾列表。當前的匹配項顯示在屏幕中心的彈出窗口中,您可以選擇帶有鍵盤的條目,以跳到該位置。然後將任何匹配項添加到QuickFix列表中。
啟用:
nmap <something> <Plug>(YCMFindSymbolInWorkspace)
nmap <something> <Plug>(YCMFindSymbolInDocument)
例如
nmap <leader>yfw <Plug>(YCMFindSymbolInWorkspace)
nmap <leader>yfd <Plug>(YCMFindSymbolInDocument)
搜索時,YCM在屏幕頂部打開一個提示緩衝區以獲取輸入,並將您置於插入模式。這意味著您可以擊中<Esc>
進入正常模式並使用及時緩衝器中支持的任何其他輸入命令。當您鍵入字符時,搜索已更新。
最初,從所有開放的菲力元中查詢結果。您可以在彈出窗口打開時點擊<Cf>
以切換到當前的Filetype。
當彈出窗口打開時,以下密鑰被截獲了:
<Cj>
, <Down>
, <Cn>
, <Tab>
- 選擇下一個項目<Ck>
, <Up>
, <Cp>
, <S-Tab>
- 選擇上一項<PageUp>
, <kPageUp>
- 跳起來一個屏幕<PageDown>
, <kPageDown>
- 跳下一個屏幕<Home>
, <kHome>
- 跳到第一項<End>
, <kEnd>
- 跳到最後一項<CR>
- 跳到選定的項目<Cc>
取消/解散彈出式<Cf>
- 切換從所有文件類型或僅當前Filetype產生如果您隨時離開提示緩衝區窗口,也可以取消搜索,則可以使用窗口命令<Cw>...
注意:按下<Esc>
不會關閉彈出窗口 - 您必須使用Ctrl-c
,或使用窗口命令(例如<Ctrl-w>j
)或鼠標離開提示緩衝區窗口。
此功能需要VIM,並且在Neovim中不支持
注意:此功能是高度實驗性的,並希望它有用。請通過報告問題和提供反饋來幫助我們。
YCM提供了一種查看和導航層次結構的方法。支持以下層次結構:
<Plug>(YCMTypeHierarchy)
:在光標下顯示符號的子類型和超級型。向下擴展到亞型,直至超級類型。<Plug>(YCMCallHierarchy)
:在光標下顯示符號的callees和呼叫者。向下擴展到呼叫者,並將其擴展到Callees。看看這個簡短的演示。
層次結構UI可以通過將某些內容映射到指示的插件映射來啟動,例如:
nmap <leader> yth <Plug> (YCMTypeHierarchy)
nmap <leader> ych <Plug> (YCMCallHierarchy)
這打開了一個“模態”彈出窗口,顯示了層次結構中的當前元素。當前的樹根與左側對齊,子和父節點向右擴展。用<Tab> and "up" with
。
樹的“根”可以用<S-Tab>
重新集中在選定的項目中,而進一步的<S-Tab>
將顯示所選項目的父母。這可能需要一些時間來習慣,但是對於當前根的“孩子”實際上可能具有其他無形的父母鏈接,這一點尤其重要。該行上的<S-Tab>
將通過將顯示詞根設置為所選項目來顯示這些內容。
顯示層次結構時,以下鍵被截獲:
<Tab>
:鑽入所選項目的層次結構:展開和顯示所選項目的孩子。<S-Tab>
:向所選項目的父母展示。當應用於子類型時,這將在該類型的類型上重新構建樹,以便所有父型(顯示)。呼叫者類似。<CR>
:跳到當前選擇的符號。<Down>
, <Cn>
, <Cj>
, j
:選擇下一個項目<Up>
, <Cp>
, <Ck>
, k
;選擇上一項注意:您可能會認為呼叫層次結構是倒置的,但是我們認為這種方式更直觀,因為這是顯示呼叫堆棧的典型方式(當前功能在頂部及其下面的呼叫者)。
:YcmRestartServer
命令如果由於某種原因突然停止YCMD完成服務器,則可以使用此命令重新啟動。
:YcmForceCompileAndDiagnostics
命令調用此命令將迫使YCM立即重新編譯您的文件並顯示其遇到的任何新診斷。請注意,使用此命令重新編譯可能需要一段時間,在此期間,VIM GUI將被阻止。
您可能需要將此命令映射到鍵;嘗試將nnoremap <F5> :YcmForceCompileAndDiagnostics<CR>
在您的VIMRC中。
:YcmDiags
命令呼叫此命令將填充VIM的locationlist
如果在您的文件中檢測到任何錯誤或警告,然後將其打開。 If a given error or warning can be fixed by a call to :YcmCompleter FixIt
, then (FixIt available)
is appended to the error or warning text. See the FixIt
completer subcommand for more information.
NOTE: The absence of (FixIt available)
does not strictly imply a fix-it is not available as not all completers are able to provide this indication. For example, the c-sharp completer provides many fix-its but does not add this additional indication.
The g:ycm_open_loclist_on_ycm_diags
option can be used to prevent the location list from opening, but still have it filled with new diagnostic data. See the Options section for details.
:YcmShowDetailedDiagnostic
commandThis command shows the full diagnostic text when the user's cursor is on the line with the diagnostic.
An options argument can be passed. If the argument is popup
the diagnostic text will be displayed in a popup at the cursor position.
If you prefer the detailed diagnostic to always be shown in a popup, then let g:ycm_show_detailed_diag_in_popup=1
.
:YcmDebugInfo
commandThis will print out various debug information for the current file. Useful to see what compile commands will be used for the file if you're using the semantic completion engine.
:YcmToggleLogs
command This command presents the list of logfiles created by YCM, the ycmd server, and the semantic engine server for the current filetype, if any. One of these logfiles can be opened in the editor (or closed if already open) by entering the corresponding number or by clicking on it with the mouse. Additionally, this command can take the logfile names as arguments. Use the <TAB>
key (or any other key defined by the wildchar
option) to complete the arguments or to cycle through them (depending on the value of the wildmode
option). Each logfile given as an argument is directly opened (or closed if already open) in the editor. Only for debugging purposes.
:YcmCompleter
commandThis command gives access to a number of additional IDE-like features in YCM, for things like semantic GoTo, type information, FixIt, and refactoring.
This command accepts a range that can either be specified through a selection in one of Vim's visual modes (see :h visual-use
) or on the command line. For instance, :2,5YcmCompleter
will apply the command from line 2 to line 5. This is useful for the Format
subcommand.
Call YcmCompleter
without further arguments for a list of the commands you can call for the current completer.
See the file type feature summary for an overview of the features available for each file type. See the YcmCompleter subcommands section for more information on the available subcommands and their usage.
Some commands, like Format
accept a range, like :%YcmCompleter Format
.
Some commands like GetDoc
and the various GoTo
commands respect modifiers, like :rightbelow YcmCompleter GetDoc
, :vertical YcmCompleter GoTo
.
NOTE: See the docs for the YcmCompleter
command before tackling this section.
The invoked subcommand is automatically routed to the currently active semantic completer, so :YcmCompleter GoToDefinition
will invoke the GoToDefinition
subcommand on the Python semantic completer if the currently active file is a Python one and on the Clang completer if the currently active file is a C-family language one.
You may also want to map the subcommands to something less verbose; for instance, nnoremap <leader>jd :YcmCompleter GoTo<CR>
maps the <leader>jd
sequence to the longer subcommand invocation.
These commands are useful for jumping around and exploring code. When moving the cursor, the subcommands add entries to Vim's jumplist
so you can use CTRL-O
to jump back to where you were before invoking the command (and CTRL-I
to jump forward; see :h jumplist
for details). If there is more than one destination, the quickfix list (see :h quickfix
) is populated with the available locations and opened to the full width at the bottom of the screen. You can change this behavior by using the YcmQuickFixOpened
autocommand.
GoToInclude
subcommandLooks up the current line for a header and jumps to it.
Supported in filetypes: c, cpp, objc, objcpp, cuda
GoToAlternateFile
subcommandJump to the associated file, as defined by the language server. Typically this will jump you to the associated header file for a C or C++ translation unit.
Supported in filetypes: c, cpp, objc, objcpp, cuda
(clangd only)
GoToDeclaration
subcommandLooks up the symbol under the cursor and jumps to its declaration.
Supported in filetypes: c, cpp, objc, objcpp, cuda, cs, go, java, javascript, python, rust, typescript
GoToDefinition
subcommandLooks up the symbol under the cursor and jumps to its definition.
NOTE: For C-family languages this only works in certain situations , namely when the definition of the symbol is in the current translation unit. A translation unit consists of the file you are editing and all the files you are including with #include
directives (directly or indirectly) in that file.
Supported in filetypes: c, cpp, objc, objcpp, cuda, cs, go, java, javascript, python, rust, typescript
GoTo
subcommandThis command tries to perform the "most sensible" GoTo operation it can. Currently, this means that it tries to look up the symbol under the cursor and jumps to its definition if possible; if the definition is not accessible from the current translation unit, jumps to the symbol's declaration. For C-family languages, it first tries to look up the current line for a header and jump to it. For C#, implementations are also considered and preferred.
Supported in filetypes: c, cpp, objc, objcpp, cuda, cs, go, java, javascript, python, rust, typescript
GoToImprecise
subcommandWARNING: This command trades correctness for speed!
Same as the GoTo
command except that it doesn't recompile the file with libclang before looking up nodes in the AST. This can be very useful when you're editing files that take time to compile but you know that you haven't made any changes since the last parse that would lead to incorrect jumps. When you're just browsing around your codebase, this command can spare you quite a bit of latency.
Supported in filetypes: c, cpp, objc, objcpp, cuda
GoToSymbol <symbol query>
subcommandFinds the definition of all symbols matching a specified string. Note that this does not use any sort of smart/fuzzy matching. However, an interactive symbol search is also available.
Supported in filetypes: c, cpp, objc, objcpp, cuda, cs, java, javascript, python, typescript
GoToReferences
subcommandThis command attempts to find all of the references within the project to the identifier under the cursor and populates the quickfix list with those locations.
Supported in filetypes: c, cpp, objc, objcpp, cuda, java, javascript, python, typescript, rust
GoToImplementation
subcommandLooks up the symbol under the cursor and jumps to its implementation (ie non-interface). If there are multiple implementations, instead provides a list of implementations to choose from.
Supported in filetypes: cs, go, java, rust, typescript, javascript
GoToImplementationElseDeclaration
subcommandLooks up the symbol under the cursor and jumps to its implementation if one, else jump to its declaration. If there are multiple implementations, instead provides a list of implementations to choose from.
Supported in filetypes: cs
GoToType
subcommandLooks up the symbol under the cursor and jumps to the definition of its type eg if the symbol is an object, go to the definition of its class.
Supported in filetypes: go, java, javascript, typescript
GoToDocumentOutline
subcommandProvides a list of symbols in the current document, in the quickfix list. See also interactive symbol search.
Supported in filetypes: c, cpp, objc, objcpp, cuda, go, java, rust
GoToCallers
and GoToCallees
subcommandsNote: A much more powerful call and type hierarchy can be viewd interactively. See interactive type and call hierarchy.
Populate the quickfix list with the callers, or callees respectively, of the function associated with the current cursor position. The semantics of this differ depending on the filetype and language server.
Only supported for LSP servers that provide the callHierarchyProvider
capability.
These commands are useful for finding static information about the code, such as the types of variables, viewing declarations, and documentation strings.
GetType
subcommandEchos the type of the variable or method under the cursor, and where it differs, the derived type.
例如:
std::string s;
Invoking this command on s
returns std::string => std::basic_string<char>
NOTE: Causes re-parsing of the current translation unit.
Supported in filetypes: c, cpp, objc, objcpp, cuda, java, javascript, go, python, typescript, rust
GetTypeImprecise
subcommandWARNING: This command trades correctness for speed!
Same as the GetType
command except that it doesn't recompile the file with libclang before looking up nodes in the AST. This can be very useful when you're editing files that take time to compile but you know that you haven't made any changes since the last parse that would lead to incorrect type. When you're just browsing around your codebase, this command can spare you quite a bit of latency.
Supported in filetypes: c, cpp, objc, objcpp, cuda
GetParent
subcommandEchos the semantic parent of the point under the cursor.
The semantic parent is the item that semantically contains the given position.
例如:
class C {
void f ();
};
void C::f () {
}
In the out-of-line definition of C::f
, the semantic parent is the class C
, of which this function is a member.
In the example above, both declarations of C::f
have C
as their semantic context, while the lexical context of the first C::f
is C
and the lexical context of the second C::f
is the translation unit.
For global declarations, the semantic parent is the translation unit.
NOTE: Causes re-parsing of the current translation unit.
Supported in filetypes: c, cpp, objc, objcpp, cuda
GetDoc
subcommandDisplays the preview window populated with quick info about the identifier under the cursor. Depending on the file type, this includes things like:
The documentation is opened in the preview window, and options like previewheight
are respected. If you would like to customise the height and position of this window, we suggest a custom command that:
previewheight
temporarilyGetDoc
command with supplied modifierspreviewheight
.例如:
command - count ShowDocWithSize
let g: ph = & previewheight
<bar> set previewheight = <count>
<bar> <mods> YcmCompleter GetDoc
<bar> let & previewheight = g: ph
You can then use something like :botright vertical 80ShowDocWithSize
. Here's an example of that: https://asciinema.org/a/hE6Pi1gU6omBShwFna8iwGEe9
Supported in filetypes: c, cpp, objc, objcpp, cuda, cs, go, java, javascript, python, typescript, rust
GetDocImprecise
subcommandWARNING: This command trades correctness for speed!
Same as the GetDoc
command except that it doesn't recompile the file with libclang before looking up nodes in the AST. This can be very useful when you're editing files that take long to compile but you know that you haven't made any changes since the last parse that would lead to incorrect docs. When you're just browsing around your codebase, this command can spare you quite a bit of latency.
Supported in filetypes: c, cpp, objc, objcpp, cuda
These commands make changes to your source code in order to perform refactoring or code correction. YouCompleteMe does not perform any action which cannot be undone, and never saves or writes files to the disk.
FixIt
subcommandWhere available, attempts to make changes to the buffer to correct diagnostics, or perform refactoring, on the current line or selection. Where multiple suggestions are available (such as when there are multiple ways to resolve a given warning, or where multiple diagnostics are reported for the current line, or multiple refactoring tweaks are available), the options are presented and one can be selected.
Completers that provide diagnostics may also provide trivial modifications to the source in order to correct the diagnostic. Examples include syntax errors such as missing trailing semi-colons, spurious characters, or other errors which the semantic engine can deterministically suggest corrections. A small demo presenting how diagnostics can be fixed with clangd:
Completers (LSPs) may also provide refactoring tweaks, which may be available even when no diagnostic is presented for the current line. These include function extraction, variable extraction, switch
population, constructor generation, ... The tweaks work for a selection as well. Consult your LSP for available refactorings. A demonstration of refactoring capabilities with clangd:
If no fix-it is available for the current line, or there is no diagnostic on the current line, this command has no effect on the current buffer. If any modifications are made, the number of changes made to the buffer is echo'd and the user may use the editor's undo command to revert.
When a diagnostic is available, and g:ycm_echo_current_diagnostic
is enabled, then the text (FixIt)
is appended to the echo'd diagnostic when the completer is able to add this indication. The text (FixIt available)
is also appended to the diagnostic text in the output of the :YcmDiags
command for any diagnostics with available fix-its (where the completer can provide this indication).
NOTE: Causes re-parsing of the current translation unit.
Supported in filetypes: c, cpp, objc, objcpp, cuda, cs, go, java, javascript, rust, typescript
RefactorRename <new name>
subcommandIn supported file types, this command attempts to perform a semantic rename of the identifier under the cursor. This includes renaming declarations, definitions, and usages of the identifier, or any other language-appropriate action. The specific behavior is defined by the semantic engine in use.
Similar to FixIt
, this command applies automatic modifications to your source files. Rename operations may involve changes to multiple files, which may or may not be open in Vim buffers at the time. YouCompleteMe handles all of this for you. The behavior is described in the following section.
Supported in filetypes: c, cpp, objc, objcpp, cuda, java, javascript, python, typescript, rust, cs
The following additional commands are supported for Python:
RefactorInline
RefactorExtractVariable
RefactorExtractFunction
See the jedi docs for what they do.
Supported in filetypes: python
When a Refactor or FixIt command touches multiple files, YouCompleteMe attempts to apply those modifications to any existing open, visible buffer in the current tab. If no such buffer can be found, YouCompleteMe opens the file in a new small horizontal split at the top of the current window, applies the change, and then hides the window. NOTE: The buffer remains open, and must be manually saved. A confirmation dialog is opened prior to doing this to remind you that this is about to happen.
Once the modifications have been made, the quickfix list (see :help quickfix
) is populated with the locations of all modifications. This can be used to review all automatic changes made by using :copen
. Typically, use the CTRL-W <enter>
combination to open the selected file in a new split. It is possible to customize how the quickfix window is opened by using the YcmQuickFixOpened
autocommand.
The buffers are not saved automatically. That is, you must save the modified buffers manually after reviewing the changes from the quickfix list. Changes can be undone using Vim's powerful undo features (see :help undo
). Note that Vim's undo is per-buffer, so to undo all changes, the undo commands must be applied in each modified buffer separately.
NOTE: While applying modifications, Vim may find files that are already open and have a swap file. The command is aborted if you select Abort or Quit in any such prompts. This leaves the Refactor operation partially complete and must be manually corrected using Vim's undo features. The quickfix list is not populated in this case. Inspect :buffers
or equivalent (see :help buffers
) to see the buffers that were opened by the command.
Format
subcommand This command formats the whole buffer or some part of it according to the value of the Vim options shiftwidth
and expandtab
(see :h 'sw'
and :h et
respectively). To format a specific part of your document, you can either select it in one of Vim's visual modes (see :h visual-use
) and run the command or directly enter the range on the command line, eg :2,5YcmCompleter Format
to format it from line 2 to line 5.
Supported in filetypes: c, cpp, objc, objcpp, cuda, java, javascript, go, typescript, rust, cs
OrganizeImports
subcommandThis command removes unused imports and sorts imports in the current file. It can also group imports from the same module in TypeScript and resolve imports in Java.
Supported in filetypes: java, javascript, typescript
These commands are for general administration, rather than IDE-like features. They cover things like the semantic engine server instance and compilation flags.
ExecuteCommand <args>
subcommandSome LSP completers (currently only Java completers) support executing server-specific commands. Consult the jdt.ls documentation to find out what commands are supported and which arguments are expected.
The support for ExecuteCommand
was implemented to support plugins like Vimspector to debug java, but isn't limited to that specific use case.
RestartServer
subcommandRestarts the downstream semantic engine server for those semantic engines that work as separate servers that YCM talks to.
Supported in filetypes: c, cpp, objc, objcpp, cuda, cs, go, java, javascript, rust, typescript
ReloadSolution
subcommandInstruct the Omnisharp-Roslyn server to clear its cache and reload all files from the disk. This is useful when files are added, removed, or renamed in the solution, files are changed outside of Vim, or whenever Omnisharp-Roslyn cache is out-of-sync.
Supported in filetypes: cs
youcompleteme#GetErrorCount
functionGet the number of YCM Diagnostic errors. If no errors are present, this function returns 0.
例如:
call youcompleteme#GetErrorCount ()
Both this function and youcompleteme#GetWarningCount
can be useful when integrating YCM with other Vim plugins. For example, a lightline user could add a diagnostics section to their statusline which would display the number of errors and warnings.
youcompleteme#GetWarningCount
functionGet the number of YCM Diagnostic warnings. If no warnings are present, this function returns 0.
例如:
call youcompleteme#GetWarningCount ()
youcompleteme#GetCommandResponse( ... )
function Run a completer subcommand and return the result as a string. This can be useful for example to display the GetDoc
output in a popup window, eg:
let s: ycm_hover_popup = -1
function s: Hover ()
let response = youcompleteme#GetCommandResponse ( ' GetDoc ' )
if response == ' '
return
endif
call popup_hide ( s: ycm_hover_popup )
let s: ycm_hover_popup = popup_atcursor ( balloon_split ( response ), {} )
endfunction
" CursorHold triggers in normal mode after a delay
autocmd CursorHold * call s: Hover ()
" Or, if you prefer, a mapping:
nnoremap <silent> <leader> D :call <SID> Hover() <CR>
NOTE : This is only an example, for real hover support, see g:ycm_auto_hover
.
If the completer subcommand result is not a string (for example, it's a FixIt or a Location), or if the completer subcommand raises an error, an empty string is returned, so that calling code does not have to check for complex error conditions.
The arguments to the function are the same as the arguments to the :YcmCompleter
ex command, eg the name of the subcommand, followed by any additional subcommand arguments. As with the YcmCompleter
command, if the first argument is ft=<filetype>
the request is targeted at the specified filetype completer. This is an advanced usage and not necessary in most cases.
NOTE: The request is run synchronously and blocks Vim until the response is received, so we do not recommend running this as part of an autocommand that triggers frequently.
youcompleteme#GetCommandResponseAsync( callback, ... )
function This works exactly like youcompleteme#GetCommandResponse
, except that instead of returning the result, you supply a callback
argument. This argument must be a FuncRef
to a function taking a single argument response
. This callback will be called with the command response at some point later, or immediately.
As with youcompleteme#GetCommandResponse()
, this function will call the callback with ''
(an empty string) if the request is not sent, or if there was some sort of error.
Here's an example that's similar to the one above:
let s: ycm_hover_popup = -1
function ! s: ShowDataPopup ( response ) abort
if response == ' '
return
endif
call popup_hide ( s: ycm_hover_popup )
let s: ycm_hover_popup = popup_atcursor ( balloon_split ( response ), {} )
endfunction
function ! s: GetData () abort
call youcompleteme#GetCommandResponseAsync (
function ( ' s:ShowDataPopup ' ),
' GetDoc ' )
endfunction
autocommand CursorHold * call s: GetData ()
Again, see g:ycm_auto_hover
for proper hover support.
NOTE : The callback may be called immediately, in the stack frame that called this function.
NOTE : Only one command request can be outstanding at once. Attempting to request a second response while the first is outstanding will result in the second callback being immediately called with ''
.
YcmLocationOpened
autocommand This User
autocommand is fired when YCM opens the location list window in response to the YcmDiags
command. By default, the location list window is opened to the bottom of the current window and its height is set to fit all entries. This behavior can be overridden by using the YcmLocationOpened
autocommand which is triggered while the cursor is in the location list window.例如:
function ! s: CustomizeYcmLocationWindow ()
" Move the window to the top of the screen.
wincmd K
" Set the window height to 5.
5 wincmd _
" Switch back to the working window.
wincmd p
endfunction
autocmd User YcmLocationOpened call s: CustomizeYcmLocationWindow ()
YcmQuickFixOpened
autocommand This User
autocommand is fired when YCM opens the quickfix window in response to the GoTo*
and RefactorRename
subcommands. By default, the quickfix window is opened to full width at the bottom of the screen and its height is set to fit all entries. This behavior can be overridden by using the YcmQuickFixOpened
autocommand which is triggered while the cursor is in the quickfix window.例如:
function ! s: CustomizeYcmQuickFixWindow ()
" Move the window to the top of the screen.
wincmd K
" Set the window height to 5.
5 wincmd _
endfunction
autocmd User YcmQuickFixOpened call s: CustomizeYcmQuickFixWindow ()
All options have reasonable defaults so if the plug-in works after installation you don't need to change any options. These options can be configured in your vimrc script by including a line like this:
let g: ycm_min_num_of_chars_for_completion = 1
Note that after changing an option in your vimrc script you have to restart ycmd with the :YcmRestartServer
command for the changes to take effect.
g:ycm_min_num_of_chars_for_completion
option This option controls the number of characters the user needs to type before identifier-based completion suggestions are triggered. For example, if the option is set to 2
, then when the user types a second alphanumeric character after a whitespace character, completion suggestions will be triggered. This option is NOT used for semantic completion.
Setting this option to a high number like 99
effectively turns off the identifier completion engine and just leaves the semantic engine.
默認值: 2
let g: ycm_min_num_of_chars_for_completion = 2
g:ycm_min_num_identifier_candidate_chars
optionThis option controls the minimum number of characters that a completion candidate coming from the identifier completer must have to be shown in the popup menu.
A special value of 0
means there is no limit.
NOTE: This option only applies to the identifier completer; it has no effect on the various semantic completers.
默認值: 0
let g: ycm_min_num_identifier_candidate_chars = 0
g:ycm_max_num_candidates
option This option controls the maximum number of semantic completion suggestions shown in the completion menu. This only applies to suggestions from semantic completion engines; see the g:ycm_max_identifier_candidates
option to limit the number of suggestions from the identifier-based engine.
A special value of 0
means there is no limit.
NOTE: Setting this option to 0
or to a value greater than 100
is not recommended as it will slow down completion when there is a very large number of suggestions.
默認值: 50
let g: ycm_max_num_candidates = 50
g:ycm_max_num_candidates_to_detail
option Some completion engines require completion candidates to be 'resolved' in order to get detailed info such as inline documentation, method signatures, etc. This information is displayed by YCM in the preview window, or if completeopt
contains popup
, in the info popup next to the completion menu.
By default, if the info popup is in use, and there are more than 10 candidates, YCM will defer resolving candidates until they are selected in the completion menu. Otherwise, YCM must resolve the details upfront, which can be costly.
If neither popup
nor preview
are in completeopt
, YCM disables resolving altogether as the information would not be displayed.
This setting can be used to override these defaults and controls the number of completion candidates that should be resolved upfront. Typically users do not need to change this, as YCM will work out an appropriate value based on your completeopt
and g:ycm_add_preview_to_completeopt
settings. However, you may override this calculation by setting this value to a number:
-1
- Resolve all candidates upfront0
- Never resolve any candidates upfront.> 0
- Resolve up to this many candidates upfront. If the number of candidates is greater than this value, no candidates are resolved. In the latter two cases, if completeopt
contains popup
, then candidates are resolved on demand asynchronously.
預設:
0
if neither popup
nor preview
are in completeopt
.10
if popup
is in completeopt.-1
if preview
is in completeopt.例子:
let g: ycm_max_num_candidates_to_detail = 0
g:ycm_max_num_identifier_candidates
optionThis option controls the maximum number of completion suggestions from the identifier-based engine shown in the completion menu.
A special value of 0
means there is no limit.
NOTE: Setting this option to 0
or to a value greater than 100
is not recommended as it will slow down completion when there is a very large number of suggestions.
默認值: 10
let g: ycm_max_num_identifier_candidates = 10
g:ycm_auto_trigger
option When set to 0
, this option turns off YCM's identifier completer (the as-you-type popup) and the semantic triggers (the popup you'd get after typing .
or ->
in say C++). You can still force semantic completion with the <C-Space>
shortcut.
If you want to just turn off the identifier completer but keep the semantic triggers, you should set g:ycm_min_num_of_chars_for_completion
to a high number like 99
.
When g:ycm_auto_trigger
is 0
, YCM sets the completefunc
, so that you can manually trigger normal completion using Cx Cu
.
If you want to map something else to trigger completion, such as Cd
, then you can map it to <plug>(YCMComplete)
.例如:
let g: ycm_auto_trigger = 0
imap <c-d> <plug> (YCMComplete)
NOTE: It's not possible to map one of the keys in g:ycm_key_list_select_completion
(or similar) to <plug>(YCMComplete)
. In practice that means that you can't use <Tab>
for this.
默認值: 1
let g: ycm_auto_trigger = 1
g:ycm_filetype_whitelist
option This option controls for which Vim filetypes (see :h filetype
) should YCM be turned on. The option value should be a Vim dictionary with keys being filetype strings (like python
, cpp
, etc.) and values being unimportant (the dictionary is used like a hash set, meaning that only the keys matter).
The *
key is special and matches all filetypes. By default, the whitelist contains only this *
key.
YCM also has a g:ycm_filetype_blacklist
option that lists filetypes for which YCM shouldn't be turned on. YCM will work only in filetypes that both the whitelist and the blacklist allow (the blacklist "allows" a filetype by not having it as a key).
For example, let's assume you want YCM to work in files with the cpp
filetype. The filetype should then be present in the whitelist either directly ( cpp
key in the whitelist) or indirectly through the special *
key. It should not be present in the blacklist.
Filetypes that are blocked by either of the lists will be completely ignored by YCM, meaning that neither the identifier-based completion engine nor the semantic engine will operate in them.
You can get the filetype of the current file in Vim with :set ft?
。
Default: {'*': 1}
let g: ycm_filetype_whitelist = { ' * ' : 1 }
** Completion in buffers with no filetype **
There is one exception to the above rule. YCM supports completion in buffers with no filetype set, but this must be explicitly whitelisted. To identify buffers with no filetype, we use the ycm_nofiletype
pseudo-filetype. To enable completion in buffers with no filetype, set:
let g: ycm_filetype_whitelist = {
' * ' : 1 ,
' ycm_nofiletype ' : 1
}
g:ycm_filetype_blacklist
option This option controls for which Vim filetypes (see :h filetype
) should YCM be turned off. The option value should be a Vim dictionary with keys being filetype strings (like python
, cpp
, etc.) and values being unimportant (the dictionary is used like a hash set, meaning that only the keys matter).
See the g:ycm_filetype_whitelist
option for more details on how this works.
Default: [see next line]
let g: ycm_filetype_blacklist = {
' tagbar ' : 1 ,
' notes ' : 1 ,
' markdown ' : 1 ,
' netrw ' : 1 ,
' unite ' : 1 ,
' text ' : 1 ,
' vimwiki ' : 1 ,
' pandoc ' : 1 ,
' infolog ' : 1 ,
' leaderf ' : 1 ,
' mail ' : 1
}
In addition, ycm_nofiletype
(representing buffers with no filetype set) is blacklisted if ycm_nofiletype
is not explicitly whitelisted (using g:ycm_filetype_whitelist
).
g:ycm_filetype_specific_completion_to_disable
option This option controls for which Vim filetypes (see :h filetype
) should the YCM semantic completion engine be turned off. The option value should be a Vim dictionary with keys being filetype strings (like python
, cpp
, etc.) and values being unimportant (the dictionary is used like a hash set, meaning that only the keys matter). The listed filetypes will be ignored by the YCM semantic completion engine, but the identifier-based completion engine will still trigger in files of those filetypes.
Note that even if semantic completion is not turned off for a specific filetype, you will not get semantic completion if the semantic engine does not support that filetype.
You can get the filetype of the current file in Vim with :set ft?
。
Default: [see next line]
let g: ycm_filetype_specific_completion_to_disable = {
' gitcommit ' : 1
}
g:ycm_filepath_blacklist
option This option controls for which Vim filetypes (see :h filetype
) should filepath completion be disabled. The option value should be a Vim dictionary with keys being filetype strings (like python
, cpp
, etc.) and values being unimportant (the dictionary is used like a hash set, meaning that only the keys matter).
The *
key is special and matches all filetypes. Use this key if you want to completely disable filepath completion:
let g: ycm_filepath_blacklist = { ' * ' : 1 }
You can get the filetype of the current file in Vim with :set ft?
。
Default: [see next line]
let g: ycm_filepath_blacklist = {
' html ' : 1 ,
' jsx ' : 1 ,
' xml ' : 1 ,
}
g:ycm_show_diagnostics_ui
optionWhen set, this option turns on YCM's diagnostic display features. See the Diagnostic display section in the User Manual for more details.
Specific parts of the diagnostics UI (like the gutter signs, text highlighting, diagnostic echo, and auto location list population) can be individually turned on or off. See the other options below for details.
Note that YCM's diagnostics UI is only supported for C-family languages.
When set, this option also makes YCM remove all Syntastic checkers set for the c
, cpp
, objc
, objcpp
, and cuda
filetypes since this would conflict with YCM's own diagnostics UI.
If you're using YCM's identifier completer in C-family languages but cannot use the clang-based semantic completer for those languages and want to use the GCC Syntastic checkers, unset this option.
默認值: 1
let g: ycm_show_diagnostics_ui = 1
g:ycm_error_symbol
optionYCM will use the value of this option as the symbol for errors in the Vim gutter.
This option is part of the Syntastic compatibility layer; if the option is not set, YCM will fall back to the value of the g:syntastic_error_symbol
option before using this option's default.
Default: >>
let g: ycm_error_symbol = ' >> '
g:ycm_warning_symbol
optionYCM will use the value of this option as the symbol for warnings in the Vim gutter.
This option is part of the Syntastic compatibility layer; if the option is not set, YCM will fall back to the value of the g:syntastic_warning_symbol
option before using this option's default.
Default: >>
let g: ycm_warning_symbol = ' >> '
g:ycm_enable_diagnostic_signs
option When this option is set, YCM will put icons in Vim's gutter on lines that have a diagnostic set. Turning this off will also turn off the YcmErrorLine
and YcmWarningLine
highlighting.
This option is part of the Syntastic compatibility layer; if the option is not set, YCM will fall back to the value of the g:syntastic_enable_signs
option before using this option's default.
默認值: 1
let g: ycm_enable_diagnostic_signs = 1
g:ycm_enable_diagnostic_highlighting
optionWhen this option is set, YCM will highlight regions of text that are related to the diagnostic that is present on a line, if any.
This option is part of the Syntastic compatibility layer; if the option is not set, YCM will fall back to the value of the g:syntastic_enable_highlighting
option before using this option's default.
默認值: 1
let g: ycm_enable_diagnostic_highlighting = 1
g:ycm_echo_current_diagnostic
option When this option is set to 1, YCM will echo the text of the diagnostic present on the current line when you move your cursor to that line. If a FixIt
is available for the current diagnostic, then (FixIt)
is appended.
If you have a Vim that supports virtual text, you can set this option to the string virtual-text
, and the diagnostic will be displayed inline with the text, right aligned in the window and wrapping to the next line if there is not enough space , 例如:
NOTE : It's strongly recommended to also set g:ycm_update_diagnostics_in_insert_mode
to 0
when using virtual-text
for diagnostics. This is due to the increased amount of distraction provided by drawing diagnostics next to your input position.
This option is part of the Syntastic compatibility layer; if the option is not set, YCM will fall back to the value of the g:syntastic_echo_current_error
option before using this option's default.
默認值: 1
有效值:
0
- disabled1
- echo diagnostic to the command area'virtual-text'
- display the dignostic to the right of the line in the window using virtual text let g: ycm_echo_current_diagnostic = 1
" Or, when you have Vim supporting virtual text
let g: ycm_echo_current_diagnostic = ' virtual-text '
g:ycm_auto_hover
optionThis option controls whether or not YCM shows documentation in a popup at the cursor location after a short delay. Only supported in Vim.
When this option is set to 'CursorHold'
, the popup is displayed on the CursorHold
autocommand. See :help CursorHold
for the details, but this means that it is displayed after updatetime
milliseconds. When set to an empty string, the popup is not automatically displayed.
In addition to this setting, there is the <plug>(YCMHover)
mapping, which can be used to manually trigger or hide the popup (it works like a toggle).例如:
nmap <leader> D <plug> (YCMHover)
After dismissing the popup with this mapping, it will not be automatically triggered again until the cursor is moved (ie CursorMoved
autocommand).
The displayed documentation depends on what the completer for the current language supports. It's selected heuristically in this order of preference:
GetHover
with markdown
syntaxGetDoc
with no syntaxGetType
with the syntax of the current file. You can customise this by manually setting up b:ycm_hover
to your liking. This buffer-local variable can be set to a dictionary with the following keys:
command
: The YCM completer subcommand which should be run on hoversyntax
: The syntax to use (as in set syntax=
) in the popup window for highlighting.popup_params
: The params passed to a popup window which gets opened.For example, to use C/C++ syntax highlighting in the popup for C-family languages, add something like this to your vimrc:
augroup MyYCMCustom
autocmd !
autocmd FileType c,cpp let b: ycm_hover = {
' command ' : ' GetDoc ' ,
' syntax ' : & filetype
}
augroup END
You can also modify the opened popup with popup_params
key. For example, you can limit the popup's maximum width and add a border to it:
augroup MyYCMCustom
autocmd !
autocmd FileType c,cpp let b: ycm_hover = {
' command ' : ' GetDoc ' ,
' syntax ' : & filetype
' popup_params ' : {
' maxwidth ' : 80 ,
' border ' : [],
' borderchars ' : [ ' ─ ' , ' │ ' , ' ─ ' , ' │ ' , ' ┌ ' , ' ┐ ' , ' ┘ ' , ' └ ' ],
},
}
augroup END
See :help popup_create-arguments
for the list of available popup window options.
Default: 'CursorHold'
g:ycm_filter_diagnostics
optionThis option controls which diagnostics will be rendered by YCM. This option holds a dictionary of key-values, where the keys are Vim's filetype strings delimited by commas and values are dictionaries describing the filter.
A filter is a dictionary of key-values, where the keys are the type of filter, and the value is a list of arguments to that filter. In the case of just a single item in the list, you may omit the brackets and just provide the argument directly. If any filter matches a diagnostic, it will be dropped and YCM will not render it.
The following filter types are supported:
re.search
, not re.match
)level: "error"
will remove all errors from the diagnostics.NOTE: The regex syntax is NOT Vim's, it's Python's.
預設: {}
The following example will do, for Java filetype only:
ta<something>co
let g: ycm_filter_diagnostics = {
" java " : {
" regex " : [ " ta.+co " , ... ],
" level " : " error " ,
...
}
}
g:ycm_always_populate_location_list
optionWhen this option is set, YCM will populate the location list automatically every time it gets new diagnostic data. This option is off by default so as not to interfere with other data you might have placed in the location list.
See :help location-list
in Vim to learn more about the location list.
This option is part of the Syntastic compatibility layer; if the option is not set, YCM will fall back to the value of the g:syntastic_always_populate_loc_list
option before using this option's default.
Note: if YCM's errors aren't visible, it might be that YCM is updating an older location list. See :help :lhistory
and :lolder
.
默認值: 0
let g: ycm_always_populate_location_list = 0
g:ycm_open_loclist_on_ycm_diags
option When this option is set, :YcmDiags
will automatically open the location list after forcing a compilation and filling the list with diagnostic data.
See :help location-list
in Vim to learn more about the location list.
默認值: 1
let g: ycm_open_loclist_on_ycm_diags = 1
g:ycm_complete_in_comments
option When this option is set to 1
, YCM will show the completion menu even when typing inside comments.
默認值: 0
let g: ycm_complete_in_comments = 0
g:ycm_complete_in_strings
option When this option is set to 1
, YCM will show the completion menu even when typing inside strings.
Note that this is turned on by default so that you can use the filename completion inside strings. This is very useful for instance in C-family files where typing #include "
will trigger the start of filename completion. If you turn off this option, you will turn off filename completion in such situations as well.
默認值: 1
let g: ycm_complete_in_strings = 1
g:ycm_collect_identifiers_from_comments_and_strings
option When this option is set to 1
, YCM's identifier completer will also collect identifiers from strings and comments. Otherwise, the text in comments and strings will be ignored.
默認值: 0
let g: ycm_collect_identifiers_from_comments_and_strings = 0
g:ycm_collect_identifiers_from_tags_files
option When this option is set to 1
, YCM's identifier completer will also collect identifiers from tags files. The list of tags files to examine is retrieved from the tagfiles()
Vim function which examines the tags
Vim option. See :h 'tags'
for details.
YCM will re-index your tags files if it detects that they have been modified.
The only supported tag format is the Exuberant Ctags format. The format from "plain" ctags is NOT supported. Ctags needs to be called with the --fields=+l
option (that's a lowercase L
, not a one) because YCM needs the language:<lang>
field in the tags output.
See the FAQ for pointers if YCM does not appear to read your tag files.
This option is off by default because it makes Vim slower if your tags are on a network directory.
默認值: 0
let g: ycm_collect_identifiers_from_tags_files = 0
g:ycm_seed_identifiers_with_syntax
option When this option is set to 1
, YCM's identifier completer will seed its identifier database with the keywords of the programming language you're writing.
Since the keywords are extracted from the Vim syntax file for the filetype, all keywords may not be collected, depending on how the syntax file was written. Usually at least 95% of the keywords are successfully extracted.
默認值: 0
let g: ycm_seed_identifiers_with_syntax = 0
g:ycm_extra_conf_vim_data
option If you're using semantic completion for C-family files, this option might come handy; it's a way of sending data from Vim to your Settings
function in your .ycm_extra_conf.py
file.
This option is supposed to be a list of VimScript expression strings that are evaluated for every request to the ycmd server and then passed to your Settings
function as a client_data
keyword argument.
For instance, if you set this option to ['v:version']
, your Settings
function will be called like this:
# The '801' value is of course contingent on Vim 8.1; in 8.0 it would be '800'
Settings ( ..., client_data = { 'v:version' : 801 } )
So the client_data
parameter is a dictionary mapping Vim expression strings to their values at the time of the request.
The correct way to define parameters for your Settings
function:
def Settings ( ** kwargs ):
You can then get to client_data
with kwargs['client_data']
.
預設: []
let g: ycm_extra_conf_vim_data = []
g:ycm_server_python_interpreter
optionYCM will by default search for an appropriate Python interpreter on your system. You can use this option to override that behavior and force the use of a specific interpreter of your choosing.
NOTE: This interpreter is only used for the ycmd server. The YCM client running inside Vim always uses the Python interpreter that's embedded inside Vim.
預設: ''
let g: ycm_server_python_interpreter = ' '
g:ycm_keep_logfiles
option When this option is set to 1
, YCM and the ycmd completion server will keep the logfiles around after shutting down (they are deleted on shutdown by default).
To see where the log files are, call :YcmDebugInfo
.
默認值: 0
let g: ycm_keep_logfiles = 0
g:ycm_log_level
optionThe logging level that YCM and the ycmd completion server use. Valid values are the following, from most verbose to least verbose:
debug
info
warning
error
critical
Note that debug
is very verbose.
Default: info
let g: ycm_log_level = ' info '
g:ycm_auto_start_csharp_server
option When set to 1
, the OmniSharp-Roslyn server will be automatically started (once per Vim session) when you open a C# file.
默認值: 1
let g: ycm_auto_start_csharp_server = 1
g:ycm_auto_stop_csharp_server
option When set to 1
, the OmniSharp-Roslyn server will be automatically stopped upon closing Vim.
默認值: 1
let g: ycm_auto_stop_csharp_server = 1
g:ycm_csharp_server_port
option When g:ycm_auto_start_csharp_server is set to 1
, specifies the port for the OmniSharp-Roslyn server to listen on. When set to 0
uses an unused port provided by the OS.
默認值: 0
let g: ycm_csharp_server_port = 0
g:ycm_csharp_insert_namespace_expr
option By default, when YCM inserts a namespace, it will insert the using
statement under the nearest using
statement. You may prefer that the using
statement is inserted somewhere, for example, to preserve sorting. If so, you can set this option to override this behavior.
When this option is set, instead of inserting the using
statement itself, YCM will set the global variable g:ycm_namespace_to_insert
to the namespace to insert, and then evaluate this option's value as an expression. The option's expression is responsible for inserting the namespace - the default insertion will not occur.
預設: ''
let g: ycm_csharp_insert_namespace_expr = ' '
g:ycm_add_preview_to_completeopt
option When this option is set to 1
, YCM will add the preview
string to Vim's completeopt
option (see :h completeopt
). If your completeopt
option already has preview
set, there will be no effect. Alternatively, when set to popup
and your version of Vim supports popup windows (see :help popup
), the popup
string will be used instead. You can see the current state of your completeopt
setting with :set completeopt?
(yes, the question mark is important).
When preview
is present in completeopt
, YCM will use the preview
window at the top of the file to store detailed information about the current completion candidate (but only if the candidate came from the semantic engine). For instance, it would show the full function prototype and all the function overloads in the window if the current completion is a function name.
When popup
is present in completeopt
, YCM will instead use a popup
window to the side of the completion popup for storing detailed information about the current completion candidate. In addition, YCM may truncate the detailed completion information in order to give the popup sufficient room to display that detailed information.
默認值: 0
let g: ycm_add_preview_to_completeopt = 0
g:ycm_autoclose_preview_window_after_completion
option When this option is set to 1
, YCM will auto-close the preview
window after the user accepts the offered completion string. If there is no preview
window triggered because there is no preview
string in completeopt
, this option is irrelevant. See the g:ycm_add_preview_to_completeopt
option for more details.
默認值: 0
let g: ycm_autoclose_preview_window_after_completion = 0
g:ycm_autoclose_preview_window_after_insertion
option When this option is set to 1
, YCM will auto-close the preview
window after the user leaves insert mode. This option is irrelevant if g:ycm_autoclose_preview_window_after_completion
is set or if no preview
window is triggered. See the g:ycm_add_preview_to_completeopt
option for more details.
默認值: 0
let g: ycm_autoclose_preview_window_after_insertion = 0
g:ycm_max_diagnostics_to_display
optionThis option controls the maximum number of diagnostics shown to the user when errors or warnings are detected in the file. This option is only relevant for the C-family, C#, Java, JavaScript, and TypeScript languages.
A special value of 0
means there is no limit.
Default: 30
let g: ycm_max_diagnostics_to_display = 30
g:ycm_key_list_select_completion
optionThis option controls the key mappings used to select the first completion string. Invoking any of them repeatedly cycles forward through the completion list.
Some users like adding <Enter>
to this list.
Default: ['<TAB>', '<Down>']
let g: ycm_key_list_select_completion = [ ' <TAB> ' , ' <Down> ' ]
g:ycm_key_list_previous_completion
optionThis option controls the key mappings used to select the previous completion string. Invoking any of them repeatedly cycles backward through the completion list.
Note that one of the defaults is <S-TAB>
which means Shift-TAB. That mapping will probably only work in GUI Vim (Gvim or MacVim) and not in plain console Vim because the terminal usually does not forward modifier key combinations to Vim.
Default: ['<S-TAB>', '<Up>']
let g: ycm_key_list_previous_completion = [ ' <S-TAB> ' , ' <Up> ' ]
g:ycm_key_list_stop_completion
option This option controls the key mappings used to close the completion menu. This is useful when the menu is blocking the view, when you need to insert the <TAB>
character, or when you want to expand a snippet from UltiSnips and navigate through it.
Default: ['<Cy>']
let g: ycm_key_list_stop_completion = [ ' <C-y> ' ]
g:ycm_key_invoke_completion
option This option controls the key mapping used to invoke the completion menu for semantic completion. By default, semantic completion is triggered automatically after typing characters appropriate for the language, such as .
, ->
, ::
, etc. in insert mode (if semantic completion support has been compiled in). This key mapping can be used to trigger semantic completion anywhere. Useful for searching for top-level functions and classes.
Console Vim (not Gvim or MacVim) passes <Nul>
to Vim when the user types <C-Space>
so YCM will make sure that <Nul>
is used in the map command when you're editing in console Vim, and <C-Space>
in GUI Vim. This means that you can just press <C-Space>
in both the console and GUI Vim and YCM will do the right thing.
Setting this option to an empty string will make sure no mapping is created.
Default: <C-Space>
let g: ycm_key_invoke_completion = ' <C-Space> '
g:ycm_key_detailed_diagnostics
option This option controls the key mapping used to show the full diagnostic text when the user's cursor is on the line with the diagnostic. It basically calls :YcmShowDetailedDiagnostic
.
Setting this option to an empty string will make sure no mapping is created.
If you prefer the detailed diagnostic to be shown in a popup, then let g:ycm_show_detailed_diag_in_popup=1
.
Default: <leader>d
let g: ycm_key_detailed_diagnostics = ' <leader>d '
g:ycm_show_detailed_diag_in_popup
option Makes :YcmShowDetailedDiagnostic
always show in a popup rather than echoing to the command line.
默認值:0
let g: ycm_show_detailed_diag_in_popup = 0
g:ycm_global_ycm_extra_conf
option Normally, YCM searches for a .ycm_extra_conf.py
file for compilation flags (see the User Guide for more details on how this works). This option specifies a fallback path to a config file which is used if no .ycm_extra_conf.py
is found.
You can place such a global file anywhere in your filesystem.
預設: ''
let g: ycm_global_ycm_extra_conf = ' '
g:ycm_confirm_extra_conf
option When this option is set to 1
YCM will ask once per .ycm_extra_conf.py
file if it is safe to be loaded. This is to prevent the execution of malicious code from a .ycm_extra_conf.py
file you didn't write.
To selectively get YCM to ask/not ask about loading certain .ycm_extra_conf.py
files, see the g:ycm_extra_conf_globlist
option.
默認值: 1
let g: ycm_confirm_extra_conf = 1
g:ycm_extra_conf_globlist
option This option is a list that may contain several globbing patterns. If a pattern starts with a !
all .ycm_extra_conf.py
files matching that pattern will be blacklisted, that is they won't be loaded and no confirmation dialog will be shown. If a pattern does not start with a !
all files matching that pattern will be whitelisted. Note that this option is not used when confirmation is disabled using g:ycm_confirm_extra_conf
and that items earlier in the list will take precedence over the later ones.
規則:
*
matches everything?
matches any single character[seq]
matches any character in seq[!seq]
matches any char not in seq例子:
let g: ycm_extra_conf_globlist = [ ' ~/dev/* ' , ' !~/* ' ]
~/dev
directory so .ycm_extra_conf.py
files from there will be loaded..ycm_extra_conf.py
file from there won't be loaded.~/dev
directory will be blacklisted. NOTE: The glob pattern is first expanded with Python's os.path.expanduser()
and then resolved with os.path.abspath()
before being matched against the filename.
預設: []
let g: ycm_extra_conf_globlist = []
g:ycm_filepath_completion_use_working_dir
option By default, YCM's filepath completion will interpret relative paths like ../
as being relative to the folder of the file of the currently active buffer. Setting this option will force YCM to always interpret relative paths as being relative to Vim's current working directory.
默認值: 0
let g: ycm_filepath_completion_use_working_dir = 0
g:ycm_semantic_triggers
optionThis option controls the character-based triggers for the various semantic completion engines. The option holds a dictionary of key-values, where the keys are Vim's filetype strings delimited by commas and values are lists of strings, where the strings are the triggers.
Setting key-value pairs on the dictionary adds semantic triggers to the internal default set (listed below). You cannot remove the default triggers, only add new ones.
A "trigger" is a sequence of one or more characters that trigger semantic completion when typed. For instance, C++ ( cpp
filetype) has .
listed as a trigger. So when the user types foo.
, the semantic engine will trigger and serve foo
's list of member functions and variables. Since C++ also has ->
listed as a trigger, the same thing would happen when the user typed foo->
.
It's also possible to use a regular expression as a trigger. You have to prefix your trigger with re!
to signify it's a regex trigger. For instance, re!w+.
would only trigger after the w+.
regex matches.
NOTE: The regex syntax is NOT Vim's, it's Python's.
Default: [see next line]
let g: ycm_semantic_triggers = {
' c ' : [ ' -> ' , ' . ' ],
' objc ' : [ ' -> ' , ' . ' , ' re![[_a-zA-Z]+w*s ' , ' re!^s*[^Wd]w*s ' ,
' re![.*]s ' ],
' ocaml ' : [ ' . ' , ' # ' ],
' cpp,cuda,objcpp ' : [ ' -> ' , ' . ' , ' :: ' ],
' perl ' : [ ' -> ' ],
' php ' : [ ' -> ' , ' :: ' ],
' cs,d,elixir,go,groovy,java,javascript,julia,perl6,python,scala,typescript,vb ' : [ ' . ' ],
' ruby,rust ' : [ ' . ' , ' :: ' ],
' lua ' : [ ' . ' , ' : ' ],
' erlang ' : [ ' : ' ],
}
g:ycm_cache_omnifunc
optionSome omnicompletion engines do not work well with the YCM cache—in particular, they might not produce all possible results for a given prefix. By unsetting this option you can ensure that the omnicompletion engine is re-queried on every keypress. That will ensure all completions will be presented but might cause stuttering and lag if the omnifunc is slow.
默認值: 1
let g: ycm_cache_omnifunc = 1
g:ycm_use_ultisnips_completer
optionBy default, YCM will query the UltiSnips plugin for possible completions of snippet triggers. This option can turn that behavior off.
默認值: 1
let g: ycm_use_ultisnips_completer = 1
g:ycm_goto_buffer_command
option Defines where GoTo*
commands result should be opened. Can take one of the following values: 'same-buffer'
, 'split'
, or 'split-or-existing-window'
. If this option is set to the 'same-buffer'
but current buffer can not be switched (when buffer is modified and nohidden
option is set), then result will be opened in a split. When the option is set to 'split-or-existing-window'
, if the result is already open in a window of the current tab page (or any tab pages with the :tab
modifier; see below), it will jump to that窗戶。 Otherwise, the result will be opened in a split as if the option was set to 'split'
.
To customize the way a new window is split, prefix the GoTo*
command with one of the following modifiers: :aboveleft
, :belowright
, :botright
, :leftabove
, :rightbelow
, :topleft
, and :vertical
. For instance, to split vertically to the right of the current window, run the command:
: rightbelow vertical YcmCompleter GoTo
To open in a new tab page, use the :tab
modifier with the 'split'
or 'split-or-existing-window'
options eg:
: tab YcmCompleter GoTo
Default: 'same-buffer'
let g: ycm_goto_buffer_command = ' same-buffer '
g:ycm_disable_for_files_larger_than_kb
optionDefines the max size (in Kb) for a file to be considered for completion. If this option is set to 0 then no check is made on the size of the file you're opening.
Default: 1000
let g: ycm_disable_for_files_larger_than_kb = 1000
g:ycm_use_clangd
option This option controls whether clangd should be used as a completion engine for C-family languages. Can take one of the following values: 1
, 0
, with meanings:
1
: YCM will use clangd if clangd binary exists in third party or it was provided with ycm_clangd_binary_path
option.0
: YCM will never use clangd completer.默認值: 1
let g: ycm_use_clangd = 1
g:ycm_clangd_binary_path
option When ycm_use_clangd
option is set to 1
, this option sets the path to clangd binary.
預設: ''
let g: ycm_clangd_binary_path = ' '
g:ycm_clangd_args
optionThis option controls the command line arguments passed to the clangd binary. It appends new options and overrides the existing ones.
預設: []
let g: ycm_clangd_args = []
g:ycm_clangd_uses_ycmd_caching
optionThis option controls which ranking and filtering algorithm to use for completion items. It can take values:
1
: Uses ycmd's caching and filtering logic.0
: Uses clangd's caching and filtering logic.默認值: 1
let g: ycm_clangd_uses_ycmd_caching = 1
g:ycm_language_server
optionThis option lets YCM use an arbitrary Language Server Protocol (LSP) server, not unlike many other completion systems. The officially supported completers are favoured over custom LSP ones, so overriding an existing completer means first making sure YCM won't choose that existing completer in the first place.
A simple working example of this option can be found in the section called "Semantic Completion for Other Languages".
Many working examples can be found in the YCM lsp-examples repo.
預設: []
let g: ycm_language_server = []
g:ycm_disable_signature_help
optionThis option allows you to disable all signature help for all completion engines. There is no way to disable it per-completer.
默認值: 0
" Disable signature help
let g: ycm_disable_signature_help = 1
g:ycm_signature_help_disable_syntax
optionSet this to 1 to disable syntax highlighting in the signature help popup. Thiis can help if your colourscheme doesn't work well with the default highliting and inverse video.
默認值: 0
" Disable signature help syntax highliting
let g: ycm_signature_help_disable_syntax = 1
g:ycm_gopls_binary_path
option In case the system-wide gopls
binary is newer than the bundled one, setting this option to the path of the system-wide gopls
would make YCM use that one instead.
If the path is just gopls
, YCM will search in $PATH
.
g:ycm_gopls_args
option Similar to the g:ycm_clangd_args
, this option allows passing additional flags to the gopls
command line.
預設: []
let g: ycm_gopls_args = []
g:ycm_rls_binary_path
and g:ycm_rustc_binary_path
optionsYCM no longer uses RLS for rust, and these options are therefore no longer supported.
To use a custom rust-analyzer, see g:ycm_rust_toolchain_root
.
g:ycm_rust_toolchain_root
option Optionally specify the path to a custom rust toolchain including at least a supported version of rust-analyzer
.
g:ycm_tsserver_binary_path
option Similar to the gopls
path, this option tells YCM where is the TSServer executable located.
g:ycm_roslyn_binary_path
option Similar to the gopls
path, this option tells YCM where is the Omnisharp-Roslyn executable located.
g:ycm_update_diagnostics_in_insert_mode
optionWith async diagnostics, LSP servers might send new diagnostics mid-typing. If seeing these new diagnostics while typing is not desired, this option can be set to 0.
When this option is set to 0
, diagnostic signs, virtual text, and highlights are cleared when entering insert mode and replaced when leaving insert mode. This reduces visual noise while editing.
In addition, this option is recommended when g:ycm_echo_current_diagnostic
is set to virtual-text
as it prevents updating the virtual text while you are typing.
默認值: 1
let g: ycm_update_diagnostics_in_insert_mode = 1
The FAQ section has been moved to the wiki.
請注意,該項目已使用貢獻者的行為準則發布。通過參加該項目,您同意遵守其條款。
If you have questions about the plugin or need help, please join the Gitter room or use the ycm-users mailing list.
If you have bug reports or feature suggestions, please use the issue tracker. Before you do, please carefully read CONTRIBUTING.md as this asks for important diagnostics which the team will use to help get you going.
The latest version of the plugin is available at https://ycm-core.github.io/YouCompleteMe/.
The author's homepage is https://val.markovic.io.
Please do NOT go to #vim, Reddit, or Stack Overflow for support. Please contact the YouCompleteMe maintainers directly using the contact details.
This software is licensed under the GPL v3 license. © 2015-2018 YouCompleteMe contributors
If you like YCM so much that you're willing to part with your hard-earned cash, please consider donating to one of the following charities, which are meaningful to the current maintainers (in no particular order):
Please note: The YCM maintainers do not specifically endorse nor necessarily have any relationship with the above charities. Disclosure: It is noted that one key maintainer is a family with Trustees of Greyhound Rescue Wales.