ycm-core/YouCompleteMe: A code-completion engine for Vim

Content

Gitter room Build status Coverage status

Looking for help, advice, or support? Having problems getting YCM to work?

First carefully read the installation instructions for your OS. We recommend you use the supplied install.py - the "full" installation guide is for rare, advanced use cases and most users should use install.py.

If the server isn't starting and you're getting a "YouCompleteMe unavailable" error, check the Troubleshooting guide.

Next, check the User Guide section on the semantic completer that you are using. For C/C++/Objective-C/Objective-C++/CUDA, you must read this section.

Finally, check the FAQ.

If, after reading the installation and user guides, and checking the FAQ, you're still having trouble, check the contacts section below for how to get in touch.

Please do NOT go to #vim on Freenode for support. Please contact the YouCompleteMe maintainers directly using the contact details below.

Please note that the below instructions suggest using Vundle. Currently there are problems with Vundle, so here are some alternative instructions using Vim packages.

YouCompleteMe is a fast, as-you-type, fuzzy-search code completion, comprehension and refactoring engine for Vim.

It has several completion engines built-in and supports any protocol-compliant Language Server, so can work with practically any language. YouCompleteMe contains:

  • an identifier-based engine that works with every programming language,
  • a powerful clangd-based engine that provides native semantic code completion for C/C++/Objective-C/Objective-C++/CUDA (from now on referred to as "the C-family languages"),
  • a Jedi-based completion engine for Python 2 and 3,
  • an OmniSharp-Roslyn-based completion engine for C#,
  • a Gopls-based completion engine for Go,
  • a TSServer-based completion engine for JavaScript and TypeScript,
  • a rust-analyzer-based completion engine for Rust,
  • a jdt.ls-based completion engine for Java.
  • a generic Language Server Protocol implementation for any language
  • and an omnifunc-based completer that uses data from Vim's omnicomplete system to provide semantic completions for many other languages (Ruby, PHP, etc.).

YouCompleteMe GIF completion demo

Here's an explanation of what happened in the last GIF demo above.

First, realize that no keyboard shortcuts had to be pressed to get the list of completion candidates at any point in the demo. The user just types and the suggestions pop up by themselves. If the user doesn't find the completion suggestions relevant and/or just wants to type, they can do so; the completion engine will not interfere.

When the user sees a useful completion string being offered, they press the TAB key to accept it. This inserts the completion string. Repeated presses of the TAB key cycle through the offered completions.

If the offered completions are not relevant enough, the user can continue typing to further filter out unwanted completions.

A critical thing to notice is that the completion filtering is NOT based on the input being a string prefix of the completion (but that works too). The input needs to be a subsequence match of a completion. This is a fancy way of saying that any input characters need to be present in a completion string in the order in which they appear in the input. So abc is a subsequence of xaybgc, but not of xbyxaxxc. After the filter, a complicated sorting system ranks the completion strings so that the most relevant ones rise to the top of the menu (so you usually need to press TAB just once).

All of the above works with any programming language because of the identifier-based completion engine. It collects all of the identifiers in the current file and other files you visit (and your tags files) and searches them when you type (identifiers are put into per-filetype groups).

The demo also shows the semantic engine in use. When the user presses ., -> or :: while typing in insert mode (for C++; different triggers are used for other languages), the semantic engine is triggered (it can also be triggered with a keyboard shortcut; see the rest of the docs).

The last thing that you can see in the demo is YCM's diagnostic display features (the little red X that shows up in the left gutter; inspired by Syntastic) if you are editing a C-family file. As the completer engine compiles your file and detects warnings or errors, they will be presented in various ways. You don't need to save your file or press any keyboard shortcut to trigger this, it "just happens" in the background.

And that's not all...

YCM might be the only Vim completion engine with the correct Unicode support. Though we do assume UTF-8 everywhere.

YouCompleteMe GIF unicode demo

YCM also provides semantic IDE-like features in a number of languages, including:

For example, here's a demo of signature help:

Signature Help Early Demo

Below we can see YCM being able to do a few things:

  • Retrieve references across files
  • Go to declaration/definition
  • Expand auto in C++
  • Fix some common errors, and provide refactorings, with FixIt
  • Not shown in the GIF are GoToImplementation and GoToType for servers that support it.

YouCompleteMe GIF subcommands demo

And here's some documentation being shown in a hover popup, automatically and manually:

hover demo

Features vary by file type, so make sure to check out the file type feature summary and the full list of completer subcommands to find out what's available for your favourite languages.

You'll also find that YCM has filepath completers (try typing ./ in a file) and a completer that integrates with UltiSnips.

Runtime

Min Version

Recommended Version (full support)

Python

Vim

9.1.0016

9.1.0016

3.8

Neovim

0.5

Vim 9.1.0016

3.8

Our policy is to support the Vim version that's in the latest LTS of Ubuntu.

Vim must have a working Python 3 runtime.

For Neovim users, our policy is to require the latest released version. Currently, Neovim 0.5.0 is required. Please note that some features are not available in Neovim, and Neovim is not officially supported.

YCM has two components: A server and a client. Both the server and client require Python 3.8 or later 3.x release.

For the Vim client, Vim must be compiled with --enable-shared (or --enable-framework on macOS). You can check if this is working with :py3 import sys; print( sys.version). It should say something like 3.8.2 (...).

For Neovim, you must have a python 3.8 runtime and the Neovim python extensions. See Neovim's :help provider-python for how to set that up.

For the server, you must run the install.py script with a python 3.8 (or later) runtime. Anaconda etc. are not supported. YCM will remember the runtime you used to run install.py and will use that when launching the server, so if you usually use anaconda, then make sure to use the full path to a real cpython3, e.g. /usr/bin/python3 install.py --all etc.

Our policy is to support the python3 version that's available in the latest Ubuntu LTS (similar to our Vim version policy). We don't increase the Python runtime version without a reason, though. Typically, we do this when the current python version we're using goes out of support. At that time we will typically pick a version that will be supported for a number of years.

In order to provide the best possible performance and stability, ycmd has updated its code to C++17. This requires a version bump of the minimum supported compilers. The new requirements are:

Compiler

Current Min

GCC

8

Clang

7

MSVC

15.7 (VS 2017)

YCM requires CMake 3.13 or greater. If your CMake is too old, you may be able to simply pip install --user cmake to get a really new version.

When enabling language support for a particular language, there may be runtime requirements, such as needing a very recent Java Development Kit for Java support. In general, YCM is not in control of the required versions for the downstream compilers, though we do our best to signal where we know them.

  • Install YCM plugin via Vundle
  • Install CMake, MacVim and Python 3; Note that the pre-installed macOS system Vim is not supported (due to it having broken Python integration).
$ brew install cmake python go nodejs
  • Install mono from Mono Project (NOTE: on Intel Macs you can also brew install mono. On arm Macs, you may require Rosetta)
  • For Java support you must install a JDK, one way to do this is with Homebrew:
$ brew install java
$ sudo ln -sfn $(brew --prefix java)/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk
  • Pre-installed macOS system Vim does not support Python 3. So you need to install either a Vim that supports Python 3 OR MacVim with Homebrew:
*   Option 1: Installing a Vim that supports Python 3
*   Option 2: Installing [MacVim](https://macvim-dev.github.io/macvim/)
  • Compile YCM.
*   For Intel and arm64 Macs, the bundled libclang/clangd work:
        cd ~/.vim/bundle/YouCompleteMe
        python3 install.py --all
*   If you have troubles with finding system frameworks or C++ standard library, try using the homebrew llvm:
        brew install llvm
        cd ~/.vim/bundle/YouCompleteMe
        python3 install.py --system-libclang --all
    And edit your vimrc to add the following line to use the Homebrew llvm's clangd:
    " Use homebrew's clangd
    let g:ycm\_clangd\_binary\_path \= trim(system('brew --prefix llvm')).'/bin/clangd'

These instructions (using install.py) are the quickest way to install YouCompleteMe, however they may not work for everyone. If the following instructions don't work for you, check out the full installation guide.

A supported Vim version with Python 3 is required. MacVim is a good option, even if you only use the terminal. YCM won't work with the pre-installed Vim from Apple as its Python support is broken. If you don't already use a Vim that supports Python 3 or MacVim, install it with Homebrew. Install CMake as well:

OR

brew install macvim cmake

Install YouCompleteMe with Vundle.

Remember: YCM is a plugin with a compiled component. If you update YCM using Vundle and the ycm_core library APIs have changed (happens rarely), YCM will notify you to recompile it. You should then rerun the install process.

NOTE: If you want C-family completion, you MUST have the latest Xcode installed along with the latest Command Line Tools (they are installed automatically when you run clang for the first time, or manually by running xcode-select --install)

Compiling YCM with semantic support for C-family languages through clangd:

cd ~/.vim/bundle/YouCompleteMe
./install.py --clangd-completer

Compiling YCM without semantic support for C-family languages:

cd ~/.vim/bundle/YouCompleteMe
./install.py

The following additional language support options are available:

  • C# support: install by downloading the Mono macOS package and add --cs-completer when calling install.py.
  • Go support: install Go and add --go-completer when calling install.py.
  • JavaScript and TypeScript support: install Node.js 18+ and npm and add --ts-completer when calling install.py.
  • Rust support: add --rust-completer when calling install.py.
  • Java support: install JDK 17 and add --java-completer when calling install.py.

To simply compile with everything enabled, there's a --all flag. So, to install with all language features, ensure xbuild, go, node and npm tools are installed and in your PATH, then simply run:

cd ~/.vim/bundle/YouCompleteMe
./install.py --all

That's it. You're done. Refer to the User Guide section on how to use YCM. Don't forget that if you want the C-family semantic completion engine to work, you will need to provide the compilation flags for your project to YCM. It's all in the User Guide.

YCM comes with sane defaults for its options, but you still may want to take a look at what's available for configuration. There are a few interesting options that are conservatively turned off by default that you may want to turn on.

The following assume you're using Ubuntu 24.04.

  • Install YCM plugin via Vundle
  • Install CMake, Vim and Python
apt install build-essential cmake vim-nox python3-dev
  • Install mono-complete, go, node, java, and npm
apt install mono-complete golang nodejs openjdk-17-jdk openjdk-17-jre npm
cd ~/.vim/bundle/YouCompleteMe
python3 install.py --all

These instructions (using install.py) are the quickest way to install YouCompleteMe, however they may not work for everyone. If the following instructions don't work for you, check out the full installation guide.

Make sure you have a supported version of Vim with Python 3 support and a supported compiler. The latest LTS of Ubuntu is the minimum platform for simple installation. For earlier releases or other distributions, you may have to do some work to acquire the dependencies.

If your Vim version is too old, you may need to compile Vim from source (don't worry, it's easy).

Install YouCompleteMe with Vundle.

Remember: YCM is a plugin with a compiled component. If you update YCM using Vundle and the ycm_core library APIs have changed (which happens rarely), YCM will notify you to recompile it. You should then rerun the installation process.

Install development tools, CMake, and Python headers:

  • Fedora-like distributions:
sudo dnf install cmake gcc-c++ make python3-devel
sudo apt install build-essential cmake3 python3-dev

Compiling YCM with semantic support for C-family languages through clangd:

cd ~/.vim/bundle/YouCompleteMe
python3 install.py --clangd-completer

Compiling YCM without semantic support for C-family languages:

cd ~/.vim/bundle/YouCompleteMe
python3 install.py

The following additional language support options are available:

  • C# support: install Mono and add --cs-completer when calling install.py.
  • Go support: install Go and add --go-completer when calling install.py.
  • JavaScript and TypeScript support: install Node.js 18+ and npm and add --ts-completer when calling install.py.
  • Rust support: add --rust-completer when calling install.py.
  • Java support: install JDK 17 and add --java-completer when calling install.py.

To simply compile with everything enabled, there's a --all flag. So, to install with all language features, ensure xbuild, go, node, and npm tools are installed and in your PATH, then simply run:

cd ~/.vim/bundle/YouCompleteMe
python3 install.py --all

That's it. You're done. Refer to the User Guide section on how to use YCM. Don't forget that if you want the C-family semantic completion engine to work, you will need to provide the compilation flags for your project to YCM. It's all in the User Guide.

YCM comes with sane defaults for its options, but you still may want to take a look at what's available for configuration. There are a few interesting options that are conservatively turned off by default that you may want to turn on.

cd YouCompleteMe
python3 install.py --all

These instructions (using install.py) are the quickest way to install YouCompleteMe, however they may not work for everyone. If the following instructions don't work for you, check out the full installation guide.

Important: we assume that you are using the cmd.exe command prompt and that you know how to add an executable to the PATH environment variable.

Make sure you have a supported Vim version with Python 3 support. You can check the version and which Python is supported by typing :version inside Vim. Look at the features included: +python3/dyn for Python 3. Take note of the Vim architecture, i.e. 32 or 64-bit. It will be important when choosing the Python installer. We recommend using a 64-bit client. Daily updated installers of 32-bit and 64-bit Vim with Python 3 support are available.

Add the following line to your vimrc if not already present.:

This option is required by YCM. Note that it does not prevent you from editing a file in another encoding than UTF-8. You can do that by specifying the ++enc argument to the :e command.

Install YouCompleteMe with Vundle.

Remember: YCM is a plugin with a compiled component. If you update YCM using Vundle and the ycm_core library APIs have changed (happens rarely), YCM will notify you to recompile it. You should then rerun the install process.

Download and install the following software:

  • Python 3. Be sure to pick the version corresponding to your Vim architecture. It is Windows x86 for a 32-bit Vim and Windows x86-64 for a 64-bit Vim. We recommend installing Python 3. Additionally, the version of Python you install must match up exactly with the version of Python that Vim is looking for. Type :version and look at the bottom of the page at the list of compiler flags. Look for flags that look similar to -DDYNAMIC_PYTHON3_DLL="python36.dll". This indicates that Vim is looking for Python 3.6. You'll need one or the other installed, matching the version number exactly.
  • CMake. Add CMake executable to the PATH environment variable.
  • Build Tools for Visual Studio 2019. During setup, select C++ build tools in Workloads.

Compiling YCM with semantic support for C-family languages through clangd:

cd %USERPROFILE%/vimfiles/bundle/YouCompleteMe
python install.py --clangd-completer

Compiling YCM without semantic support for C-family languages:

cd %USERPROFILE%/vimfiles/bundle/YouCompleteMe
python install.py

The following additional language support options are available:

  • C# support: add --cs-completer when calling install.py. Be sure that the build utility msbuild is in your PATH.
  • Go support: install Go and add --go-completer when calling install.py.
  • JavaScript and TypeScript support: install Node.js 18+ and npm and add --ts-completer when calling install.py.
  • Rust support: add --rust-completer when calling install.py.
  • Java support: install JDK 17 and add --java-completer when calling install.py.

To simply compile with everything enabled, there's a --all flag. So, to install with all language features, ensure msbuild, go, node and npm tools are installed and in your PATH, then simply run:

cd %USERPROFILE%/vimfiles/bundle/YouCompleteMe
python install.py --all

You can specify the Microsoft Visual C++ (MSVC) version using the --msvc option. YCM officially supports MSVC 15 (2017), MSVC 16 (Visual Studio 2019) and MSVC 17 (Visual Studio 17 2022).

That's it. You're done. Refer to the User Guide section on how to use YCM. Don't forget that if you want the C-family semantic completion engine to work, you will need to provide the compilation flags for your project to YCM. It's all in the User Guide.

YCM comes with sane defaults for its options, but you still may want to take a look at what's available for configuration. There are a few interesting options that are conservatively turned off by default that you may want to turn on.

The full installation guide has been moved to the wiki.

  • Super-fast identifier completer including tags files and syntax elements
  • Intelligent suggestion ranking and filtering
  • File and path suggestions
  • Suggestions from Vim's omnifunc
  • UltiSnips snippet suggestions
  • Semantic auto-completion with automatic fixes
  • Signature help
  • Real-time diagnostic display
  • Go to include/declaration/definition (GoTo, etc.)
  • Go to alternate file (e.g. associated header GoToAlternateFile)
  • Find Symbol (GoToSymbol), with interactive search
  • Document outline (GoToDocumentOutline), with interactive search
  • View documentation comments for identifiers (GetDoc)
  • Type information for identifiers (GetType)
  • Automatically fix certain errors (FixIt)
  • Perform refactoring (FixIt)
  • Reference finding (GoToReferences)
  • Renaming symbols (RefactorRename <new name>)
  • Code formatting (Format)
  • Semantic highlighting
  • Inlay hints
  • Type hierarchy
  • Call hierarchy
  • Semantic auto-completion
  • Signature help
  • Real-time diagnostic display
  • Go to declaration/definition (GoTo, etc.)
  • Go to implementation (GoToImplementation)
  • Find Symbol (GoToSymbol), with interactive search
  • View documentation comments for identifiers (GetDoc)
  • Type information for identifiers (GetType)
  • Automatically fix certain errors (FixIt)
  • Perform refactoring (FixIt)
  • Management of OmniSharp-Roslyn server instance
  • Renaming symbols (RefactorRename <new name>)
  • Code formatting (Format)
  • Semantic auto-completion
  • Signature help
  • Go to definition (GoTo)
  • Find Symbol (GoToSymbol), with interactive search
  • Reference finding (GoToReferences)
  • View documentation comments for identifiers (GetDoc)
  • Type information for identifiers (GetType)
  • Renaming symbols (RefactorRename <new name>)
  • Semantic auto-completion
  • Signature help
  • Real-time diagnostic display
  • Go to declaration/definition (GoTo, etc.)
  • Go to type definition (GoToType)
  • Go to implementation (GoToImplementation)
  • Document outline (GoToDocumentOutline), with interactive search
  • Automatically fix certain errors (FixIt)
  • Perform refactoring (FixIt)
  • View documentation comments for identifiers (GetDoc)
  • Type information for identifiers (GetType)
  • Code formatting (Format)
  • Management of gopls server instance
  • Inlay hints
  • Call hierarchy
  • Semantic auto-completion with automatic import insertion
  • Signature help
  • Real-time diagnostic display
  • Go to definition (GoTo, GoToDefinition, and GoToDeclaration are identical)
  • Go to type definition (GoToType)
  • Go to implementation (GoToImplementation)
  • Find Symbol (GoToSymbol), with interactive search
  • Reference finding (GoToReferences)
  • View documentation comments for identifiers (GetDoc)
  • Type information for identifiers (GetType)
  • Automatically fix certain errors and perform refactoring (FixIt)
  • Perform refactoring (FixIt)
  • Renaming symbols (RefactorRename <new name>)
  • Code formatting (Format)
  • Organize imports (OrganizeImports)
  • Management of TSServer server instance
  • Inlay hints
  • Call hierarchy
  • Semantic auto-completion
  • Real-time diagnostic display
  • Go to declaration/definition (GoTo, etc.)
  • Go to implementation (GoToImplementation)
  • Reference finding (GoToReferences)
  • Document outline (GoToDocumentOutline), with interactive search
  • View documentation comments for identifiers (GetDoc)
  • Automatically fix certain errors (FixIt)
  • Perform refactoring (FixIt)
  • Type information for identifiers (GetType)
  • Renaming symbols (RefactorRename <new name>)
  • Code formatting (Format)
  • Management of rust-analyzer server instance
  • Semantic highlighting
  • Inlay hints
  • Call hierarchy
  • Semantic auto-completion with automatic import insertion
  • Signature help
  • Real-time diagnostic display
  • Go to definition (GoTo, GoToDefinition, and GoToDeclaration are identical)
  • Go to type definition (GoToType)
  • Go to implementation (GoToImplementation)
  • Find Symbol (GoToSymbol), with interactive search
  • Reference finding (GoToReferences)
  • Document outline (GoToDocumentOutline), with interactive search
  • View documentation comments for identifiers (GetDoc)
  • Type information for identifiers (GetType)
  • Automatically fix certain errors including code generation (FixIt)
  • Renaming symbols (RefactorRename <new name>)
  • Code formatting (Format)
  • Organize imports (OrganizeImports)
  • Detection of Java projects
  • Execute custom server command (ExecuteCommand <args>)
  • Management of jdt.ls server instance
  • Semantic highlighting
  • Inlay hints
  • Type hierarchy
  • Call hierarchy

If the offered completions are too broad, keep typing characters; YCM will continue refining the offered completions based on your input.

Filtering is "smart-case" and "smart-diacritic" sensitive; if you are typing only lowercase letters, then it's case-insensitive. If your input contains uppercase letters, then the uppercase letters in your query must match uppercase letters in the completion strings (the lowercase letters still match both). On top of that, a letter with no diacritic marks will match that letter with or without marks:

matches

foo

'fôo'

fOo

fÔo

foo

✔️

✔️

✔️

✔️

'fôo'

✔️

✔️

fOo

✔️

✔️

fÔo

✔️

Use the TAB key to accept a completion and continue pressing TAB to cycle through the completions. Use Shift-TAB to cycle backward. Note that if you're using console Vim (that is, not gvim or MacVim) then it's likely that the Shift-TAB binding will not work because the console will not pass it to Vim. You can remap the keys; see the Options section below.

Knowing a little bit about how YCM works internally will prevent confusion. YCM has several completion engines: an identifier-based completer that collects all of the identifiers in the current file and other files you visit (and your tags files) and searches them when you type (identifiers are put into per-filetype groups).

There are also several semantic engines in YCM. There are libclang-based and clangd-based completers that provide semantic completion for C-family languages. There's a Jedi-based completer for semantic completion for Python. There's also an omnifunc-based completer that uses data from Vim's omnicomplete system to provide semantic completions when no native completer exists for that language in YCM.

There are also other completion engines, like the UltiSnips completer and the filepath completer.

YCM automatically detects which completion engine would be the best in any situation. On occasion, it queries several of them at once, merges the outputs and presents the results to you.

YCM has a client-server architecture; the Vim part of YCM is only a thin client that talks to the ycmd HTTP+JSON server that has the vast majority of YCM logic and functionality. The server is started and stopped automatically as you start and stop Vim.

The subsequence filter removes any completions that do not match the input, but then the sorting system kicks in. It's actually very complicated and uses lots of factors, but suffice it to say that "word boundary" (WB) subsequence character matches are "worth" more than non-WB matches. In effect, this means that given an input of "gua", the completion "getUserAccount" would be ranked higher in the list than the "Fooguxa" completion (both of which are subsequence matches). Word-boundary characters are all capital characters, characters preceded by an underscore, and the first letter character in the completion string.

Valid signatures are displayed in a second popup menu and the current signature is highlighted along with the current argument.

Signature help is triggered in insert mode automatically when g:ycm_auto_trigger is enabled and is not supported when it is not enabled.

The signatures popup is hidden when there are no matching signatures or when you leave insert mode. If you want to manually control when it is visible, you can map something to <plug>YCMToggleSignatureHelp (see below).

For more details on this feature and a few demos, check out the PR that proposed it.

The signature help popup sometimes gets in the way. You can toggle its visibility with a mapping. YCM provides the "Plug" mapping <Plug>(YCMToggleSignatureHelp) for this.

For example, to hide/show the signature help popup by pressing Ctrl+l in insert mode: imap <silent> <C-l> <Plug>(YCMToggleSignatureHelp).

NOTE: No default mapping is provided because insert mappings are very difficult to create without breaking or overriding some existing functionality. Ctrl-l is not a suggestion, just an example.

Semantic highlighting is the process where the buffer text is coloured according to the underlying semantic type of the word, rather than classic syntax highlighting based on regular expressions. This can be powerful additional data that we can process very quickly.

This feature is only supported in Vim.

For example, here is a function with classic highlighting:

highliting-classic

And here is the same function with semantic highlighting:

highliting-semantic

As you can see, the function calls, macros, etc. are correctly identified.

This can be enabled globally with let g:ycm_enable_semantic_highlighting=1 or per buffer, by setting b:ycm_enable_semantic_highlighting.

YCM uses text properties (see :help text-prop-intro) for semantic highlighting. In order to customise the coloring, you can define the text properties that are used.

If you define a text property named YCM_HL_<token type>, then it will be used in place of the defaults. The <token type> is defined as the Language Server Protocol semantic token type, defined in the LSP Spec.

Some servers also use custom values. In this case, YCM prints a warning including the token type name that you can customise.

For example, to render parameter tokens using the Normal highlight group, you can do this:

call prop_type_add( 'YCM_HL_parameter', { 'highlight': 'Normal' } )

More generally, this pattern can be useful for customizing the groups:

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

NOTE: Highly experimental feature, requiring Vim 9.0.214 or later (not supported in NeoVim).

When g:ycm_enable_inlay_hints (globally) or b:ycm_enable_inlay_hints (for a specific buffer) is set to 1, then YCM will insert inlay hints as supported by the language semantic engine.

An inlay hint is text that is rendered on the screen that is not part of the buffer and is often used to mark up the type or name of arguments, parameters, etc. which help the developer understand the semantics of the code.

Here are some examples:

c-inlay

ts-inlay

go-inlay

By default, YCM renders the inlay hints with the NonText highlight group. To override this, define the YcmInlayHint highlight yourself, e.g. in your .vimrc:

hi link YcmInlayHint Comment

Similar to semantic highlighting above, you can override specific highlighting for different inlay hint types by defining text properties named after the kind of inlay hint, for example:

call prop_type_add( 'YCM_INLAY_Type', #{ highlight: 'Comment' } )

The list of inlay hint kinds can be found in python/ycm/inlay_hints.py

  • g:ycm_enable_inlay_hints or b:ycm_enable_inlay_hints - enable/disable globally or for local buffer
  • g:ycm_clear_inlay_hints_in_insert_mode - set to 1 to remove all inlay hints when entering insert mode and reinstate them when leaving insert mode

Inlay hints can add a lot of text to the screen and may be distracting. You can toggle them on/off instantly, by mapping something to <Plug>(YCMToggleInlayHints), for example:

nnoremap <silent> <localleader>h <Plug>(YCMToggleInlayHints)

No default mapping is provided for this due to the personal nature of mappings.

You can use Ctrl+Space to trigger the completion suggestions anywhere, even without a string prefix. This is useful to see which top-level functions are available for use.

NOTE: YCM originally used the libclang based engine for C-family, but users should migrate to clangd, as it provides more features and better performance. Users who rely on override_filename in their .ycm_extra_conf.py will need to stay on the old libclang engine. Instructions on how to stay on the old engine are available on the wiki.

Some of the features of clangd:

  • Project wide indexing: Clangd has both dynamic and static index support. The dynamic index stores up-to-date symbols coming from any files you are currently editing, whereas static index contains project-wide symbol information. This symbol information is used for code completion and code navigation. Whereas libclang is limited to the current translation unit(TU).
  • Code navigation: Clangd provides all the GoTo requests libclang provides and it improves those using the above-mentioned index information to contain project-wide information rather than just the current TU.
  • Rename: Clangd can perform semantic rename operations on the current file, whereas libclang doesn't support such functionality.
  • Code Completion: Clangd can perform code completions at a lower latency than libclang; also, it has information about all the symbols in your project so it can suggest items outside your current TU and also provides proper #include insertions for those items.
  • Signature help: Clangd provides signature help so that you can see the names and types of arguments when calling functions.
  • Format Code: Clangd provides code formatting either for the selected lines or the whole file, whereas libclang doesn't have such functionality.
  • Performance: Clangd has faster re-parse and code completion times compared to libclang.

On supported architectures, the install.py script will download a suitable clangd (--clangd-completer) or libclang (--clang-completer) for you. Supported architectures are:

  • Linux glibc >= 2.39 (Intel, armv7-a, aarch64) - built on ubuntu 24.04
  • MacOS >=10.15 (Intel, arm64)
    • For Intel, compatibility per clang.llvm.org downloads
    • For arm64, macOS 10.15+
  • Windows (Intel) - compatibility per clang.llvm.org downloads

clangd:

Typically, clangd is installed by the YCM installer (either with --all or with --clangd-completer). This downloads a pre-built clangd binary for your architecture. If your OS or architecture is not supported or is too old, you can install a compatible clangd and use g:ycm_clangd_binary_path to point to it.

libclang:

libclang can be enabled also with --all or --clang-completer. As with clangd, YCM will try and download a version of libclang that is suitable for your environment, but again if your environment can't be supported, you can build or acquire libclang for yourself and specify it when building, as:

$ EXTRA_CMAKE_ARGS='-DPATH_TO_LLVM_ROOT=/path/to/your/llvm' ./install.py --clang-completer --system-libclang

Please note that if using custom clangd or libclang it must match the version that YCM requires. Currently YCM requires clang 17.0.1.

In order to perform semantic analysis such as code completion, GoTo, and diagnostics, YouCompleteMe uses clangd, which makes use of clang compiler, sometimes also referred to as LLVM. Like any compiler, clang also requires a set of compile flags in order to parse your code. Simply put: If clang can't parse your code, YouCompleteMe can't provide semantic analysis.

There are 2 methods that can be used to provide compile flags to clang:

The easiest way to get YCM to compile your code is to use a compilation database. A compilation database is usually generated by your build system (e.g. CMake) and contains the compiler invocation for each compilation unit in your project.

For information on how to generate a compilation database, see the clang documentation. In short:

  • If using CMake, add -DCMAKE_EXPORT_COMPILE_COMMANDS=ON when configuring (or add set( CMAKE_EXPORT_COMPILE_COMMANDS ON ) to CMakeLists.txt) and copy or symlink the generated database to the root of your project.
  • If using Ninja, check out the compdb tool (-t compdb) in its docs.
  • If using GNU make, check out compiledb or Bear.
  • For other build systems, check out .ycm_extra_conf.py below.

If no .ycm_extra_conf.py is found, YouCompleteMe automatically tries to load a compilation database if there is one.

YCM looks for a file named compile_commands.json in the directory of the opened file or in any directory above it in the hierarchy (recursively); when the file is found before a local .ycm_extra_conf.py, YouCompleteMe stops searching the directories and lets clangd take over and handle the flags.

If you don't have a compilation database or aren't able to generate one, you have to tell YouCompleteMe how to compile your code some other way.

Every C-family project is different. It is not possible for YCM to guess what compiler flags to supply for your project. Fortunately, YCM provides a mechanism for you to generate the flags for a particular file with arbitrary complexity. This is achieved by requiring you to provide a Python module that implements a trivial function that, given the file name as an argument, returns a list of compiler flags to use to compile that file.

YCM looks for a .ycm_extra_conf.py file in the directory of the opened file or in any directory above it in the hierarchy (recursively); when the file is found, it is loaded (only once!) as a Python module. YCM calls a Settings method in that module which should provide it with the information necessary to compile the current file. You can also provide a path to a global configuration file with the g:ycm_global_ycm_extra_conf option, which will be used as a fallback. To prevent the execution of malicious code from a file you didn't write YCM will ask you once per .ycm_extra_conf.py if it is safe to load. This can be disabled and you can white-/blacklist files. See the g:ycm_confirm_extra_conf and g:ycm_extra_conf_globlist options respectively.

This system was designed this way so that the user can perform any arbitrary sequence of operations to produce a list of compilation flags YCM should hand to Clang.

NOTE: It is highly recommended to include -x <language> flag to libclang. This is so that the correct language is detected, particularly for header files. Common values are -x c for C, -x c++ for C++, -x objc for Objective-C, and -x cuda for CUDA.

To give you an impression, if your C++ project is trivial, and your usual compilation command is: g++ -Wall -Wextra -Werror -o FILE.o FILE.cc, then the following .ycm_extra_conf.py is enough to get semantic analysis from YouCompleteMe:

def Settings( **kwargs ): return { 'flags': [ '-x', 'c++', '-Wall', '-Wextra', '-Werror' ], }

As you can see from the trivial example, YCM calls the Settings method which returns a dictionary with a single element 'flags'. This element is a list of compiler flags to pass to libclang for the current file. The absolute path of that file is accessible under the filename key of the kwargs dictionary. That's it! This is actually enough for most projects, but for complex projects it is not uncommon to integrate directly with an existing build system using the full power of the Python language.

For a more elaborate example, see ycmd's own .ycm_extra_conf.py. You should be able to use it as a starting point. Don't just copy/paste that file somewhere and expect things to magically work; your project needs different flags. Hint: just replace the strings in the flags variable with compilation flags necessary for your project. That should be enough for 99% of projects.

You could also consider using YCM-Generator to generate the ycm_extra_conf.py file.

If Clang encounters errors when compiling the header files that your file includes, then it's probably going to take a long time to get completions. When the completion menu finally appears, it's going to have a large number of unrelated completion strings (type/function names that are not actually members). This is because Clang fails to build a precompiled preamble for your file if there are any errors in the included headers and that preamble is key to getting fast completions.

Call the :YcmDiags command to see if any errors or warnings were detected in your file.

  1. Ensure that you have enabled the Java completer. See the installation guide for details.
  1. Create a project file (gradle or maven) file in the root directory of your Java project, by following the instructions below.
  1. (Optional) Configure the LSP server. The jdt.ls configuration options can be found in their codebase.
  1. If you previously used Eclim or Syntastic for Java, disable them for Java.
  1. Edit a Java file from your project.

In order to provide semantic analysis, the Java completion engine requires knowledge of your project structure. In particular, it needs to know the class path to use, when compiling your code. Fortunately jdt.ls supports eclipse project files, maven projects and gradle projects.

NOTE: Our recommendation is to use either Maven or Gradle projects.

The native support for Java includes YCM's native real-time diagnostics display. This can conflict with other diagnostics plugins like Syntastic, so when enabling Java support, please manually disable Syntastic Java diagnostics.

Add the following to your vimrc:

let g:syntastic_java_checkers = []

Summary
YouCompleteMe (YCM) is a powerful code completion engine for Vim, offering fast, as-you-type fuzzy-search capabilities across multiple programming languages. It features various built-in completion engines, including identifier-based, clangd for C-family languages, Jedi for Python, OmniSharp for C#, Gopls for Go, TSServer for JavaScript/TypeScript, rust-analyzer for Rust, and jdt.ls for Java. YCM supports any protocol-compliant Language Server, making it versatile for different languages. Users can easily install YCM using the provided `install.py` script and troubleshoot common issues through the detailed guides available. The engine provides semantic completion, diagnostic displays for errors, and IDE-like features such as signature help, finding declarations, and semantic renaming. The completion system allows users to filter suggestions based on subsequence matches, enhancing the relevance of the suggestions. YCM also supports Unicode and offers features like code formatting and fixing common coding errors. For support, users are encouraged to refer to the installation and user guides, FAQs, and contact the maintainers directly, avoiding public channels like Freenode.