The Trouble Plugin in Neovim

Adam Drake
3 min readAug 26, 2024

--

AI made this and I didn’t even pay for it

I have been using the trouble.nvim plugin in Neovim for a while now and it really has improved my development experience. I work predominantly in Typescript and as such I run into many type errors throughout the day.

When working in large codebases, half the battle is finding the right file to update and then finding the right code in that file which needs fixing. This is where Trouble comes in. It provides a convinient interface to list all the current errors or warnings you may have and enables you to find them quickly.

Working With Trouble

When you are working in a file that has warnings or errors, you can open the Trouble window pane (in the latest version this is configurable in how it opens) and it lists all the errors/warnings that are in that file (or any file you have open in Neovim).

You can then traverse this list and if you select any item in this list then you jump to the specific line in the code where that item happens to be. This way you can quickly and easily navigate to where you errors/warnings are and fix them one by one.

Setting Up Trouble

On the Trouble Github page there are plenty of instructions about how to setup and configure the Trouble plugin. The standard setup and installation if you are using Lazy plugin manager is the following:

{
"folke/trouble.nvim",
opts = {}, -- for default options, refer to the configuration section for custom setup.
cmd = "Trouble",
keys = {
{
"<leader>xx",
"<cmd>Trouble diagnostics toggle<cr>",
desc = "Diagnostics (Trouble)",
},
{
"<leader>xX",
"<cmd>Trouble diagnostics toggle filter.buf=0<cr>",
desc = "Buffer Diagnostics (Trouble)",
},
{
"<leader>cs",
"<cmd>Trouble symbols toggle focus=false<cr>",
desc = "Symbols (Trouble)",
},
{
"<leader>cl",
"<cmd>Trouble lsp toggle focus=false win.position=right<cr>",
desc = "LSP Definitions / references / ... (Trouble)",
},
{
"<leader>xL",
"<cmd>Trouble loclist toggle<cr>",
desc = "Location List (Trouble)",
},
{
"<leader>xQ",
"<cmd>Trouble qflist toggle<cr>",
desc = "Quickfix List (Trouble)",
},
},
}

To be honest I haven’t really needed to change this default configuration. The main usage I get out of Trouble is the ‘Diagnostics (Trouble)’ command with the keymap <leader>xx Whenever I have some type errors in my code I press this keymap and it brings up a list of these errors in a separate pane.

An example would be something like this:

List of linting and type errors produced by the Trouble plugin

As I navigate through this list (using the Vim motions) it highlights the specific code is the open file in Neovim. This plugin has really made my navigating of errors and warnings in my code much more efficient.

Conclusion

Errors in your code are not fun but it’s much better to catch these errors when you are developing rather than waiting until your app is out in the wild and your users are catching them.

Trouble is a plugin that can really help you with this and improve your overall development experience.

Subscribe to My Weekly Updates!

Enjoyed This Post?

If you found this blog post helpful, why not stay updated with my latest content? Subscribe to receive email notifications every time I publish. New posts go live every Monday at 8:30 AM Central European Time.

What You’ll Get

By subscribing, you’ll get:

  • Exciting Discoveries: Be the first to know about the latest tools and libraries.
  • How-To Guides: Step-by-step articles to enhance your development skills.
  • Opinion Pieces: Thought-provoking insights into the world of frontend development.

Join Our Community

I live in the vibrant city of Prague, Czech Republic, with my family. My blog is more than just articles; it’s a community of like-minded developers who share a love for innovation and learning.

About me

I’m a passionate Frontend Developer specialising in React and TypeScript. My professional journey revolves around exploring and mastering new tools and libraries within the JavaScript ecosystem.

Check out the original blog post on my blog.

Check out my LinkedIn and Github if you are interested.

--

--

Adam Drake
Adam Drake

Written by Adam Drake

I'm a Frontend Developer and I write about all things Frontend Related - Think lightly of yourself and deeply of the world. Based in Prague, CZ

No responses yet