Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vim: Add sneak motion #15572

Closed
wants to merge 1 commit into from
Closed

Conversation

mrkajetanp
Copy link
Contributor

Implement support for the vim sneak motion from the vim-sneak plugin. The motion jumps forward or backward to any location specified by two characters.

The Sneak & SneakBackward operators are bound to 'z' and 'Z' by default to avoid overwriting the 's' and 'S' default keybindings, similar to the way the original plugin uses 'z' with operators to avoid conflicts.

Reference:
https://github.com/justinmk/vim-sneak

Release Notes:

  • Added support for the vim-sneak motion (#13858).

Implement support for the vim sneak motion from the vim-sneak plugin.
The motion jumps forward or backward to any location specified by two
characters.

The Sneak & SneakBackward operators are bound to 'z' and 'Z' by default
to avoid overwriting the 's' and 'S' default keybindings, similar to the
way the original plugin uses 'z' with operators to avoid conflicts.

Reference:
https://github.com/justinmk/vim-sneak
Copy link

cla-bot bot commented Jul 31, 2024

We require contributors to sign our Contributor License Agreement, and we don't have @mrkajetanp on file. You can sign our CLA at https://zed.dev/cla. Once you've signed, post a comment here that says '@cla-bot check'.

@mrkajetanp
Copy link
Contributor Author

@cla-bot check

@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Jul 31, 2024
Copy link

cla-bot bot commented Jul 31, 2024

The cla-bot has been summoned, and re-checked this pull request!

@mrnugget mrnugget self-assigned this Aug 1, 2024
@mrnugget
Copy link
Member

mrnugget commented Aug 1, 2024

Wowow, this is already looking amazing! Before I dive too deep into the code, some thoughts/comments:

  1. Can you add a test here? https://github.com/zed-industries/zed/blob/99385e5d12d7d35da386d3d2f19d010f25648596/crates/vim/src/test.rs
  2. It doesn't look like this will work with multi-byte characters, right? Here's a test that ensures t works with them, you can maybe take a look at that one:

    zed/crates/vim/src/test.rs

    Lines 1298 to 1309 in 99385e5

    #[gpui::test]
    async fn test_find_multibyte(cx: &mut gpui::TestAppContext) {
    let mut cx = NeovimBackedTestContext::new(cx).await;
    cx.set_shared_state(r#"<label for="guests">ˇPočet hostů</label>"#)
    .await;
    cx.simulate_shared_keystrokes("c t < o escape").await;
    cx.shared_state()
    .await
    .assert_eq(r#"<label for="guests">ˇo</label>"#);
    }
  3. This breaks zz keybinding, I assume. I don't think we should do that. How about we use a setting to disable this behavior? That way we could also use s. See here which other Vim settings there are already in use:

    zed/crates/vim/src/vim.rs

    Lines 1113 to 1120 in 99385e5

    #[derive(Clone, Default, Serialize, Deserialize, JsonSchema)]
    struct VimSettingsContent {
    pub use_system_clipboard: Option<UseSystemClipboard>,
    pub use_multiline_find: Option<bool>,
    pub use_smartcase_find: Option<bool>,
    pub custom_digraphs: Option<HashMap<String, Arc<str>>>,
    }

@ConradIrwin
Copy link
Member

Thanks for this! Closing this for now due to a lack of activity, but this is a very highly requested feature. if you want to pair with me on getting this over the line: https://calendly.com/conradirwin/pairing

@nilehmann nilehmann mentioned this pull request Jan 7, 2025
github-merge-queue bot pushed a commit that referenced this pull request Jan 10, 2025
A (re)continuation of #21067. 

This takes the original implementation in
#15572 and adds the test in
#21067. Then, as requested in
#21067 (comment),
it documents how to map a keybinding instead of having a setting.

Closes #13858

Release Notes:

- Added support for the popular
[vim_sneak](https://github.com/justinmk/vim-sneak) plugin. This is
disabled by default and can be enabled by binding a key to the `Sneak`
and `SneakBackward` operators.

Reference:
https://github.com/justinmk/vim-sneak

---------

Co-authored-by: Kajetan Puchalski <[email protected]>
Co-authored-by: Aidan Grant <[email protected]>
Co-authored-by: Conrad Irwin <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla-signed The user has signed the Contributor License Agreement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants