First of all i’d like to say hello to the Rust community . I’m very new to Rust : i’ve just finished the 5th chapter of the book .
Now I want to configure a development environment based on VIM and I’m a bit confused because when searching for ‘vim rust’ apparently there are too many plugins for vim . And … I’m not sure how to find out which of them are mature and which are just prototypes .
The ‘are we ide yet’ website mentions several vim plugins (rust.vim, YouCompleteMe, vim-racer ,…) but it’s unclear whether they are alternatives that do the same thing, or if they need to be installed together.
So my question is : what vim plugin(s) do you recommend me to install in order to have
- colored syntax for rust
- code completion (if i understand correctly there is a tool called racer that can be used by editors)
- nice to have : a left pane for files browsing
Thanks in advance for any suggestion!
Yep, pretty much this! I use NERDTree for a left pane / file browser that I can toggle when I need to.
I went through my gross and gnarly vimrc and trimmed it down to something that’s possibly helpful. It’s a combination of my personal stuff and https://dougblack.io/words/a-good-vimrc.html . You’ll need to be using vim8 and install https://github.com/junegunn/vim-plug .
" Vim recommended
filetype plugin indent on
if has('syntax') && !exists('g:syntax_on')
set hidden " Allows you to switch buffers without saving current
set wildmenu "tab completion
set wildmode=longest:full,full " First tab brings up options, second tab cycles
let mapleader = ","
noremap ,, ,
" treat wrapped lines as different lines
nnoremap j gj
nnoremap k gk
" Enable mouse support
" Set 7 lines to the cursor - when moving vertically using j/k
" Always show current position
" Remove bell
" Better searching
set wrapscan "wraps around end of file
" Redraw screen and clear highlighting
nnoremap <Leader>r :nohl<CR><C-L>
" Don't redraw while executing macros (good performance config)
" Show matching bracket
" Configure backspace so it acts as it should act
" Return to last edit position when opening files (You want this!)
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal! g`\"" |
" Close nerdtree after a file is selected
let NERDTreeQuitOnOpen = 1
return exists("t:NERDTreeBufName") && (bufwinnr(t:NERDTreeBufName) != -1)
" CtrlP using ripgrep
set grepprg=rg\ --color=never
let g:ctrlp_user_command = 'rg %s --files --color=never --glob ""'
let g:ctrlp_use_caching = 0
" If nerd tree is closed, find current file, if open, close it
nmap <silent> <leader>f <ESC>:call ToggleFindNerd()<CR>
nmap <silent> <leader>F <ESC>:NERDTreeToggle<CR>
set statusline=%f\ %h%w%m%r\ %=%(%l,%c%V\ %=\ %P%)
" Ale syntax checking
let g:ale_rust_cargo_use_check = 1
" use Ctrl-k and Ctrl-j to jump up and down between errors
nmap <silent> <C-k> <Plug>(ale_previous_wrap)
nmap <silent> <C-j> <Plug>(ale_next_wrap)
Open up a file, and run PlugInstall() to have vimplug download the plugins. This vimrc gets you a couple of goodies
- rust-vim: Provides rust language support/syntax highlighting.
- Ale: Error checking based off of cargo check. Use ctrl-j and ctrl-k to jump between errors
- NerdTree: A file explorer. Use f to open up the side pane (I have leader set to comma)
- Ctrl-P: Fuzzy file finding. Hit ctrl-p and type a file name, and it will show you files in your directory with that name. You can then open that file. If you have ripgrep installed, ctrl-p will use it to do the search.
- SuperTab: Basic tab completion (just based off of words already in your file).
I’ve built something that I use for Rust, check it out here https://github.com/spastorino/vinimum/tree/vinimum2 is the vinimum2 branch. master doesn’t have any Rust stuff but have some other goodies. I’m going to keep adding general purpose plugins as the thing has in master but for now I’m just trying to use a bare thing that works for Rust.
It basically has rust.vim, ale, snippets/ultisnips and YouCompleteMe and some cool configs. I still need to make ctags autogenerate when saving a file and things like that.
Thanks for the suggestions! Now I have a good starting point for experimenting a bit with different plugins and settings .
Note that Vim 8.0 comes with rust.vim so if all you want is syntax highlighting you don’t need to do anything.
Hey, great job making the vimrc, I agree with basically all of what is on there. Just wanted to add that the function ToggleFindNerd() is completely unnecessary. You can achieve the same functionality with
nmap <silent> <leader>f :NERDTreeToggle %<CR>
Anyone had luck with getting RLS working? I have it installed via vim-plug using the instructions in the README, but none of the keymappings shown in the README work.
K does nothing. both
gd and the F2 key make “Not found!” appear in the status line. When I first open a Rust source file in Vim, the status line displays “LanguageClient project root: /path/to/repo” but doesn’t show any sort of “initializing” or “complete” message.
Yes, RLS works easily. Installing it via vim-plug sounds like the wrong thing to do, which README are you referring to? Did you check
:messages if there’s any kind of error? Which client pluting are you using?
It looks like it actually is working — I suspect what happened before is that I coincidentally tried the keybindings on types that were in dependent crates and hence it couldn’t jump to their definitions.
Also, to clarify, I installed RLS itself through rustup. It’s LanguageClient-neovim that I installed with vim-plug.
Ok, that makes a lot more sense Great it’s working for you
I highly recomend YouCompleteMe for reasonable racer autocometion out of the box.