helix-editor / helix

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

Command and keyboard shortcut for transpose letters/word #1678

Closed gmilleramilar closed 1 year ago

gmilleramilar commented 2 years ago

I'm new to the Vim-like editor world, so there may already be a way to easily transpose adjacent letters/words. If so, please interpret this as a documentation/tutorial request. If not, it would be nice to have a single gesture keybinding to transpose letters/words.

EpocSquadron commented 2 years ago

Transposing is accomplished by rising the contents of selections with alt-( and alt-). You need to first isolate the things you want to transpose. For example, if I want to transpose the id and name attributes in the following:

<input name="about-you" id="about" />

I would first select the whole line x, then make a partial search on about s abo<enter>, then extend the two selections to the following quotations vt". Then alt-) competes the transposition. The specifics will of course vary based on what you are trying to transpose.

Note that this generalizes to arbitrary numbers of selections, in which you are literally rotating the contents through each selection. This is part of the genius that sets kakoune, the basis of helix's interaction model, above vim, IMO.

gmilleramilar commented 2 years ago

I'm going to be perfectly candid, here. I'm still working through your instructions, and haven't been able to make them work yet. I think part of the problem is terminology, (What does it mean to isolate the things I want to transpose, for example). But, assuming that all works for transposing words, I still think you (developers of Helix) should consider a shorter way to transpose letters. Its something that comes up a lot in programming, and is bound to a single keystroke in many editors.

EpocSquadron commented 2 years ago

We support a number of readline keybindings in insert mode, I don't see the harm in implementing the letter transpose binding there as well. I'm of neutral opinion on having it in normal mode, but I'm also just a minor contributor.

anthonyjclark commented 2 years ago

Here is a quick demo. You might notice that, at first, I tried Alt-0 instead of Alt-(.

https://user-images.githubusercontent.com/4173647/155245090-4c25aae3-7529-44bd-be60-a134c3d8dd1e.mov

One other quick note. I am on macOS using iterm2. The Alt-( combo did not work until I set "Left Option key:" to "Esc+". This can be found under Preferences ->Profiles -> Keys.

archseer commented 2 years ago

@anthonyjclark Unrelated, what theme are you using? I'm noticing there's no cursor head rendered on the second selection

archseer commented 2 years ago

should consider a shorter way to transpose letters.

xp will transpose two characters. x deletes a single char, then p pastes after the next char

anthonyjclark commented 2 years ago

@archseer I was using bogster. I can confirm that I see multiple cursors when I change to, for example, onedark.

archseer commented 2 years ago

@anthonyjclark Seems that the theme only provides a ui.cursor.primary style. I fixed it in 6a6a9ab2