Micro: Selecting text does not work in standard Linux console

Created on 6 Sep 2017  路  17Comments  路  Source: zyedidia/micro

Description of the problem or steps to reproduce

Selecting text does not work when I use micro in the linux console (TERM=linux), that means no GUI. I use Shift-Left and Shift-Right. The cursor moves, but the text is not marked as selected. Consequently copy and paste does not produce a result.

Steps to reproduce:

  • Boot into Console, Close your GUI or try Ctrl-Alt-F2 (3,4..)
  • open micro, write 'AA' or so
  • try to select the text

Expected behavior: Text gets visually selected and can be copied + pasted
Bahaviour: Cursor moves but text is not visually selected, copy paste has no effect

Specifications

Linux: Archlinux (up to date)
TERM=linux)
Version: 1.3.1
Commit hash: dd5afc0
Compiled on August 08, 2017

Most helpful comment

I've got a fix coming soon -- stay tuned.

All 17 comments

There isn't much I can do about this. The linux console is pretty limited in terms of what events it sends to micro and for example it does not send shift-arrows. I recommend rebinding the selection commands (perhaps to alt-hjkl?):

In ~/.config/micro/bindings.json:

{
    "Alt-h": "SelectLeft",
    "Alt-j": "SelectDown",
    "Alt-k": "SelectUp",
    "Alt-l": "SelectRight"
}

@zyedidia
Happy to accept that it might not work for micro and thanks for the work around suggestion.
However, nano (and that's the only other editor I have tested) supports this function.

So it might be possible to catch Shift-Arrow in the linux console somehow but I am happy to accept that this would mess up the micro way of dong things or is just too much effort for a limited use case.

Hmm ok if it is possible with Nano then I will look into this a bit more. It seems unlikely though that I'll get this to work.

EDIT: it seems like Nano doesn't support selecting with shift-arrow keys. Is there some option I need to enable for it to work?

For me it works with nano. I have tested a few other editors I have installed with mixed result. Tilde works as well but ne does not. It seems it is not an uncommon problem. Maybe the issue can stay open ?

Alright I wasn't able to get it to work with nano but it does seem that tilde works. I'll re-open this and see what I can do.

I've got a fix coming soon -- stay tuned.

Alright here's the fix.

You should create a file called supplemental.kmap and put the following inside it. This comes from the tilde project, but I've modified the escape codes to work for micro.

# The following is a map with supplemental key mappings for the linux console.
# Using these mappings will allow distinction between key presses for several
# keys with and without control and shift modifiers.

# These mappings can be loaded with the loadkeys(1) program. Simply run
#   loadkeys supplemental.kmap
# as root to add these mappings to your console. How to make these changes
# permanent depends on your distribution. There are also two ways to make these
# changes permanent: create a keymap which contains this file, or add a job
# which is run on startup and executes the above loadkeys command.

# Debian (or Debian based such as Ubuntu):
#   Add the contents of this file to /etc/console-setup/remap.inc and run
#   "dpkg-reconfigure -u keyboard-configuration" as root. Adding the mappings
#   to the remap.inc file will ensure that the mappings are activated, even if
#   another keyboard layout is chosen at a later time.

# Right
control keycode 106 = F100
shift keycode 106 = F101
control shift keycode 106 = F102
# Left
control keycode 105 = F103
shift keycode 105 = F104
control shift keycode 105 = F105
# Up
shift keycode 103 = F106
# Down
shift keycode 108 = F107

string F100 = "\033[1;5C"
string F101 = "\033[1;2C"
string F102 = "\033[1;6C"
string F103 = "\033[1;5D"
string F104 = "\033[1;2D"
string F105 = "\033[1;6D"
string F106 = "\033[1;2A"
string F107 = "\033[1;2B"

Then you can load it with sudo loadkeys supplemental.kmap. The terminal only remembers it for the current session (correction: current boot) so you may want to run a job which runs at startup to execute the command.

This should also enable CtrlArrows and CtrlShiftArrows (on top of ShiftArrows).

I could not test it completely but at least something happened and it looks like the solution might be in reach.

when used in micro in the console I get parts of the key code from the mapping. I mean part of the keycode gets actually printed in the editor (with some variations):

[1;2A]    up
[1;2B]    down
[1;2C]    right
[1;2D]    left

if you press shift-left at the end of the line [1;2D] with ] at the end.
Also the sursor is positioned on the last letter before the ]
if you press all four keys one after the other you get: [1;2A[1;2B[1;2C[1;2D]]]]

if pressed somewhere in the line then there is no last ]

e.g
a[1;2Aa  up pressed between the two aa

So the keys are available now

I have now tested another editor where it works on the console and this one is a super simple one, maybe that canhelp as well ?
edit

I have compiled it and it works (without the above mentione kmap) . As the whole editor is ~2000 lines, maybe it is possible to find it's secrets?

Oh I see it isn't exactly yet. If you run export TERM=xterm and use the new keymap it will work but that's not a good solution so I'll reopen.

Give it a try now -- it should work right with TERM=linux.

I can confirm it works on the latest master, without loadkeys.

Hmm that's strange, it should still require loadkeys to work (only if you are using the linux console).

Apparently it's one loadkeys each boot, not login. My bad.

Works for me as well now :-) Thanks for the effort.
I would add the instructions to the Wiki but it seems it cannot be changed ? What's the best way to document this tip ?

I have added it to the wiki for you. By default, the wiki is only editable by anyone and I'm not sure if it is really a good idea to allow any user to edit the wiki (maybe it is though -- github users seem very civil).

Yay! Thank you! (local console on Ubuntu Server 16.04)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ns-cweber picture ns-cweber  路  4Comments

johnmbaughman picture johnmbaughman  路  3Comments

Calinou picture Calinou  路  3Comments

utkarsh2102 picture utkarsh2102  路  3Comments

nabeelomer picture nabeelomer  路  4Comments