Skip to content

Instantly share code, notes, and snippets.

@PeterDing
Last active August 6, 2017 15:13
Show Gist options
  • Save PeterDing/6e80966c0a14f07a8517cfad5f1fb93c to your computer and use it in GitHub Desktop.
Save PeterDing/6e80966c0a14f07a8517cfad5f1fb93c to your computer and use it in GitHub Desktop.
Rust code completion for neovim

Rust code completion for neovim

Using vim-racer and racer.

racer

  1. Install racer

    cargo install racer

  2. Fetch the Rust sourcecode

    rustup component add rust-src

  3. Set the RUST_SRC_PATH

    export RUST_SRC_PATH="$(rustc --print sysroot)/lib/rustlib/src/rust/src"

  4. Test on the command line

    racer complete std::io::B

vim-racer

  1. Add to vim-plug

    Plug 'racer-rust/vim-racer'

  2. Add g:racer_cmd to init.vim

    set hidden
    let g:racer_cmd = "/path/to/racer/bin"
    
  3. To show the complete function definition (e.g. its arguments and return type)

    let g:racer_experimental_completer = 1
    
  4. GoTo definations

    au FileType rust nmap gd <Plug>(rust-def)
    au FileType rust nmap gs <Plug>(rust-def-split)
    au FileType rust nmap gx <Plug>(rust-def-vertical)
    au FileType rust nmap <leader>gd <Plug>(rust-doc)
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment