Skip to content

Instantly share code, notes, and snippets.

@jodh-intel
Created July 6, 2022 17:02
Show Gist options
  • Save jodh-intel/7bde3e2405a39c898f48ec8b7dd0d374 to your computer and use it in GitHub Desktop.
Save jodh-intel/7bde3e2405a39c898f48ec8b7dd0d374 to your computer and use it in GitHub Desktop.

Install rust

Install the rust language server and clippy tools:

$ rustup component add rustfmt rls
$ rustup component add clippy

Configure vim

Modify ~/.vimrc to include some/all of the following:

call plug#begin('~/.vim/plugged')

Plug 'tpope/vim-fugitive' " for git commands
Plug 'preservim/tagbar'   " OMG essential
Plug 'rust-lang/rust.vim', {'for': 'rust'}
Plug 'racer-rust/vim-racer', {'for': 'rust'}

" Fuzzy finder
Plug 'junegunn/fzf', { 'do': './install --bin' }
Plug 'junegunn/fzf.vim'

Plug 'dense-analysis/ale'

let g:deoplete#enable_at_startup = 1
let g:ale_completion_enabled = 1
let g:ale_completion_autoimport = 1
let g:ale_update_tagstack = 1
let g:ale_rust_cargo_use_clippy = executable('cargo-clippy')

let g:ale_linters = {
            \ 'rust': ['rls', 'cargo', 'rustc'],
            \}

let g:ale_fixers = {
            \   '*': ['remove_trailing_lines', 'trim_whitespace'],
            \   'rust': ['rustfmt', 'trim_whitespace', 'remove_trailing_lines'],
            \}

" Check test and example code too
let g:ale_rust_cargo_check_tests = 1
let g:ale_rust_cargo_check_examples = 1

call plug#end()

" press "gd" to jump to definition (and CTRL-t to return).
:au FileType rust nmap gd <Plug>(rust-def)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment