Vim icon indicating copy to clipboard operation
Vim copied to clipboard

Implementing a leap plugin

Open cuixiaorui opened this issue 3 years ago • 32 comments

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

show-vscode-leap

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?)

vim-leap-01

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:

  1. Download my code branch
  2. yarn
  3. yarn package
  4. code --install-extension vim-1.25.2.vsix --force
  5. set vim.leap.enable = true on 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.

leap111

Support bidirectional search

vim_leap_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

cuixiaorui avatar Jan 06 '23 08:01 cuixiaorui

The settings need to be contributed to the package.json such that eg vim.leap=true can be set from the GUI.

kabouzeid avatar Jan 07 '23 11:01 kabouzeid

The settings need to be contributed to the package.json such that eg vim.leap=true can be set from the GUI.

thx your tips, it's fixed now.

cuixiaorui avatar Jan 08 '23 05:01 cuixiaorui

in visual mode x and X don't jump to the right character. and s and S are not there at all.

kabouzeid avatar Jan 11 '23 14:01 kabouzeid

@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?

cuixiaorui avatar Jan 12 '23 04:01 cuixiaorui

fixed the bug that in visual mode x and X don't jump to the right character

in visual mode x and X don't jump to the right character. and s and S are not there at all.

cuixiaorui avatar Jan 15 '23 08:01 cuixiaorui

@cuixiaorui leap.nvim can be set to support two-way search, do you plan to support it later?

Leiyi548 avatar Feb 09 '23 16:02 Leiyi548

@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 avatar Feb 10 '23 01:02 cuixiaorui

@cuixiaorui image more information please see https://github.com/ggandor/leap.nvim#calling-leap-with-custom-arguments

Leiyi548 avatar Feb 10 '23 07:02 Leiyi548

@cuixiaorui image 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

cuixiaorui avatar Feb 10 '23 10:02 cuixiaorui

Yes, sometimes I have to think in my head whether to press shift or not, and it bothers me.

Leiyi548 avatar Feb 10 '23 11:02 Leiyi548

@Leiyi548
vim_leap_search

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

cuixiaorui avatar Mar 11 '23 04:03 cuixiaorui

Would love to see this merged.

Shaker-Pelcro avatar Mar 23 '23 16:03 Shaker-Pelcro

@cuixiaorui Can you add the option to uncheck visual mode x leap search, because most of the time I checked x for delete

Leiyi548 avatar Apr 06 '23 06:04 Leiyi548

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:

  1. Added the functionality of bidirectional search.
  2. Supported marker background color and font color configuration.
  3. 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.

cuixiaorui avatar Apr 07 '23 03:04 cuixiaorui

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?

Alan-MQ avatar Apr 07 '23 03:04 Alan-MQ

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.

Alan-MQ avatar Apr 07 '23 04:04 Alan-MQ

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.

cuixiaorui avatar Apr 07 '23 04:04 cuixiaorui

This PR wasn't merged yet?

rennsax avatar Jun 28 '23 05:06 rennsax

@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.

archilkarchava avatar Jun 28 '23 18:06 archilkarchava

@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.

archilkarchava avatar Jun 29 '23 16:06 archilkarchava

@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.

archilkarchava avatar Jun 29 '23 16:06 archilkarchava

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

archilkarchava avatar Jul 03 '23 17:07 archilkarchava

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

cuixiaorui avatar Jul 04 '23 08:07 cuixiaorui

@J-Fields is this PR okay to merge?

dykwok avatar Aug 08 '23 01:08 dykwok

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:

  1. Cursor is at position A
  2. Start remote action: for example for yanking remotely press yr and then leap to a position B
  3. Do a motion, e.g. iw or another leap
  4. Cursor jumps back to A

UnderTheCarpet avatar Aug 08 '23 07:08 UnderTheCarpet

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:

  1. Cursor is at position A
  2. Start remote action: for example for yanking remotely press yr and then leap to a position B
  3. Do a motion, e.g. iw or another leap
  4. Cursor jumps back to A

Soon I will implement flash-like functionality in vscodeVim! Progress will be synchronized to this issue

cuixiaorui avatar Aug 09 '23 03:08 cuixiaorui

@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

archilkarchava avatar Oct 06 '23 20:10 archilkarchava

Why this PR not be merged? This is a realy used plugin for vim user.

cooljser avatar Mar 04 '24 10:03 cooljser

I'd love to see the PR merged, leap is a great plugin.

Edgar-Avila avatar Jun 30 '24 00:06 Edgar-Avila

Any updates on this PR? It's been so long, and it's a much-needed plugin.

Shaker-Hamdi avatar Jul 10 '24 12:07 Shaker-Hamdi