One of the best features of Vim and Neovim is the ability to be precise in your editing.
Using [ or ] you can quickly jump up or down paragraphs of text and using f, t, F, T you can jump to exact characters in a line.
Add in jump lists and using Ctrl+o and Ctrl+i to jump back and forth between buffers and you can stay in flow state and edit text.
Yet another way is to use line numbers (or relative line numbers) to jump to a specific line to edit text.
There are other plugins that take this to the next level and allow you to jump to exact location in a line or on a separate window.
The plugin I have started with is Leap.nvim and I will show you how to install, use and incorporate it into your workflow.
There are also alternatives to Leap.nvim that I will explore and do comparisons with Leap.nvim to find the best plugin for location jumping,
so stay tuned for even more information on jumping!
Installation
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.
{
"ggandor/leap.nvim",
config = function()
local leap = require('leap')
leap.add_default_mappings()
leap.opts.case_sensitive = true
end,
},
After adding this config, restart Neovim and you should see Leap.nvim install successfully.
Note: leap.nvim depends on repeat.vim for dot-repeats to work.
The config above includes setting up the default keymappings, if you prefer to override these then check out the docs here:
https://github.com/ggandor/leap.nvim?tab=readme-ov-file#mappings
I personally prefer to have the jumps match case_sensitive, if you do not like this then you can leave out that config line.
Usage
Now that you have the plugin installed, open up a buffer and let’s start jumping around!
Jumping forward
Initiate the search using
s
Start typing a 2-character pattern (
{char1}{char2}
) that you want to jump to.After typing the first character, you will see labels appearing next to some of the
{char1}{?}
pairs. You cannot use the labels yet (make sure to always finish typing two characters).
Enter `{char2}`. If the pair was not labeled, then you will jump there automatically. If there are multiple matches, type the label character and you will jump there.
Note: You can hit
v
to enter insert mode and thens
to start leap to visually select text.
Jumping backward
Follow the same steps above but use S
instead of s
.
The same matching logic applies for matching and using labels.
Note: I personally am not able to get visual selection to work going backwards by hitting v
and then using S
. I am unsure if this is my config or a limitation of the plugin.
Jumping across windows (aka splits)
Follow the same steps above but use gs
instead of s
.
The same matching logic applies for matching and using labels.
Open two splits using :vs
and then gs
to jump to the other window.
Jumping to end of lines
Since there is no set of characters to match when jumping to the end of a line, you need a special combination.
A character at the end of a line or with a space following it can be targeted by pressing <space>
after it.
In practice, you hit s
and then <char><space>
OR s
, then <space><space>
to jump to the end of a line.
Searching
If you have already jumped but want to jump to the next match, s<enter> uses the previous search pattern.
Additional Features
If you want to customize anything about leap.nvim then check out their FAQ section and it will likely have what you are looking for.
https://github.com/ggandor/leap.nvim?tab=readme-ov-file#faq
Conclusion
I hope this has helped you to learn about leap.nvim and have another way to jump around within a buffer or across splits in Neovim. I am still getting used to hitting s
instead of f
or F
to jump to characters but it is getting to be second nature to me over time. Like I mentioned earlier in the article, I intend to review several other jumping plugins so stay tuned and let me know in the comments if you have a favorite and why you prefer it.