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

Support text editing shorcuts #21

Closed
kenden opened this issue Apr 18, 2016 · 20 comments
Closed

Support text editing shorcuts #21

kenden opened this issue Apr 18, 2016 · 20 comments

Comments

@kenden
Copy link

kenden commented Apr 18, 2016

It would be nice if the full range of text editing shorcuts worked:

On Macs:

Movement
Cmd-UpArrow: Go to start of the file
Cmd-LeftArrow: Go to start of the line
Cmd-RightArrow: Go to end of the line
Cmd-DownArrow: Go to end of the file

Alt-LeftArrow: Go to start of previous word
Alt-RightArrow: Go to start of next word

Selection
Shift-Cmd-UpArrow: Select from current position to start of the file
Shift-Cmd-LeftArrow: Select from current position to start of the line
Shift-Cmd-RightArrow: Select from current position to end of the line
Shift-Cmd-DownArrow: Select from current position to end of the file

Shift-Alt-LeftArrow: Select from current position to start of previous word
Shift-Alt-RightArrow: Select from current position to start of next word

Deletion
Cmd-Backspace: Delete until the start of the line
Cmd-Delete: Delete until the end of the line

Alt-Backspace: delete until end of previous word
Alt-Delete: delete until end of next word

Jump to previous/next word: #12
Select to previous/next word: #13

@zyedidia
Copy link
Owner

I think most of these will be possible to implement, although they will only work on a subset of terminals which support these kinds of keybindings. I believe all relatively modern terminals support this stuff though. Unfortunately tcell does not support these keybindings out of the box, but I might be able add them anyway.

Of course, I will need to use Ctrl instead of Cmd for all these keybindings. See #19.

@Red5d
Copy link

Red5d commented Apr 18, 2016

Sortof related to this, the Home and End keys don't seem to work yet.

zyedidia added a commit that referenced this issue Apr 18, 2016
@slnt
Copy link

slnt commented Apr 18, 2016

Tagging onto this, also appreciated would be some Sublime/Atom like commands such as:

Ctrl-l: select line under cursor
Ctrl-d: select word under cursor, subsequent inputs of this will select the next occurrence of the current selection.

Another small nit I have is when selecting text with the mouse, it would be nice if it highlighted as you go rather than when you release the mouse.

Great work, love having this!

@zyedidia
Copy link
Owner

zyedidia commented Apr 18, 2016

It should highlight as you go, unless your terminal doesn't support mouse tracking. What terminal are you using?

Also, I'm currently using Ctrl-d for half page down. Does Sublime/Atom have a keybinding for this that I could use instead?

@slnt
Copy link

slnt commented Apr 18, 2016

OS X Terminal.app, but I'm inside of a tmux. Hmmm, works find outside of tmux.

Looks like sublime support keyboard scrolling functionality but don't have key bindings set by default.
Perhaps alt-uparrow and alt-downarrow? Personally that feels a bit more intuitive than ctrl-u and ctrl-d, but just my 2c.

@pscollins
Copy link

Maybe a nice solution to this would be to read off configuration from a file, and ship it with sensible defaults? Assigning meaning to keybindings borders on holy war territory.

@slnt
Copy link

slnt commented Apr 19, 2016

I think @pscollins has the way of it. :)

@bentranter
Copy link

@zyedidia do you think it'd be better to try to add more keypress events to tcell, or to look for an alternative solution for dealing with keybindings? I feel like most of these aren't possible until those keybindings are easily detectable. I also do really like @pscollins idea about a config file

@pscollins
Copy link

I guess the first step towards making it configurable would be defining what actions there should be: move-word-forward, move-word-back, page-up, page-down, etc.

@zyedidia
Copy link
Owner

Yeah, that's what I was planning on doing. This configuration could go in the ~/.config/micro/settings.json file. For example:

{
    "syntax": true,
    "keybindings": {
        "CtrlC": "copy",
        "CtrlV": "paste"
    }
}

@zyedidia
Copy link
Owner

A bunch of these keybindings are now supported (using Ctrl instead of Cmd). See #79.

@bendem
Copy link

bendem commented Apr 27, 2016

Using current master (6c99eea) I'm still seeing ctrl+arrows doing nothing and alt+arrows inserting [1;3C or [1;3D.

@zyedidia
Copy link
Owner

zyedidia commented Apr 27, 2016

Can you make sure you run make install from the root directory of the project to build. I think you need to update your version of tcell, and make install will do that automatically.

Make sure you use commit 957e97d which has the updated makefile.

@bendem
Copy link

bendem commented Apr 27, 2016

I ran GOPATH=$(pwd) make clean build test to compile. Pretty sure that does it.

@bendem
Copy link

bendem commented Apr 27, 2016

Nevermind, I was on the wrong branch, works fine.

@zyedidia
Copy link
Owner

Of the bindings on this list, all that are possible have been implemented, so I'm closing this issue as resolved.

Here are the bindings that are implemented:

Movement
Ctrl-UpArrow: Go to start of the file
Ctrl-LeftArrow: Go to start of the line
Ctrl-RightArrow: Go to end of the line
Ctrl-DownArrow: Go to end of the file

Alt-LeftArrow: Go to start of previous word
Alt-RightArrow: Go to start of next word

Selection
Shift-Ctrl-UpArrow: Select from current position to start of the file
Shift-Ctrl-LeftArrow: Select from current position to start of the line
Shift-Ctrl-RightArrow: Select from current position to end of the line
Shift-Ctrl-DownArrow: Select from current position to end of the file

Shift-Alt-LeftArrow: Select from current position to start of previous word
Shift-Alt-RightArrow: Select from current position to start of next word

Deletion
Alt-Backspace: delete until end of previous word

Unfortunately, due to the way terminals work, it is not possible to support these keybindings:

Ctrl-Backspace: Delete until the start of the line
Ctrl-Delete: Delete until the end of the line

Alt-Delete: delete until end of next word

Terminals simply don't send these as their own key events.

@LukeSkyw
Copy link

Sorry to hijack that closed thread, but for all the people who came here for some sane defaults:

$ cat >> ~/.config/micro/bindings
{
  "CtrlLeft": "WordLeft",
  "CtrlRight": "WordRight"
}
^D

@bendem
Copy link

bendem commented Mar 24, 2017

@LukeSkyw I understand your feeling, but you're implying that the default keybindings are not sane while they totally make sense from a mac perspective. 😉

I guess providing keybindings for linux and windows couldn't hurt. That would go in a new issue though.

@mixmastamyk
Copy link

The file above should be bindings.json, and to fix the shifted as well:

$ cat >> ~/.config/micro/bindings.json
{
    "AltLeft":        "StartOfLine",
    "AltRight":       "EndOfLine",
    "CtrlLeft":       "WordLeft",
    "CtrlRight":      "WordRight",

    "AltShiftLeft":   "SelectToStartOfLine",
    "AltShiftRight":  "SelectToEndOfLine",
    "CtrlShiftLeft":  "SelectWordLeft",
    "CtrlShiftRight": "SelectWordRight",

    "ShiftLeft":      "SelectLeft",
    "ShiftRight":     "SelectRight",

    "AltUp":         "CursorStart",
    "AltDown":       "CursorEnd",
    "AltShiftUp":    "SelectToStart",
    "AltShiftDown":  "SelectToEnd",
}

@robinmonjo
Copy link

Hello, I was having the same (original) issue on Mac OS with Terminal app. The CtrlShiftRight, CtrlShiftLeft, AltShiftRight, AltShiftLeft ... wasn't working (it was supposed to select text), here is how I fixed it:

Based on the mapping here, in preferences > profiles > keyboard you must map the missing key / action pair with what's on the code, by replacing \x1b by \033:

screen shot 2018-08-02 at 17 38 02

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants