Recently I reviewed Hop.nvim and really liked the ability to use the Lua API and enhance the f, F, t, T
motions to display hints. I remarked in the video that I wanted to figure out how to bring this into Flash.nvim since I preferred other features of that plugin, and someone showed me that it was already in Flash.nvim!
I’ll show you how to add this to your config to get some nice hints as well.
From a previous video / blog post, here is what the default Flash.nvim f
experience looks like:
It highlights going forward and has the character highlighted and you can jump across many lines.
Thanks to shyam1602 for bringing this up, we can update our config by using the built in Flash.nvim functionality!
We need to add a couple items to the opt section of the config.
The first option is to jump automatically when there is a single match.
opts = {
jump = {
autojump = true,
},
},
Instead of showing hints, we will just jump.
Now we can constrain jumping to only a single line (I prefer this and use jump()
when I want to do multiline) and also display jump_labels:
opts = {
jump = {
autojump = true,
},
modes = {
char = {
jump_labels = true,
multi_line = false,
}
}
},
Now when we trigger f we should see labels on a single line when there are multiple matches, or jump right to a character when only a single match exists.
Complete Config
{
"folke/flash.nvim",
event = "VeryLazy",
---@type Flash.Config
opts = {
jump = {
autojump = true,
},
modes = {
char = {
jump_labels = true,
multi_line = false,
}
}
},
-- stylua: ignore
keys = {
{ "s", mode = { "n", "x", "o" }, function() require("flash").jump() end, desc = "Flash" },
{ "S", mode = { "n" }, function() require("flash").treesitter() end, desc = "Flash Treesitter" },
{ "r", mode = "o", function() require("flash").remote() end, desc = "Remote Flash" },
{ "R", mode = { "o", "x" }, function() require("flash").treesitter_search() end, desc = "Treesitter Search" },
{ "<c-s>", mode = { "c" }, function() require("flash").toggle() end, desc = "Toggle Flash Search" },
},
}
Conclusion
If you have other tips or tricks with using Flash.nvim then please let me know and I will share any others that I come across myself. Hope you enjoyed this and gotten value from it!