zed icon indicating copy to clipboard operation
zed copied to clipboard

vim: `f` and `t` multiline option

Open romgrk opened this issue 1 year ago • 7 comments

I'm not sure how compliant you're aiming to be with vim, but the f behavior is more useful when it can search on multiple lines instead of a single one, so I'd like to propose this change.

This change is quite frequent in vim/neovim as a plugin (e.g. clever-f, improved-ft, etc), and in other vim emulations (e.g. vscode-vim).

romgrk avatar Feb 26 '24 19:02 romgrk

How does this work when I have multiple cursors or a visual block selection and I want each cursor only to search on its own line?

mrnugget avatar Feb 26 '24 19:02 mrnugget

Good question, that's a difference with vim.

For visual block selection, it seems to act as if there was only one cursor, the last one, and all the other cursors follow the last one. This is not different than other motions right now, e.g. w does word motions on the last cursor and the other cursors follow the column position, regardless of the words on their own line.

For multiple cursors that end up on the same line, I haven't tested yet, depends what's the behavior right now when multiple cursors collide, but I haven't found a way to create multiple cursors in vim normal mode other than visual block selection.

romgrk avatar Feb 26 '24 19:02 romgrk

Thanks for this! I like the idea of it, but think it is too far off from vim to support by default.

We recently added the ability to have vim-specific configuration options; so let's add an option:

{
  "vim": {
    "use_multiline_find": true
  }
}

I'd happily pair with you to get this over the line: https://calendly.com/conradirwin/pairing. But if you want to take a pass yourself, you can use #7936 as inspiration for how the setting might work.

We'll also want at least one test for the new behavior so we don't break it by accident.

ConradIrwin avatar Feb 26 '24 20:02 ConradIrwin

Sounds good, I think I have enough information to do it by myself.

romgrk avatar Feb 26 '24 20:02 romgrk

but I haven't found a way to create multiple cursors in vim normal mode other than visual block selection.

FWIW you can use opt-click (it would be neat if we find a Vim-y way to this): screenshot-2024-02-27-09 59 29

mrnugget avatar Feb 27 '24 09:02 mrnugget

Gotcha, works on linux as alt-click. Played a bit with colliding selections/cursors and multiline find, it feels like the current behavior is good.

it would be neat if we find a Vim-y way to this

I see two solutions to create multiple cursors in a keyboard-centric way:

  • Have a "create cursors" mode, where the user can move like in normal mode and mark locations for new cursors, and once complete all the marks turn to cursors.
  • Inspired by atom-vim-mode-plus and kakoune selections, we can add a command that adds cursors at either pre-defined patterns (e.g. word boundaries, other matches for current word, etc) or user-inputed patterns (regex). In conjunction with visual mode or operator-pending mode, it's a very efficient way to add cursors.

Once we get linux working I'd definitely be interested in spending some time on the vim implementation.

romgrk avatar Feb 27 '24 09:02 romgrk

This is ready for review. I've added a small section to the docs for the vim settings.

romgrk avatar Feb 27 '24 12:02 romgrk

Great, thanks so much for this!

I'd love to talk through the multi-cursor thing before you jump in and implement anything.

ConradIrwin avatar Feb 28 '24 02:02 ConradIrwin