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

Ctrl, Alt, Shift + arrow keys #79

Merged
merged 5 commits into from
Apr 27, 2016
Merged

Ctrl, Alt, Shift + arrow keys #79

merged 5 commits into from
Apr 27, 2016

Conversation

zyedidia
Copy link
Owner

@zyedidia zyedidia commented Apr 26, 2016

This pull request adds bindings for ctrl, alt, and shift + arrows. Here are the current bindings I plan on using.

shift+arrows: select
alt+arrows (left and right): move by word
alt+shift+arrows: select by word
ctrl+arrows (left and right): move to beginning and end of lines
ctrl+arrows (up and down): move to beginning and end of file
ctrl+shift+arrows: select according to movement

Let me know if you think the keybindings should be different.

Ref #21.

@benadamstyles
Copy link

ctrl+arrows: move by line

Do you mean move the cursor, or move actual lines of text? I don't think you need a special keybinding to move the cursor by line – you can just use the up and down arrows right? Or am I missing something?

These mappings include Alt+arrows and Shift+arrows and Alt+Shift+arrows

This commit also switches the version of tcell that micro uses to my
fork which supports alt, shift, and ctrl + arrows.
@zyedidia
Copy link
Owner Author

I'll reword it to be more clear. I mean move the cursor to the start and end of lines.

@benadamstyles
Copy link

Ah ok yep that makes sense, sorry, don't know why I didn't read it that way!

@bendem
Copy link

bendem commented Apr 26, 2016

alt+arrows (left and right): move by word
ctrl+arrows (left and right): move to beginning and end of lines

Never seen that behavior on windows or linux. There, it's ctrl+arrows to move by word, alt+arrows doesn't do anything.


Also, I tested this branch. At the moment, ctrl+arrows does nothing and alt+arrows inserts [1;3C or [1;3D.

@zyedidia
Copy link
Owner Author

zyedidia commented Apr 26, 2016

Ok, that's good to know. Ctrl keys don't do anything on the branch yet, but it seems like alt sends a different keycode on Linux than on Mac.

It seems like the alt+arrows keycodes are not consistent across terminals, so it might be better to use ctrl+arrows instead.

@aravindet
Copy link

Linux and Windows applications use ctrl+left/right to move to the previous/next word break, and holding down shift selects according to the cursor movement.

There aren't any universal conventions around alt+arrows or ctrl+up/down. On my current machine (GTK):

  1. text area widgets do not move the cursor when Alt is pressed, and ignore the Ctrl and move normally on up/down.
  2. In Gedit, Ctrl+Up goes to the beginning of the previous line, Ctrl+Down goes to the end of the next line, and Alt+Left/right move the current word (i.e. swaps it with the previous/next word), Alt+Up/Dn moves the current line.
  3. In Atom, Alt+Left/Right work almost the same as Ctrl+Left/Right, except for treating underscores as word boundaries. Ctrl+Up/Down moves the current line.

I suspect that these are rarely used, so Ctrl+Left/Right and Shift should cover 99% of use cases.

@benadamstyles
Copy link

On Mac, Ctrl+arrows is sometimes used to switch desktops/spaces. Will there be the option to set Cmd keybindings instead for Mac? On Mac, Cmd tends to occupy the conceptual space taken by Ctrl on Linux and Windows, i.e. it is used "inside" apps whereas Ctrl is often used for system level commands.

@Adurol
Copy link

Adurol commented Apr 26, 2016

ctrl+arrows (left and right): move to beginning and end of lines
ctrl+arrows (up and down): move to beginning and end of file

Alternative would be to use Pos1 and End keys:

ctrl + pos1 = jump to beginning of the file
ctrl + end = jump to end of the file

Pressing shift too would select the text from current cursor position until beginning (pos1) or end (end) of the file. This is how the most editor/offices suits I know do it.


I agree with using ctrl+arrows (left and right) to jump by word, too.

@zyedidia
Copy link
Owner Author

@Leeds-eBooks Unfortunately, it is impossible to detect Cmd key presses, so that is not possible. See #19.

@benadamstyles
Copy link

Ah yes ok. Are you planning to make these keybindings configurable, like those already in micro? If so then all we're talking about is the defaults so it doesn't really matter too much.

@zyedidia
Copy link
Owner Author

Yeah, all these keybindings will be configurable.

@zyedidia
Copy link
Owner Author

The current keybindings are as follows:

{
    "ShiftLeft":      "SelectLeft",
    "ShiftRight":     "SelectRight",
    "AltLeft":        "WordLeft",
    "AltRight":       "WordRight",
    "AltShiftRight":  "SelectWordRight",
    "AltShiftLeft":   "SelectWordLeft",
    "CtrlLeft":       "StartOfLine",
    "CtrlRight":      "EndOfLine",
    "CtrlShiftLeft":  "SelectToStartOfLine",
    "CtrlShiftRight": "SelectToEndOfLine",
    "CtrlUp":         "CursorStart",
    "CtrlDown":       "CursorEnd",
    "CtrlShiftUp":    "SelectToStart",
    "CtrlShiftDown":  "SelectToEnd",
}

You can rebind these however you'd like using the bindings.json file.

@zyedidia zyedidia merged commit 8e03e20 into master Apr 27, 2016
@zyedidia zyedidia changed the title [WIP] Ctrl, Alt, Shift + arrow keys Ctrl, Alt, Shift + arrow keys Apr 27, 2016
@zyedidia zyedidia deleted the arrow-bindings branch April 30, 2016 22:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants