Vim error navigation

I was just checking out Vim development environment for Rust. I have code completion through RLS and code navigation with Racer setup.

What plugins are recommended for convenient building, error browsing, and debugging (gdb/lldb) ?

Checkout Development best practices and especially search for the quickfix list (vim related part) …

1 Like

99% of the time I've found you can get away with using dual screens where vim is open on the primary monitor and then a couple open terminal windows on my secondary monitor (tmux is great for working with multiple terminals at the same time).

For compiling, you should have a look at cargo-watch. It's a tool which watches your source code and will automatically do something whenever any of the files gets updated. By default it'll just run cargo check, but I also get it to run my tests and regenerate documentation (cargo watch --exec check --exec test --exec "doc --document-private-items"). You can think of cargo watch as the CLI equivalent of live reload in a web app.

To be honest, the error messages from rustc (just run from the terminal) are some of the best I've ever seen. We use C# at work and I find Visual Studio to be nowhere near as useful at explaining an error. That said, for a fast "hey there's an error on this line" (which is usually all that's needed with most simple issues) I use vim's RLS integration. It gives you a fairly unobtrusive "x" next to the error's line.

I actually can't remember the last time I needed to reach for a debugger when doing Rust development. Having a powerful type system and unit testing as a first-class citizen means a lot of time if it compiles and the tests pass, you're good to go. Gdb is quite solid and it can debug Rust code about as well as C++, although as far as I know Rust doesn't (yet?) have anything as useful/powerful as the C# debugger in Visual Studio :frowning_face:

That's just my setup and what works for me though. Your mileage may vary.


With rust.vim or new enough Vim that includes Rust support, you can just set :compiler cargo, and then :make build works natively.

I also like vim-dispatch with its asynchronous :Make, and it includes a few easy key mappings.

error browsing

The builtin :cnext and :cprev for the quickfix list should be fine. There’s also vim-unimpaired which maps these to ]q and [q.

debugging (gdb/lldb)

This has been challenging for a long time. Conque GDB kind of worked, but I found it easier to just run GDB in its own tmux pane. Starting with Vim 8.1 though, the new :Termdebug actually works pretty well! (I think neovim had something like this first, FWIW.)

deoplete and neomake for handling errors on write and easy jumping between them.

let g:rustfmt_autosave_if_config_present = 1                                                                                              

for rustfmt on write.

I like ALE for error navigation. You have to map your own key combo for jumping previous and next errors:

nmap <silent> <C-k> <Plug>(ale_previous_wrap)
nmap <silent> <C-j> <Plug>(ale_next_wrap)

In that example Ctrl-K is previous and Ctrl-J is next.

1 Like

Thats quite a lot of suggestions that I expected. Its quite rejuvenating to get so many suggestions! Thank you everyone!