Racer support for Vim

Related tags

IDEs vim-racer
Overview

Vim Racer Plugin

This plugin allows vim to use Racer for Rust code completion and navigation.

Installation

  1. Build / Install Racer

  2. Install using Pathogen, Vundle or NeoBundle. Or, copy ftplugin/rust_racer.vim into your ~/.vim/plugin directory.

Vundle users:

Plugin 'racer-rust/vim-racer'

NeoBundle users:

NeoBundle 'racer-rust/vim-racer'

vim-plug users:

Plug 'racer-rust/vim-racer'

Pathogen users:

git clone --depth=1 https://github.com/racer-rust/vim-racer.git ~/.vim/bundle/vim-racer
  1. Add g:racer_cmd to your .vimrc. It contains full path to racer executable file. Variable g:racer_cmd is optional. You do not need to use this variable if the executable file is in a directory that is specified in $PATH, else you should specified full path to racer executable binary file in this g:racer_cmd. Also it's worth turning on 'hidden' mode for buffers otherwise you need to save the current buffer every time you do a goto-definition. E.g.:
set hidden
let g:racer_cmd = "/home/user/.cargo/bin/racer"
  1. If you want completions to show the complete function definition (e.g. its arguments and return type), enable the experimental completer:
let g:racer_experimental_completer = 1
  1. If you want to insert the parenthesis in the completion:
let g:racer_insert_paren = 1

Example Mappings

vim-racer enables C-x-C-o to search for completions and provides several <Plug> mappings for source code navigation. These mappings are not enabled by default but you can easily use them by adding the following lines to your .vimrc (Or init.vim in case of Neovim).

For example, with the following mappings you can navigate to the identifier under the cursor and open it on the current buffer, on an horizontal or vertical split, on a new tab, or go straight to the documentation:

augroup Racer
    autocmd!
    autocmd FileType rust nmap <buffer> gd         <Plug>(rust-def)
    autocmd FileType rust nmap <buffer> gs         <Plug>(rust-def-split)
    autocmd FileType rust nmap <buffer> gx         <Plug>(rust-def-vertical)
    autocmd FileType rust nmap <buffer> gt         <Plug>(rust-def-tab)
    autocmd FileType rust nmap <buffer> <leader>gd <Plug>(rust-doc)
    autocmd FileType rust nmap <buffer> <leader>gD <Plug>(rust-doc-tab)
augroup END
Comments
  • No completion (after update?)

    No completion (after update?)

    Today I decided to :PlugUpdate. Not sure if that's why, but I later today realized no completions at all worked.

    It has worked previously, and my init.vim file looks like this, where it's worth to point out

    call plug#begin()
    Plug 'rust-lang/rust.vim'
    Plug 'racer-rust/vim-racer'
    call plug#end()
    

    and

    filetype plugin indent on
    
    let g:racer_cmd = '~/.cargo/bin/racer'
    let g:racer_experimental_completer = 1
    

    No idea why it fails. Still doesn't work if I replace ~ with /home/legolord208, so it's not the expansion that is the problem.

    EDIT:

    Still doesn't work

    accidentally said "Works" at first


    TL;DR Omni completion (^O^N^P) Pattern not found

    reproduce ways 
    opened by jD91mZM2 35
  • Add tag stack

    Add tag stack

    gd currently exists to jump to a definition. Is it possible to add capabilities for a tag stack?

    I imagine that CTRL+] could use the same underlying jump-to-definition functionality that gd uses, with the addition that CTRL+T could pop us back to the previous location.

    I'd be interested in adding this myself, but don't know where to start.

    opened by twmb 16
  • Completion adds the whole token

    Completion adds the whole token

    In Vim and GVim on Windows when I type prin<C-x><C-o> then select println! I see prinprintln! in the buffer instead of println!.

    A short _vimrc is attached in case the fault is in there.

    cannot reproduce 
    opened by londospark 10
  • Ctrl+x + Ctrl+o does not work

    Ctrl+x + Ctrl+o does not work

    Ctrl + x + Ctrl + o (using mac's control key) does not bring up any completions for me. Sometimes it brings up "pattern not found" and at other times it seems to bring up my vimrc or take me to the top of the file I'm editing.

    I have racer installeed and working (the example command from the Racer readme returns the expected result)

    Racer / System info

    macOS Catalina 10.15.7 rustc 1.52.0-nightly (caca2121f 2021-03-05) racer 2.1.44 echo $RUST_SRC_PATH: /Users/murtyjones/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library

    ~/.vimrc

    set nocompatible              " be iMproved, required
    filetype off                  " required
    
    " set the runtime path to include Vundle and initialize
    set rtp+=~/.vim/bundle/Vundle.vim
    call vundle#begin()
    " alternatively, pass a path where Vundle should install plugins
    "call vundle#begin('~/some/path/here')
    
    " let Vundle manage Vundle, required
    Plugin 'VundleVim/Vundle.vim'
    
    Plugin 'racer-rust/vim-racer'
    
    " All of your Plugins must be added before the following line
    call vundle#end()            " required
    
    " ... redacted
    
    set hidden
    let g:racer_cmd = "/Users/murtyjones/.cargo/bin/racer"
    let g:racer_experimental_completer = 1
    let g:racer_insert_paren = 1
    
    invalid cannot reproduce 
    opened by murtyjones 9
  • Error

    Error "E117: Unknown function: racer#RacerComplete

    I installed racer globally and also I have the source installed by running rustup component add rust-src.

    I have the plugin in .vim/bundle/rust_racer/plugin/rust_racer.vim, downloaded from the ftplugin folder from this repo.

    And finally - in .vimrc I have:

    set runtimepath^=~/.vim/bundle/rust_racer
    
    " Set rust autocompletion tool "racer" ..
    set hidden
    let g:racer_cmd = "/home/petar/.cargo/bin/racer"
    let $RUST_SRC_PATH="/home/petar/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src"
    

    But when I open a rs file and try Ctrl+x + Ctrl+o - I get this error: Error "E117: Unknown function: racer#RacerComplete

    Any ideas?

    invalid 
    opened by peshoicov 9
  • No behaviour.

    No behaviour.

    I'm in linux using nvim 0.1.4.

    I cloned racer into ~/work/rust/lib, and ran cargo build. In my vimrc:

    Plug 'racer-rust/vim-racer'
    set hidden
    let g:racer_cmd='/home/ploppz/work/rust/lib/racer/target/debug/racer'
    let $RUST_SRC_PATH='/home/ploppz/work/rust/lib/racer/src/'
    

    But the plugin doesn't work. There's no useful completion, and hotkeys like gd don't do anything. It worked earlier. What changed since then is just that I cloned and built the racer repository anew. (edit: this is ~/work/rust/lib/racer)

    opened by Ploppz 9
  • Always the same completion

    Always the same completion

    It seems like I always get the same list of completions provided, no matter what I position my cursor after. Of course, if I've already written R then only the ones starting with R will be provided as options, but the "source list" from which it will provide the suggestions seems to be the same every time.

    The "available" completions are these:

    AsMut AsRef Box Clone Copy Debug Decodable Default DoubleEndedIterator Drop
    Encodable Eq Err ExactSizeIterator Extend FIXME Fn FnMut FnOnce From
    FromPrimitive Hash Into IntoIterator Iterator NB NOTE None Ok Option Ord
    PartialEq PartialOrd Rand Result RustcDecodable RustcEncodable Self Send Show
    Sized SliceConcatExt Some String Sync TODO ToOwned ToString Vec XXX abstract
    alignof as become bool box break char const continue crate display do else enum
    extern f32 f64 false final fn for i16 i32 i64 i8 if impl in isize let loop
    macro match mod move mut offsetof override priv pub pure ref return self size
    sizeof static str struct super trait transparent true type typeof u16 u32 u64
    u8 unsafe unsized use usize virtual where while
    

    For a one-completion-per-line list, read this gist.

    opened by linduxed 9
  • Question install instructions.

    Question install instructions.

    It seem like set omnifunc=syntaxcomplete#Complete is needed, or nothing works fro me. Is that expected ?

    Still it does not work perfectly C-x-C-o delete the start of the line before the token being completed. Am I doing something wrong ? Thanks.

    opened by Carreau 9
  • Should add an option to suppress stderr printout when racer panics

    Should add an option to suppress stderr printout when racer panics

    System info

    OS: Debian 10 nvim --version output:

    NVIM v0.3.7
    Build type: Release
    LuaJIT 2.0.5
    Compilation: /usr/bin/cc -Wconversion -O2 -DNDEBUG -DMIN_LOG_LEVEL=3 -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fdiagnostics-color=auto -Wno-array-bounds -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_UNIBI_HAS_VAR_FROM -I/home/mac/build_src/neovim/build/config -I/home/mac/build_src/neovim/src -I/home/mac/build_src/neovim/.deps/usr/include -I/usr/include -I/home/mac/build_src/neovim/build/src/nvim/auto -I/home/mac/build_src/neovim/build/include
    Compiled by mac@debian
    
    Features: +acl +iconv +jemalloc +tui
    

    Problem description:

    Racer keeps crashing under certain conditions and when it does and does so frequently, neovim is practically unusable because of the constant stderr output (read once per keystroke--I'm not kidding). Things get bad enough that sometimes it wouldn't accept any of my input unless I exit insert mode.

    Minimal init.vim

    call plug#begin('~/.config/nvim/vimplug')
    Plug 'rust-lang/rust.vim'
    Plug 'Shougo/deoplete.nvim', { 'do': ':UpdateRemotePlugins' }
    Plug 'racer-rust/vim-racer'
    call plug#end()
    
    let g:deoplete#enable_at_startup = 0
    augroup enable_deoplete
      autocmd!
      autocmd InsertEnter * call deoplete#enable() | autocmd! enable_deoplete
    augroup END
     
    if !exists('g:deoplete#omni#input_patterns')
      let g:deoplete#omni#input_patterns = {}
    endif
    let g:racer_cmd = $HOME . "/.cargo/bin/racer"
    let g:racer_insert_paren = 0
    

    Steps to reproduce

    Here is a MWE to crash racer: https://github.com/macthecadillac/mwe/blob/master/src/lib.rs

    Proceed to the bottom of the file, start and new line, and type impl_vec_eq_test!(f64: abs);. Racer should crash and make deoplete print a bunch of stderr junk once you get to "6" and should continue doing so for every letter you type until you get to "a", at which point it will block you from inserting more text unless you type space or exit insert mode.

    opened by macthecadillac 8
  • vim-racer conflicting with neocomplete?

    vim-racer conflicting with neocomplete?

    I seem to have a weird cross interaction with vim-racer and neocomplete.

    If you look at the following gif, you see what happen when I type .unwrap(). As you can see something is "eating" some of the letters. If I disable either vim-racer or neocomplete this doesn't happen. The letters that get eaten are not always the same, at another time I got .uwrp() as result.

    racer-complete

    Both plugins are on default settings as per their READMEs.

    I don't know what is causing this, so I can't really offer any debug information upfront. Please just ask for what you need.

    opened by jinks 8
  • No racer executable found in $PATH

    No racer executable found in $PATH

    Hi.

    I installed racer and this plugin, and configure them.
    I can launch racer using /Users/antonin/.cargo/bin/racer, and it works!
    But, when I try gd in a simple line like use std::, Vim returns :

    No racer executable found in $PATH ...
    :/Users/antonin/.cargo/bin/racer
    :/Users/antonin/.cargo/bin...
    

    And that's weird, because the racer executable is in the PATH environment :-/

    Anyone here has a solution to test please?

    opened by k0pernicus 8
  • third party crate support with mirror file path

    third party crate support with mirror file path

    I'm using a rust crate mirror links: mirrors.ustc.edu.cn and racer with vim YCM when I update dependents library, the third party crate source code is just download into the .cargo/registry/src/mirrors.ustc.edu.cn-XXXX/ path. but I found that, racer does not catch the right define of the crate code. just show Errors: "RuntimeError: Can't jump to definition." how could I resolve this problem. any help will be appreciate, thanks.

    opened by zhiyuan-liao 1
  • Completion does not show after newline

    Completion does not show after newline

    If you split a chain of invocations into multiple lines (according to style guidelines. This is also what rustfmt does) the completion won't work

    use std::io;
    
    fn main() {
        println!("Guess the number!");
    
        let mut guess = String::new();
        io::stdin()
            .r // here, the completion won't work 
        println!("You guessed {}", guess);
    }
    

    The completion popup does not show on its own, but also when you press C-xC-o

    racer problem 
    opened by jrosiek 1
  • Some elements are missing completion options

    Some elements are missing completion options

    If I have

        let mut file = try!(File::open(file_path).map_err(|e| e.to_string()));
        let mut contents = String::new();
    

    Then contents.<C-x C-o> gives a good list of completion options, all appropriate for String, showing that vim-racer is indeed working properly. However, file.<C-x C-o> doesn't find anything: Pattern not found. Things like read_to_string, which are properly defined for File, can successfully be used, and the program successfully compiles, however.

    racer problem 
    opened by Giels 1
Releases(1.0)
Owner
null
Language Server Protocol (LSP) support for vim and neovim.

For legacy python implementation, see branch master. LanguageClient-neovim Language Server Protocol support for vim and neovim. More recordings at Upd

Junfeng Li 3.5k Dec 29, 2022
Vim configuration for Rust.

rust.vim Description This is a Vim plugin that provides Rust file detection, syntax highlighting, formatting, Syntastic integration, and more. It requ

The Rust Programming Language 3.4k Jan 8, 2023
N vim win! Neovim UI designed for Sway/i3.

Nwin This is an experimental Neovim UI that creates a new OS window for each Neovim window, all backed by the same neovim server. This enables perform

Ghjuvan Lacambre 86 Dec 29, 2022
A vim profiling tool

vim-profiler ?? vim-profiler is a wrapper around the (n)vim --startuptime command, written in Rust. The binary is called vp and has only been tested o

Liam 35 Dec 14, 2022
Vim-fork focused on extensibility and usability

Documentation | Chat | Twitter Neovim is a project that seeks to aggressively refactor Vim in order to: Simplify maintenance and encourage contributio

Neovim 61k Jan 2, 2023
Convert VSCode themes to (Neo)Vim colorschemes

Djanho is a prototype which tries to convert VSCode themes to (Neo)Vim colorschemes. Features Handling of VSCode RGBA colors Out of the box conversion

Vinícius Müller 73 Jan 2, 2023
Apprentice-vscode - a port of @romainl’s excellent Apprentice Vim colour scheme to VS Code

Apprentice for VS Code apprentice-vscode is a port of @romainl’s excellent Apprentice Vim colour scheme to VS Code. The theme is available in two vari

Luna Razzaghipour 6 Dec 21, 2022
IDE tools for writing pest grammars, using the Language Server Protocol for Visual Studio Code, Vim and other editors

Pest IDE Tools IDE support for Pest, via the LSP. This repository contains an implementation of the Language Server Protocol in Rust, for the Pest par

pest 20 Apr 8, 2023
Rust language support in Atom - LOOKING FOR MAINTAINER, see #144

Rust language support in Atom Adds syntax highlighting and snippets to Rust files in Atom. Install Install the package language-rust in Atom (Preferen

Andreas Neuhaus 118 Oct 11, 2022
Rust IDE support for Atom, powered by the Rust Language Server (RLS)

IDE-Rust Rust language support for Atom-IDE, powered by rust-analyzer. Features Auto-completion Diagnostics (errors and warnings from rustc) Document

The Rust Programming Language 239 Dec 14, 2022
Better Rust/Cargo support for Flycheck

flycheck-rust — Flycheck for Rust This Flycheck extension configures Flycheck automatically for the current Cargo project. Setup Install from MELPA or

Flycheck 112 Sep 21, 2022
Rust extension for Visual Studio 2017 with RLS support

Rust support for Visual Studio 2017 Preview Adds language support for Rust to Visual Studio 2017. Supports: code completion goto definition find all r

Zoey Riordan 111 Aug 4, 2022
Fennel language server protocol (LSP) support.

fennel-language-server Fennel language server protocol (LSP) support. fennel-language-server is currently in a very early stage and unreliable. Use it

null 68 Dec 27, 2022
Racer support for Emacs

Racer for Emacs This is the official Emacs package for Racer. Table of Contents Racer for Emacs Completion Find Definitions Describe Functions and Typ

null 398 Nov 30, 2022
Easy c̵̰͠r̵̛̠ö̴̪s̶̩̒s̵̭̀-t̶̲͝h̶̯̚r̵̺͐e̷̖̽ḁ̴̍d̶̖̔ ȓ̵͙ė̶͎ḟ̴͙e̸̖͛r̶̖͗ë̶̱́ṉ̵̒ĉ̷̥e̷͚̍ s̷̹͌h̷̲̉a̵̭͋r̷̫̊ḭ̵̊n̷̬͂g̵̦̃ f̶̻̊ơ̵̜ṟ̸̈́ R̵̞̋ù̵̺s̷̖̅ţ̸͗!̸̼͋

Rust S̵̓i̸̓n̵̉ I̴n̴f̶e̸r̵n̷a̴l mutability! Howdy, friendly Rust developer! Ever had a value get m̵̯̅ð̶͊v̴̮̾ê̴̼͘d away right under your nose just when

null 294 Dec 23, 2022
Language Server Protocol (LSP) support for vim and neovim.

For legacy python implementation, see branch master. LanguageClient-neovim Language Server Protocol support for vim and neovim. More recordings at Upd

Junfeng Li 3.5k Dec 29, 2022
Aspiring vim-like text editor

Rim Rim is an aspiring Vim-like text editor written in Rust. Current state Rim is in an early prototype stage. This means that you can load, edit and

Mathias Hällman 557 Jan 2, 2023
Vim configuration for Rust.

rust.vim Description This is a Vim plugin that provides Rust file detection, syntax highlighting, formatting, Syntastic integration, and more. It requ

The Rust Programming Language 3.4k Jan 8, 2023
N vim win! Neovim UI designed for Sway/i3.

Nwin This is an experimental Neovim UI that creates a new OS window for each Neovim window, all backed by the same neovim server. This enables perform

Ghjuvan Lacambre 86 Dec 29, 2022
hackernews_tui is a Terminal UI to browse Hacker News with vim-like key bindings.

hackernews_tui is written in Rust with the help of Cursive TUI library. It uses HN Algolia search APIs to get Hacker News data.

Thang Pham 364 Dec 28, 2022