I'm looking for a way to add one more "layout" to my keyboard. I'm already using a layout that uses altgr for local alphabet letters. What I'd like to add is a mirrored righthand-side keyboard that's activated with the caps-lock (one described in http://xkcd.com/mirrorboard.xkb)
Unfortunately ISO_LEVEL3_SHIFT is already taken by local alphabet. (AFAIK) If I use mode_shift to change groups I cannot use more than 2 levels in a group anymore. Is there a way to create different groups for both altgr and mode_shift?
For each keycode definition you can have up to eight keysyms. These are organized pairwise into four groups. There is a family of keysyms ISO_Next_Group, ISO_Prev_Group, ISO_First_Group, and ISO_Last_Group that, when pressed, cycle the keysym output by striking the key among the keysym groups. These keys are how you attain multiple layouts.
As an example, assuming ISO_Next_Group has been bound to a keycode and assigned to a modifier, then for this definition:
keycode 53 = x X Greek_xi Greek_XI multiply U2297 U24E7 U24CD
pressing my keyboard key with the label “X” on types out “x”. After pressing the ISO_Next_Group key, I get “ξ”. Pressing it again, I get “×”. Pressing it again, “ⓧ”. Finally, pressing it a fourth time gets things back to normal.
Having spend several days (because Xkb¹ has horrible documentation; finally found an okay guide here), you can create a symbol definition file with entries like this:
key <SPCE> {
// Level I II III IV
[ space, space, U2395, U2592 ], // Group 1
[ U2423, emspace, U2420, hairspace ] // Group 2
};
key <RALT> {
[ Mode_switch, Mode_switch ]
};
key <RCTL> {
[ ISO_Level3_Shift, ISO_Level3_Shift ]
};
The brackets enclose a single group. Normally, the first group is active. The group can be temporarily incremented by one with ISO_Group_Shift, a.k.a. Mode_switch. Within a group, the symbols emitted are defined in increasing levels. Level I is with a bare keypress. Shift adds one to the current level. ISO_Level3_Shift sets the level to III.
The example above maps seven symbols to the space bar plus various shift keys such that:
space ⟨ ⟩ U+0020 SPACE
Shift+space ⟨ ⟩ U+0020 SPACE
R. Alt+space ⟨␣⟩ U+2423 OPEN BOX
R. Alt+Shift+space ⟨ ⟩ U+2003 EM SPACE
R. Ctl+space ⟨⎕⟩ U+2395 APL FUNCTIONAL SYMBOL QUAD
R. Ctl+Shift+space ⟨▒⟩ U+2592 MEDIUM SHADE
R. Alt+R. Ctl.+space ⟨␠⟩ U+2420 SYMBOL FOR SPACE
R. Alt+R. Ctl.+Shift+space ⟨ ⟩ U+200A HAIR SPACE
There is also a key ISO_Level5_Shift for level V. So you can have at least six symbols for one group. With the mode shift key this implies that you can configure your keyboard to type out approximately 1,200 distinct symbols, but at that point holding down so many modifiers will likely deaden a few keys.
P.S. The names of all the named symbols are stored in /usr/include/X11/keysymdef.h.
¹ Turns out that xmodmap(1) is buggy and deprecated.
Related
The control and command keys are basically analogs when it comes to computer applications, when I'm talking about them in a cross-platform application, what should they be called? Is there a term like " the _______ key"?
Alt / Shift / Control / Command - they're all modifier keys. Ctrl/Command are analogs in the sense that they're used for "command"-type shortcuts, i.e. performing some action. Maybe a C-modifier key or action-modifier key would be the right names.
"Modifier key" is the term at least used many online dictionaries and documentation. (Including Apple and IBM.) (As used but not quite advocated in ALGOholic's answer.)
FYI there is an old term that has been used: "bucky (bit) keys". From The Hacker's Dictionary:
BUCKY BITS noun.
Control characters are so useful that sometimes special keyboards
are built that have even more shift keys. One of the first of these was
used at Stanford. It had the usual shift and control keys, and a third
key called "meta", as well as lots of unusual characters such as Greek
letter. So, one can type such characters as control-F, meta-N, and
control-meta-B.
Now, when you type a character on a Stanford keyboard, the
following information is sent to the computer: a code indicating the
basic character, plus one BIT for each shifting key to indicate whether
that shifting key was pressed along with the basic character key.
Programs usually treat the regular shift key as part of the basic
character, indicating whether you want lower case or upper case (or
whether you want "3" or "#", and so on). The other bits (control and
meta) are called the bucky bits.
(Observe that the source itself refers to "shift keys" and "shifting keys".
See also the jargon file glossary:
bucky bits: /buh'kee bits/, n.
[obs.] The bits produced by the CONTROL and META shift keys on a SAIL keyboard [...] (see space-cadet keyboard).
By extension, bits associated with ‘extra’ shift keys on any keyboard, e.g., the ALT on an IBM PC or command and option keys on a Macintosh.
Observe that the source itself refers to the bucky keys as "‘extra’ shift keys".
(I observe that "Bucky bits" & "space cadet keyboard" are referenced in the Wikipedia entry for "modifier key". Unfortunately, there isn't an etymology for "modifier key" itself.)
I need to find out which key was pressed, not what character it would be.
For example, I want after pressing 'a' a number such (1) create so I can map it to other languages. In common way we can find it is 'a' or we can have it's hash code, but is it possible to have char or hash code in a language and find out what char or hash code it would be in another language?
Attention some language have not the standard keyboard so pressing a key not mean a certain character.
There's no reason to do this in any language i've seen.
(besides the fact that you didn't specify in which language you are trying to achieve this)
All languages allow you to get the character code from a keypress.
If you know which encoding was used (UTF 8, Ascii, you name it), it's trivial to map the code to the actual character.
Assigning a different keyboard layout on OS level means that it no longer matters which keyboard layout you are using.
if you have a QWERTY keyboard, switch it to AZERTY and press the button where the q would be, you get an a, despite the letters on the keyboard still saying QWERTY.
If you are using a chinese keyboard, the characters no longer map to any western set, so the character codes will not match up with UTF8 or ASCII, but CP963 (or another chinese codepage, depending on several factors), which is so different there is no real way to translate it to UTF8 or ASCII.
Imagine I have a sentence like this:
Block chain, the decentralised public ledger that records transactions on the bitcoin network.
And if my cursor is at the end of the first word, is there a way to move relative to the end of the sentence rather than from the cursor position? Think of something like, the first c from right hand side is where I want to go, is there a way to reach rather than going to the end first and using F to reach the c ($Fc).
Yes, Vim has (an abundance of) motions that move relative to the current (cursor) position: l, w, f among them. And you can re-position the cursor easily with many motions: ^, 0, $, gm. When combined, that means you can reach almost any place with just a few keystrokes, and it's possible to remember each of those quite easily.
Given that there's a limit to available keys (and that Vim out of the box already uses most of them!), and a limit to what you can memorize, I think that's a perfect balance. In that light, I think $Fc is nothing to worry about (just compare with other editors!)
If that particular motion's inefficiency bothers you, you can always write a custom mapping (and assign one of the few available keys), but that doesn't scale well.
If you think $Fc 3 keystrokes is too many......
operator + target char have already 2 strokes.
We can dynamic capture the target char. But to make it 2 strokes, we have to scarify a normal mode key, I don't know which one you don't use, I just cannot find one on my keyboard, so as example I use the <F6> you can change it as you like.
This mapping allows you press <F6>c to that place, of course, c could be any character.
nnoremap <expr> <space> '$F'. nr2char(getchar())
And this won't work if the target char, i.e (c) is at the EOL. Well you can do further checking, e.g. write your own function to do it, if you think it is really necessary.
Personally I don't think it is worthwhile. Just get used to the $Fx.
Suppose I am working on three functions and I will be jumping back and forth between them. Suppose functions A,B, and C are on lines a, b and c. Is there a way to bind the following (which jump to the line position)
:a
:b
:c
to keys during runtime so I can easily jump to these positions. If you play Starcraft this is kind of like binding a selected group of units to your number keys, and then using the number keys to quickly change your selected group (or jump to the designated line, in this case).
Or is there another way of getting a similar result that I am unaware of? I just recently discovered that =% autoformats your tabs within the highlighted brace, so I am pretty new to vim.
Thanks.
You want to use marks. They allow you to save your current position in the file to a variable.
In Starcraft, you "Hotkey" your guys by pressing Ctrl+1 to tag them, then tap 1 to select them again.
In Vim, you "Mark" a place by pressing [m], then [a](or any letter) to mark them, then [`], then [a] to go back to that mark.
So you have hotkeys to 1,2,3,4, etc in SC, but marks are a-z(and probably other characters but I'm not sure) in Vim.
For more technical info try
:help marks
I'm wondering why in Vim the w key affects an inconsistent amount of text when preceded by d vs v. For example, suppose my cursor is over the "t" of "two" in this text:
one two three
Now dw produces:
one three
But vwd produces:
one hree
Is there some setting to make this more consistent, or do I need to write my own custom definition to fix it?
Also, the capital W selector is similarly inconsistent, and I'm wondering if there's a key for visually selecting the same portion that dW would have deleted? Best I can come up with is vfspace which is OK but wondered if there's anything shorter I'm missing that's built in.
yes there is one option: selection which default is inclusive. it makes v to select the last char.
:h 'selection'
to check detail.
w is exclusive motion. but if in visual mode, it depends on the selection setting.
you could set selection to exclusive to make vwd and dw to behave identical.
The w key does the same in both cases, it puts the cursor in the begining of the next word.
What is "inconsistent" is the v command.
In the first case dw means, delete up to, but not including, the cursor.
In the second case vwd deletes the selection, however the selection includes the cursor. You can clearly see this when you do vw.