Difference between revisions of "Vim/YouCompleteMe"

From ArchWiki
< Vim
Jump to: navigation, search
(Configuration: +plugin)
Line 1: Line 1:
[[Category:Text editors]]
[[Category:Text editors]]
[https://github.com/Valloric/YouCompleteMe YouCompleteMe] (shortened ad YCM) is a code-completion engine for [[Vim]]. It supports the following languages:
[https://github.com/Valloric/YouCompleteMe YouCompleteMe] (shortened as YCM) is a code-completion engine for [[Vim]]. It supports the following languages:
* C/C++
* C/C++

Revision as of 13:21, 15 March 2015

YouCompleteMe (shortened as YCM) is a code-completion engine for Vim. It supports the following languages:

  • C/C++
  • Python
  • Java
  • Ruby
  • C#


Install vim-youcompleteme-gitAUR package from AUR. For an alternative manual way of installing YouCompleteMe see upstream instructions.



YCM uses a python script called .ycm_extra_conf.py to set project wide settings, needed to provide completion and syntax check. A brief introduction to essential configuration follows, for details and advanced options see the upstream documentation.

Extra conf structure

A sample .ycm_extra_conf.py may be found here. You should save a copy of this file in your project folder and customize it with adequate settings for your source files. The most important settings (which usually suffices for a minimal configuration) are the -x and --std options, which respectively tell to the sintax checker the language used in the project and the standard followed. The -x value may be set to c or c++, while common values for the --std are --std=c89, --std=c99, --std=c11, --std=c14 and their respective c++ version. The standard parameter will determine the warning and the errors in the syntax check (e.g., a line commented with // will be marked as unallowed in C89, but not under following versions of the standard).

A third party script and vim plugin for the automatic generation of the .ycm_extra_conf.py is avaible on this repo.

Extra conf location

The program searches for the .ycm_extra_conf.py file on startup in the current source file directory and in its parent folders. If the file is not found, YCM features are not avaible. A global file (used as fallback when a local extra conf file is not found) may be set adding the following to ~/.vimrc:

let g:ycm_global_ycm_extra_conf = '/path/to/the/file'

Being the extra conf file a python script, when a file is found a confirmation is asked for security reason before to load it. This behaviour may be disabled adding the following to ~/.vimrc:

let g:ycm_confirm_extra_conf = 0

For a less unsecure solution, when the confirmation is enabled a extra conf file blacklist/whitelist may be set assigning a list of patterns to the ycm_extra_conf_globlist variable. A file matching one pattern is blacklisted if the pattern begins with !, whitelisted otherwise, confirmation is asked if the file does not match any pattern. Rule precedence is determined by the order, and the first match is applied. Some glob pattern rules are avaible:

  • * matches everything
  •  ? matches any single character
  • [seq] matches any character in seq
  • [!seq] matches any char not in seq

In example, with the following setting

let g:ycm_extra_conf_globlist = ['~/dev/*','!~/*']

any file in ~/dev will be whitelisted, any in ~/ will be blacklisted, and due to order precedence any file in ~/ excepted the ~/dev folder will be blacklisted.


For Java completion, a project file should be present and Eclim headless server must be running.

  1. Install eclimAUR or eclim-gitAUR from AUR.
  2. Put this in your .vimrc:
    let g:EclimCompletionMethod = 'omnifunc'
  3. Start eclimd script in a separate terminal:
    $ /usr/share/eclipse/eclimd
  4. Create a file named .project in the same directory as your Java files:
  5. Open your Java file in Vim and run:
    :ProjectCreate . -n java

To compile the project:


To run the project:


To run only current file:

:Java %


Note: For C# completion to "just work" simply create an empty .sln file in current or parent directory. The rest of this section explains how to manually create a full working C# project.

The easiest way to create a project is to use monodevelop. The rest of this section explains how to manually create a C# project which can also be built from command line with xbuild.

First create a solution file. Replace bold-italic names appropriately.


Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{00000000-0000-0000-0000-000000000000}") = "PROJECT", "PROJECT\PROJECT.csproj", "{11111111-1111-1111-1111-111111111111}"
	GlobalSection(SolutionConfigurationPlatforms) = preSolution
		Debug|x86 = Debug|x86
		Release|x86 = Release|x86
	GlobalSection(ProjectConfigurationPlatforms) = postSolution
		{11111111-1111-1111-1111-111111111111}.Debug|x86.ActiveCfg = Debug|x86
		{11111111-1111-1111-1111-111111111111}.Debug|x86.Build.0 = Debug|x86
		{11111111-1111-1111-1111-111111111111}.Release|x86.ActiveCfg = Release|x86
		{11111111-1111-1111-1111-111111111111}.Release|x86.Build.0 = Release|x86

Then create a directory named PROJECT and in it a file named PROJECT.csproj:

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">x86</Platform>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
  <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
    <Compile Include="HelloWorld.cs" />
    <Compile Include="CSharpFile1.cs" />
    <Compile Include="CSharpFile2.cs" />

Place your C# files in PROJECT directory and don't forget to manually add them at the bottom of PROJECT/PROJECT.csproj.

Now YouCompleteMe should work for C# files in that directory and you can build the project. To compile the project from inside Vim:



Remember that it might take some time for YouCompleteMe to generate a list of completion strings.

The following commands are available for diagnostics:

  • :messages - show previous errors or messages from Vim
  • :YcmDiags
  • :YcmDebugInfo

E764: Option 'omnifunc' is not set

If this happens for Java files, you forgot to put this in your .vimrc:

let g:EclimCompletionMethod = 'omnifunc'

No completion in Java files

Make sure eclimd daemon is running:

$ ps -ax|grep eclimd

and that you have first generated project files.

URLError: <urlopen error [Errno 111] Connection refused>

This error appears when you do not have a .sln file in current or parent directory.

RuntimeError: Error starting OmniSharp server: no solutionfile found

Same as above.

Ctrl+space does not trigger the completion anymore in terminal vim

Due to a bug in KDE Framework5/Qt5, the Ctrl+space key combination is not recognized by Konsole5. A temporary workaround may be to set another trigger for YouCompleteMe completion, changing the value of the variable ycm_key_invoke_completion, e.g. to use Ctrl-b instead of Ctrl-space add the following to the ~/.vimrc config file:

let g:ycm_key_invoke_completion = '<C-b>'

See also