Which is Better Flash.nvim OR Leap.nvim?
Which plugin has the best features and is the most flexible?
One of the best features of Vim and Neovim is the ability to be precise in your editing.
There are many different ways to jump to different locations in a buffer using native capabilities, as well as utilizing plugins.
I have been using Leap.nvim for quite awhile on my Neovim journey and have been mostly satisfied. Admittedly, I have leaned more on native
functionality and will occasionally remember that I don’t need to only jump between paragraphs using [
or ]
.
If you haven’t read my recent article about Leap.nvim then check it out here.
I have had a lot of fun with Leap.nvim but certainly there are some things that are hard to get used to without continually working on the muscle memory.
The number of times that I have tried to type more or less than 2 characters to jump to a location and ended up with a bad outcome is higher than I would like.
This is what led me to try Flash.nvim and I have been using it for the last week and I must say it does a lot right and feels less of a mental burden than Leap.nvim.
GitHub - folke/flash.nvim: Navigate your code with search labels, enhanced character motions and…
Navigate your code with search labels, enhanced character motions and Treesitter integration - folke/flash.nvimgithub.com
Let’s get into how to setup Flash.nvim, the keymappings and some features and workflows that you can start using and then we will compare that to Leap.nvim.
Installation and Configuration
Install the plugin using your favorite package manager, for me that is lazy.nvim. If you are still using Packer then checkout this article on migrating to lazy.
Add this config into your plugins Lua table or into a Lua file if you prefer that approach.
{
"folke/flash.nvim",
event = "VeryLazy",
- -@type Flash.Config
opts = {},
- stylua: ignore
keys = {
{ "s", mode = { "n", "x", "o" }, function() require("flash").jump() end, desc = "Flash" },
{ "S", mode = { "n", "x", "o" }, 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" },
},
}
After adding this config, restart Neovim and you should see Flash.nvim install successfully.
You will notice that we are setting up several keymappings to call different functions of Flash.nvim. Each of these is a different way to use Flash and I will go through each of these in the Usage section.
Note: Feel free to adjust the keymappings in your own config, especially if you have conflicts. You can check for conflicts using
require(“telescope.builtin”).keymaps
OR using:checkhealth
and looking at WhichKey (requires plugin installation).
Usage
Now that we have Flash.nvim installed and ready, open up a file and let’s start with some basic usage.
Jumping to a location
The main way that I interact with Flash.nvim is using require(“flash”).jump()
which I have mapped to s
.
When you hit s
in normal mode you will see the text on screen gray awaiting your next characters.
Note: If you don’t see the text gray then it may be due to your colorscheme, I am using Tokyonight so give that a try.
Now you can type 1 or many characters for where you want to jump and you will see orange highlights for matched characters and red for your “jump labels”. Hitting Enter will jump you to the first match OR hitting the specific key for a jump label will take you to that match. Labels are guaranteed not to exist as a continuation of the search pattern so you don’t need to worry about conflicts and jumping to the wrong location.
You can jump up or down in your current buffer AND across splits using only s
!
Treesitter Mode
Another great feature of Flash.nvim is to visually highlight blocks using require(“flash”).treesitter()
which I have mapped to S
.
Note: I remapped this only for normal mode instead of “x” and “o” so that it didn’t conflict with nvim-surround.
This utilizes Treesitter to parse the text and understand logical blocks to grab and then flash presents each of them as jump labels for you to quickly highlight. When you hit S
in normal mode you will see the current line highlight and several jump labels appear. Hitting the key for one of them will highlight that block of text for you to then copy, change or delete how you want.
Remote Flash
Remote Flash lets you perform actions remotely, I have require(“flash”).remote()
to r
. You can use this with motions similar to Treessitter Search and your cursor will be placed back in the original position.
For example, press yr
to start yanking and open flash
- select a label to set the cursor position
- perform any motion, like iw
or $
- yank will be performed on the new selection
- you’ll be back in the original window / position
Treesitter Search
This feature of Flash.nvim can be combined with a Vim motion to do all sorts of really cool workflows.
I have require(“flash”).treesitter_search()
mapped to R
, so if I type yR
then that will trigger Treesitter Search. Next type 1 character to show different labels. Now pick what text you want to yank and you will grab it. Then you can hit g;
to jump back to where you were editing and paste that text.
Toggle Flash Search
To enable jump labels when you are searching text using /
or ?
, you can toggle Flash Search on.
When in Command Mode (e.g. hit : first), use <C-s>
(aka Control + s). Then hit Esc and hit / and start typing some characters. You will see jump labels appear like when using s
and you can jump to that label using that key.
Enhanced f, F, t, T
If you are already using f, F, t, T then these get some cool additional behavior for free from Flash.nvim.
Hitting f will gray out the text below your cursor and after you hit a single key, will jump to the first match and see all matches highlighted. You can then use f or ; to go through the matches and F or , to go backwards.
The same applies for F and if you use t or T then you will jump to the character before the matched character as you would expect (use t to progress forward and T to progress backwards).
Comparison — Flash OR Leap
Both Flash and Leap deliver on having a solution to quickly jump to a location quickly within a buffer or split. One of the key differences is HOW you accomplish this.
Leap needs you to type 2 characters before you can jump to a location using the default configuration. Flash allows you to be much more flexible in how much or little you type when jumping. In practice this helps significantly when you are in flow state and need to jump somewhere. To me, this is the key differentiator in Flash.nvim being easier on my mental load and plugging better into my workflow. Layer in the fact that you only need to use s
to jump up or down or across splits and Flash.nvim only requires you to remember 1 keybinding instead of 3 for the default use case.
In my opinion Flash.nvim delivers better on this default use case and we haven’t even talked about the other really cool features.
The enhanced f, F, t, T is really nice and is a fast way to quickly jump within a line or even a few lines in either direction. I probably will use this less over time as I lean more into using s
but we will see!
Treesitter Mode is going to let me quickly grab blocks when I am coding and I can already see the benefit in using this. I think this is a better option and less to remember than using Treesitter TextObjects.
Remote Flash and Treesitter Search are both something I need to spend more time digging into but the idea of being able to yank some text in a different place and then have my cursor jump right back to where I was sounds VERY nice for coding sessions. There are so many times that I want to clone a function to get the boiler plate and then modify a couple fields. If you use this yourself or have ideas on workflows then definitely leave a comment so I can start using that as well.
I think the Flash Search is nifty but probably not something I would use in practice. If I am searching I am expecting the default capabilities, which are different in my mind that jumping.
Flash.nvim Benefits
Flexible number of matching characters entered before jumping
Nice highlighting in different colors when typing to differentiate matches from jump labels
Treesitter Mode is nice for grabbing blocks of text
Using
s
to search both directions AND across splits
Note: You are able to extend Leap.nvim to get some of these abilities, like enhanced f, t and also selecting Treesitter nodes. Check out that here.
Conclusion
I hope this has given you great information on being able to not only use Flash.nvim but also give Leap.nvim a try and decide for yourself which plugin you prefer. I am going to continue my journey of experimenting with other jumping plugins like hop.nvim and mini.jump so stay tuned for more to come on the different plugins that allow you to more precisely navigate your code and text documents. Thanks again for reading and have a great day!