This plugin enables viewing the locations found in a .bacon-locations
file, and jumping to them.
This extension may be imported with a standard plugin system.
Plug 'Canop/nvim-bacon'
In eg lua/config/plugins/bacon.lua
:
return {
-- other plugins
{
"Canop/nvim-bacon",
config = function()
require("bacon").setup({
quickfix = {
enabled = true, -- Enable Quickfix integration
event_trigger = true, -- Trigger QuickFixCmdPost after populating Quickfix list
},
})
end,
},
}
You must enable locations export in bacon.
Change/uncomment the exports part of your prefs.toml file:
[exports.locations]
auto = true
path = ".bacon-locations"
line_format = "{kind} {path}:{line}:{column} {message}"
You'll use this plugin in nvim while a bacon instance is running in another panel, probably side to it.
To navigate among errors and warnings, you'll use either the standard Quickfix feature of your editor or nvim-bacon dedicated commands and view.
The following functions are exposed by the plugin:
Function | Usage |
---|---|
:BaconLoad |
Silently load the locations of the .bacon-locations file |
:BaconShow |
Display the locations in a floating window |
:BaconList |
Does :BaconLoad then :BaconShow |
:BaconPrevious |
Jump to the previous location in the current list |
:BaconNext |
Jump to the next location in the current list |
You should define at least two shortcuts, for example like this:
nnoremap ! :BaconLoad<CR>:w<CR>:BaconNext<CR>
nnoremap , :BaconList<CR>
or, if using lazyVim, in lua/config/keymaps.lua:
local map = LazyVim.safe_keymap_set
map("n", "!", ":BaconLoad<CR>:w<CR>:BaconNext<CR>", { desc = "Navigate to next bacon location" })
map("n", ",", ":BaconList<CR>", { desc = "Open bacon locations list" })
The first shortcut navigates from location to location, without opening the window.
This is probably the one you'll use all the time.
You may notice it loads the list (:BaconLoad
) then saves the current document (:w
), to prevent both race conditions and having a bunch of unsaved buffers.
The second shortcut, which is mapped to the , key, opens the list of all bacon locations:
When the list is open, you can select a line and hit enter or just hit the number of the location if it's in 1-9. As there's no need to wait for the window to appear, you may just type ,3 to go to location 3 without opening the window.
You may define other shortcuts using the various API functions.
Errors and warnings also populate the Quicklist list by default.
You can disable this feature with this configuration:
require("bacon").setup({
quickfix = {
enabled = false, -- true to populate the quickfix list with bacon errors and warnings
event_trigger = true, -- triggers the QuickFixCmdPost event after populating the quickfix list
}
)}