helix-editor / helix

A post-modern modal text editor.
https://helix-editor.com
Mozilla Public License 2.0
32.53k stars 2.4k forks source link

Repeat last command #501

Closed mankinskin closed 2 years ago

mankinskin commented 3 years ago

vim has this feature where the last command can be repeated by pressing .. This is very useful and I would love to see this in this editor aswell.

sudormrfbin commented 3 years ago

Helix does have the dot repeat, but it currently only tracks the last insert mode change (vim tracks every change like ones made with d, c, gU, etc). Tracking every change would be better.

archseer commented 3 years ago

Yeah this is equivalent to kakoune's ., there's also alt-. to repeat last selection (which we still need). It doesn't track other commands either from what I can tell, since it can't tell what the intended selection is (imagine xd for example, we repeat the d on what?).

cessen commented 3 years ago

imagine xd for example, we repeat the d on what?

How much utility is there in the . command if it's only typically meaningful for insertions? I wonder if focusing on a more general macro recording system would make more sense.

(I realize vim also has a macro system, and that doesn't obviate the utility of .. I'm just wondering if, in our case, given the reduced utility of . compared to vim if it would be better to drop it entirely and just try to make macros really fast and ergonomic.)

heliostatic commented 3 years ago

Just adding a vote for normal mode . for my very lazy use case: 10j and then . -- I use this daily in vim, would love a simple equivalent in Helix.

mankinskin commented 3 years ago

@heliostatic For this I think you would be much better served with Ctrl-d and Ctrl-u, right? I'm on my phone so I'm not sure if helix has this, but I believe it has. In vim I also added remaps for Ctrl-j to 4j and for k respectively for small jumps.. not sure if remaps are possible in helix as of now.

pickfire commented 3 years ago

Just adding a vote for normal mode . for my very lazy use case: 10j and then . -- I use this daily in vim, would love a simple equivalent in Helix.

Movement stuff should be covered under alt-. like kakoune. . should only cover manipulation. Macro wise, both should be covered.

archseer commented 2 years ago

We have both ., Alt-. and macros now.

sudormrfbin commented 2 years ago

Maybe we should have . repeat both action and change by default and keep around the individual commands to be remappable if desired. A keybind to do both . and Alt-. can't be defined in the config file right now since . is a special cased key. Moreover, I think repeating both selection and change is the more common case and it would be useful to have it by default on ..

Even if it's not made the default, refactoring the current . behavior (of repeating only last change) into a proper command would enable having a command sequence of "repeat selection, repeat change" be mappable in the config file.

pinpox commented 1 year ago

Maybe we should have . repeat both action and change by default

+1 for this. In it's current state . is not nearly as powerful as in vim. While macros can cover some of the use-cases, I use the dot command quite often in vim to repeat a change or deletion I just did on some textobject and fould another occurence where it is needed aftewards. Macros, search/replace and multiple cursors all require me to know in advance all occurances where I will need that edit, which is quite different than the very useful "Oh, here's another one! Let's do the same change" presses . as muscle memory

Making . repeat changes and deletions on textobjects would be a big improvement in my opinion.

tarunsharma20 commented 1 year ago

+1 for this. One of the main reasons I can't use any other text editor besides vim is the repeat command. It appears that we are utilising three commands in Helix to do the same task. macro, Alt-., and .

Having the ability to repeat the last command would be fantastic if we could alter text case, add/update/delete text, edit surround, etc.

goosethedev commented 8 months ago

Yeah this is equivalent to kakoune's ., there's also alt-. to repeat last selection (which we still need). It doesn't track other commands either from what I can tell, since it can't tell what the intended selection is (imagine xd for example, we repeat the d on what?).

On the line where the cursor currently is, as if you pressed xd again.

From Practical Vim (2nd ed):

The dot command lets us repeat the last change. It is the most powerful and versatile command in Vim.

I hope this feature gets the priority it deserves.

archseer commented 8 months ago

And to re-iterate: Helix is based on kakoune bindings, so Practical Vim has no relevance here.

.: repeat last insert mode change (i, a, or c, including the inserted text)

Think about it. The selection first model requires you to build a bunch off selections first, then operate on them. It's much harder to determine exactly what you want to repeat since selecting is also part of movement. Do we repeat just the last selecting operation, then the action? That likely won't be what you want. Do we repeat all selecting operations since the last change? Well that won't be what you want either since it'll involve scrolling and other movement.

goosethedev commented 8 months ago

The selection first model requires you to build a bunch off selections first, then operate on them.

Yes, I agree this breaks the selection-first model. But under this perspective, so do macros, a feature present in Kakoune and experimental here. The dot command could be seen as an automatically recorded macro for the last action, as if we pressed again the same keys with one single keystroke.

I think at least it would be worth it as an additional command repeat_last_action and leave to the user the decision to bind it or not.

Also thanks for the quick reply! I'm sorry if I'm missing something, I didn't use Kakoune at all.