< Vim

Vim/YouCompleteMe

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

  • C/C++/Objective-C/Objective-C++
  • Python
  • C#
  • Go
  • Rust
  • Java
  • JavaScript
  • TypeScript
  • Other languages (Ruby, PHP etc.) through the use of omnicompletion system

Installation

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

Configuration

C/C++

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.

Alternatively, provide a compile_commands.json in the project's root.

Extra conf structure

A sample .ycm_extra_conf.py may be found in . 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 tells the syntax 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 available 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 available. A global file (used as fallback when a local extra conf file is not found) may be set adding the following to :

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 :

For a less unsecure solution, when the confirmation is enabled an 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 available:

  • * 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

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

Java

YCM has integrated support for jdt.ls which can be installed by passing to the script.

Java - alternative

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

  1. Install from AUR.
  2. Put this in your .vimrc:
  3. Start script in a separate terminal:
    $ /usr/lib/eclipse/plugins/org.eclim_$pkgver/bin/eclimd
  4. Create a file named .project in the same directory as your Java files:
  5. Open your Java file in Vim and run:

To compile the project:

 :ProjectBuild

To run the project:

 :Java

To run only current file:

 :Java %

A list of available commands may be found here.

C#

Before starting work with a C# project, ensure that is installed on your system as it is a required dependency of Omnisharp-Roslyn, the C# completion engine used by YouCompleteMe. More information can be found in Omnisharp-Roslyn's README and the following Github issue.

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

Then create a directory named and in it a file named :

Place your C# files in directory and do not 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:

  • - show previous errors or messages from Vim

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 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 file in current or parent directory.

RuntimeError: Error starting OmniSharp server: no solutionfile found

Same as above.

gollark: Impossible.
gollark: How DOES fish do it? Magic, probably.
gollark: Perhaps one day I might actually catch a CB metal.
gollark: So... if you ask for "anything but gender swap" you'll get that?
gollark: So you'd need to incubate and hatch them too, then send the hatchling back, I think.

See also

This article is issued from Archlinux. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.