YouCompleteMe
YouCompleteMe is a code-completion engine for Vim. It supports the following languages:
- C/C++
- Python
- Java
- Ruby
- C#
Contents
Installation
Install vim-youcompleteme-git package from AUR. For an alternative manual way of installing YouCompleteMe see upstream instructions.
Configuration
Java
For Java completion, a project file should be present and Eclim headless server must be running.
- Install eclim or eclim-git from AUR.
-
Put this in your .vimrc:
~/.vimrc
let g:EclimCompletionMethod = 'omnifunc'
-
Start
eclimdscript in a separate terminal:$ /usr/share/eclipse/eclimd
-
Create a file named
.projectin the same directory as your Java files:.project
<projectDescription> <name>PROJECTNAME</name> </projectDescription> -
Open your Java file in Vim and run:
:ProjectCreate . -n java
To compile the project:
:ProjectBuild
To run the project:
:Java
To run only current file:
:Java %
C#
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.
SOLUTION.sln
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}"
EndProject
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x86 = Debug|x86
Release|x86 = Release|x86
EndGlobalSection
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
EndGlobalSection
EndGlobal
Then create a directory named PROJECT and in it a file named PROJECT.csproj:
PROJECT/PROJECT.csproj
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<ProductVersion>10.0.0</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{11111111-1111-1111-1111-111111111111}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>PROJECT</RootNamespace>
<AssemblyName>PROJECT</AssemblyName>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug</OutputPath>
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<DebugType>full</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>
<Compile Include="HelloWorld.cs" />
<Compile Include="CSharpFile1.cs" />
<Compile Include="CSharpFile2.cs" />
</ItemGroup>
</Project>
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:
:!xbuild
Troubleshooting
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:
~/.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.