Implementing a leap plugin
What this PR does / why we need it:
hi @J-Fields
I have implemented a leap functionality plugin in vscodevim
leap is currently a very popular mobile plugin in the neovim community, and it is really efficient. I believe there are many vscodevim users waiting for its arrival #8144
Functional Features
- s c c -> search down
- S c c -> Search up
- s c -> Show cue marker points
- s <enter> -> Execute the previous search
- s c <space> -> Search c + \t
You can see how it behaves in vscodevim

Docs
You can read leap documentation for more detailed information
Compare the functional differences between leap.nvim
Because the implementation of vscodevim is different from neovim. So in some functions it is not the same as leap.nvim
- No automatic jumping to the first marker point
- Selection of multiple markers
- No support for using operators together
Does not automatically jump to the first marker point
When matching multiple tag points, it does not automatically jump to the first tag point position.
In leap.nvim you can recognize that when you press a character that is the tag of a marker point then it will automatically jump to the marker point, otherwise it will execute the character as if it was a command in normal mode, but unfortunately this is not possible in vscodevim.
Another problem is that this feature can be confusing. Sometimes it jumps automatically and sometimes it doesn't (for example when there are multiple jump points, or you set the corresponding configuration). So I simply killed this feature in my implementation.
Instead of jumping to the first match point by default, the implementation now requires you to press an s. This s can be modified by the configuration
Of course, if only one marker is matched, then it will automatically jump over
Multiple markers are selected in the following way
In leap.nvim, if there are too many matching tokens, then the selection method is to select the corresponding group by /.The problem with this method is that if three groups are matched, then needs to be pressed twice to select them. (Of course, this is a very extreme case, so you will not encounter it)
In my implementation, I refer to easymotion's jump implementation, which starts with one letter and uses two letters if it goes beyond that, so the advantage is that no matter how many matches are made, the two letters will directly locate the marker point.Of course, another reason is that this implementation is unified with easymotion. Because some mobile scenes use easymotion. So it would be difficult to have two sets of selections. (I believe many users of vscodeVim also use easymotion, so this behavior may be more preferable for them, but I'm not sure... haha... what do you think?)

Use with operators is not supported
Unfortunately, this feature is also not supported, again because of the underlying implementation of vscodevim. Currently there is no way to do this
But this feature scenario is not used very often
Can I map other keys if I don't want to use s S?
You can refer to the following configuration
Replace s with f
"vim.normalModeKeyBindingsNonRecursive": [
{
"before":[
"f"
],
"after":[
"s"
]
},
{
"before":[
"s"
],
"after":[
"c",
"l"
]
},
]
How should I experience this feature before this pr merge?
You can install the experience locally based on my code branch
From time to time, I will merge new code from vscodevim into my branch until this pr is merged.
Here's how to do it:
- Download my code branch
- yarn
- yarn package
- code --install-extension vim-1.25.2.vsix --force
- set
vim.leap.enable = trueon setting.json
There is another easy way to download my compiled files directly download vim-1.25.2.vsix
Issues
Conflict of S keys in visualization mode
the s/S in visualization mode contains both characters of the match But now the problem is that S is used by the surround plugin. How can I solve this key conflict problem? Does anyone have any good ideas?
Update
Support for using leap in visual mode
Use x / X instead of s / S on visual mode, because s/S is already taken by the surround plugin.

Support bidirectional search

set vim.leap.bidirectionalSearch": true enable the feature
Because I feel a little uncomfortable using ’S’. I need to reflect between ’s’ and ’S’ and ’S’ makes me press an extra ’shift’. It also supports ’s’ and ’x’ in visual mode
The settings need to be contributed to the package.json such that eg vim.leap=true can be set from the GUI.
The settings need to be contributed to the
package.jsonsuch that egvim.leap=truecan be set from the GUI.
thx your tips, it's fixed now.
in visual mode x and X don't jump to the right character. and s and S are not there at all.
@kabouzeid I just found this detail
The x in visualization mode does not contain the match, while the s in visualization mode contains both characters of the match But now the problem is that S is used by the surround plugin. How can I solve this key conflict problem? Do you have any good ideas?
fixed the bug that in visual mode x and X don't jump to the right character
in visual mode
xandXdon't jump to the right character. andsandSare not there at all.
@cuixiaorui leap.nvim can be set to support two-way search, do you plan to support it later?
@cuixiaorui leap.nvim can be set to support two-way search, do you plan to support it later?
Is there a description document for two-way search? I'll look into it.
@cuixiaorui
more information please see https://github.com/ggandor/leap.nvim#calling-leap-with-custom-arguments
@cuixiaorui
more information please see https://github.com/ggandor/leap.nvim#calling-leap-with-custom-arguments
Haha
Interesting feature
Sometimes I really don't like to use S because I have to press one more shift
I will implement this feature when I have time in a few days
I will update the documentation and then
Yes, sometimes I have to think in my head whether to press shift or not, and it bothers me.
@Leiyi548

I finally finished implementing this function yesterday You can use it to see If you have problems, just give me feedback!
set vim.leap.bidirectionalSearch": true enable the feature
Would love to see this merged.
@cuixiaorui Can you add the option to uncheck visual mode x leap search, because most of the time I checked x for delete
Hi @J-Fields @elazarcoh thank you very much for taking the time to review Leap's code. I have just fixed all the issues mentioned above. In addition, I have also updated the following features:
- Added the functionality of bidirectional search.
- Supported marker background color and font color configuration.
- Refactored the way to get Leap (removed it from vimState).
Please feel free to contact me if you have any questions. I really like vscodeVim and promote it in many places. I sincerely hope that vscodeVim will become better and better.
I have a suggestion, make the first match always be "j", or have a setting where user can choose what character they want to jumo to the first match point. (you know they did similar stuff in neovim ,in neovim they support command , but that's whole another thing though) eg: use "Sse" here , "j" will get me to the "use" of this line since in this line we have the first match. am I making myself clear?
I have a suggestion, make the first match always be "j", or have a setting where user can choose what character they want to jumo to the first match point. (you know they did similar stuff in neovim ,in neovim they support command , but that's whole another thing though) eg: use "Sse" here , "j" will get me to the "use" of this line since in this line we have the first match. am I making myself clear?
You know what maybe make the first match the last command character if the command = "sse" make the firt match jumping character is e, if command = "sid" make the first match jumping character is d. dynamic.
I have a suggestion, make the first match always be "j", or have a setting where user can choose what character they want to jumo to the first match point. (you know they did similar stuff in neovim ,in neovim they support command , but that's whole another thing though) eg: use "Sse" here , "j" will get me to the "use" of this line since in this line we have the first match. am I making myself clear?
You can set vim.leap.labels to modify the default value of "sklyuiopnm,qwertzxcvbahdgjf;", where "s" is the first jumping point.
This PR wasn't merged yet?
@cuixiaorui, thanks a lot for the plugin implementation. I found a small issue. When multiple cursors are present and the leap plugin is invoked the extension gets stuck in Leap mode and it's not possible to move the cursor until the file is closed and reopened. The issue is reproducible with multiple cursors both in normal and visual modes.
https://github.com/VSCodeVim/Vim/assets/16840190/722190aa-f10a-4a64-87c2-69abe870d4a4
It's an easy fix, we just need to check for !vimState.isMultiCursor inside the doesActionApply function https://github.com/archilkarchava/Vim/commit/2af6856f7cdaa11a59d0517d01bed76cf8f7de95.
In this case, the sneak plugin will be used instead as long as it is enabled.
@cuixiaorui, the leap action is dot-repeatable, which is not desirable. Here's how we can exclude it from being marked as dot-repeatable https://github.com/archilkarchava/Vim/commit/12da1ca1d4a0e19283056808f329d2c598bec3b7.
@cuixiaorui, also, I've discovered that the <s-Enter> to execute the previous search is disabled in the code for some reason if the vim.leap.bidirectionalSearch enabled.
I've reenabled it in my fork https://github.com/archilkarchava/Vim/commit/e0d0f966866da46d9b71fd4c349ce9f186dbde8c and it looks like it's working just fine.
I've been daily driving this plugin for a couple of days and discovered a significant performance degradation over time when it comes to displaying the markers.
It turns out that calling the this.textEditorDecorationType.dispose is not enough and we can fix it by adding the this.editor.setDecorations(this.textEditorDecorationType, []); call to the dispose method on the marker.
Here's how I've fixed it in my fork https://github.com/archilkarchava/Vim/commit/41b444d7e13dd141072edaa0ea8e33d050bab60b.
Here's a demo:
Before the fix
https://github.com/VSCodeVim/Vim/assets/16840190/17860893-6485-450e-b434-8550f9d9f88a
After the fix
https://github.com/VSCodeVim/Vim/assets/16840190/639b756f-2fc8-4126-bb6e-7b6541ce00ab
I want to express my sincere gratitude for bringing these issues to my attention. Your feedback has been incredibly useful.
I have addressed and resolved the problems you pointed out. The code has been updated accordingly. I truly appreciate your help in improving the quality of this project.
Please feel free to check the updated code and let me know if you encounter any other issues. Your continued support and feedback are always welcome.
Thank you once again for your valuable contribution. @archilkarchava
@J-Fields is this PR okay to merge?
Love it!
For further reference and inspiration, if required, there is yet another alternative https://github.com/folke/flash.nvim, that also features remote actions, which I find rather ingenious.
Remote actions work like that:
- Cursor is at position A
- Start remote action: for example for yanking remotely press
yrand then leap to a position B - Do a motion, e.g.
iwor another leap - Cursor jumps back to A
Love it!
For further reference and inspiration, if required, there is yet another alternative https://github.com/folke/flash.nvim, that also features remote actions, which I find rather ingenious.
Remote actions work like that:
- Cursor is at position A
- Start remote action: for example for yanking remotely press
yrand then leap to a position B- Do a motion, e.g.
iwor another leap- Cursor jumps back to A
Soon I will implement flash-like functionality in vscodeVim! Progress will be synchronized to this issue
@cuixiaorui, thanks for your kind words. I've been using this plugin ever since and it's been a major improvement to my workflow. I found another small issue: all matches get a label. This includes cases where a search string has a single match. These labels only confuse the user since the cursor will jump to the match automatically without pressing a label key.
We can fix the issue by not assigning a label in case a search string only has a single corresponding match: https://github.com/archilkarchava/Vim/commit/318fd31049589a211a5a0615a559c7a6467666d7.
Before the fix
https://github.com/VSCodeVim/Vim/assets/16840190/f4ca8cfa-0c45-4e59-9796-5cd3ea64704e
After the fix
https://github.com/VSCodeVim/Vim/assets/16840190/4b5f7f70-553c-41d5-b974-93eb9c94444a
Why this PR not be merged? This is a realy used plugin for vim user.
I'd love to see the PR merged, leap is a great plugin.
Any updates on this PR? It's been so long, and it's a much-needed plugin.