XTerm Control Sequences specifies the following key sequences:
CSI ? 1 h → Application Cursor Keys (DECCKM)
CSI ? 1 l → Normal Cursor Mode (DECOM)
CSI ? 66 h → Application keypad (DECNKM)
CSI ? 66 l → Numeric keypad (DECNKM)
and the Terminfo Source Format has the following entry:
Variable: keypad_xmit
Capname: smkx
Termcap: ks
Description: Put terminal in "keypad-transmit" mode
But the terminfo for xterm actually says smkx=\E[?1h\E=, which seems mixed up to me (smkx should affect the keypad, not the cursor keys, right?). What am I missing here?
The line
CSI ? 1 h → Normal Cursor Mode (DECOM)
probably should read
CSI ? 1 l → Normal Cursor Keys (DECCKM)
There are two escape sequences in each of smkx and rmkx because these capabilities are used in curses, i.e., for the keypad function.
The manual page for ncurses (like others) does not say so explicitly, but the function applies to all of the special keys on the keyboard which have the ability to switch between normal and application mode. This is a well-known feature of smkx and rmkx, as for example in the xterm FAQ Why can't I use the cursor keys in (whatever) shell?.
Special keys on the keyboard may include these (depending on the type of terminal):
numeric keypad (on the extreme right of a PC keyboard)
editing keypad (6 keys between the main keyboard and the numeric keyboard)
cursor keys
function keys (commonly at the top of a PC keyboard)
The VT100 (which does not have function keys or editing keypad) has separate escape sequences for the other two categories. In VT220 (emulated by xterm), the editing keypad's normal/application mode is an extension of the VT100 DECCKM, (documented in XTerm Control Sequences). DEC did not define a corresponding feature for function keys; however if there were some terminal which supported this capability it would probably be used in smkx and rmkx.
It looks like you are missing the \E= at the end of smkx.
ESC = Application Keypad (DECKPAM).
ESC > Normal Keypad (DECKPNM).
are listed on the XTerm Control Sequences page as well and you would expect them to affect the keypad.
I found a related question here: keyboard transmit mode in vt100 terminal emulator.
Related
I'm using emacs 24.3 in the OS X terminal, and have run into something strange.
In markdown-mode.el, the tab key is bound to a specific function in the keymap via (define-key map (kbd "<tab>") 'markdown-cycle), but for some reason this wasn't registering for me (though other parts of the keymap were working fine).
What fixed this was changing <tab> to TAB in the above. Is this something wonky in the OS X terminal? Is there a way to fix this; I feel like this shouldn't occur.
I believe markdown-mode should be using TAB, not <tab>.
As far as I can tell, <tab> is the Tab key on the keyboard, and TAB is control-I, or ascii character 9 (written \t or \x09). The Tab key doesn't have an ascii value.
In GUI Emacs, Emacs sees that you pressed the Tab key (<tab>) and converts it to C-i (TAB) by default. Emacs can distinguish Tab and C-i, but converts Tab to C-i unless you specifically bind <tab> to something else (which markdown-mode does).
In the terminal, the terminal converts the Tab key to C-i (ascii 9), and Emacs sees only C-i. Emacs can't distinguish the two because they both show up as C-i.
The same thing happens with <return> vs RET (C-m, ascii 13).
Using TAB with define-key should automatically bind whatever event your keyboard sends for the key labeled "Tab", whether it is the ASCII TAB character, also known as C-i (Control + i) or something else -- including what Emacs writes as the pseudo-function key <tab>.
This might not work automatically in all cases. If it does not work for your particular keyboard then use C-h k and hit your Tab key, to find out what it is bound to. Whatever Emacs tells you is the key sequence, try binding that. For example, if it tells you that the key sequence is <foobar> then use (kbd "<foobar>").
But in most cases, all you need to do is use (kbd "TAB") (or "\C-i" or [control ?i]).
The numeric keypad seems to be not working in X shell terminal application.
How to enable the numeric keypad.
In google, i found to change the mode to ansi instead of Xterm. But some functionality were missing in ansi.
Set the following settings in X shell
In properties of the given shell:
Go to
TERMINAL -> VT MODES -> INITIAL NUMERIC KEYPAD MODE
and select option
-> SET TO NORMAL
Now your numeric keypad will work as usual.
I'm implementing a vt100 terminal emulator in javascript and the vt100 spec (from man terminfo and infocmp) tells me that smkx=\E[?1h\E= is the code to enter key-board transmit mode and rmkx=\E[?1l\E> is the code to leave 'key-board transmit' mode. I couldn't really understand what key-board transmit mode is.
From http://vt100.net/dec/ek-vt220-tm-001.pdf,
7.4.4.1 Keyboard Transmit Mode -- The keyboard codes and a few other special codes are transmitted via a serial line output in PORT of the
8051. The transmitted signal goes from the 8051 to a driver, through the keyboard cable, monitor and video cable to the CPU. A UART within
the 8051 controls the transmission"
I'm getting these codes while entering into and leaving vim, respectively. Can I safely ignore these codes or do I need to handle them? In the latter case, what am I supposed to do?
These two strings contain two sequences each; they control subtly different things:
The first of these,
CSI ? 1h
CSI ? 1l
controls DEC private mode number 1, DECCKM, cursor key mode. This mode determines whether the four arrow keys (Up, Down, Left, Right) will send SS3 or CSI-prefixed sequences.
The second pair of sequences,
ESC =
ESC >
are called DECKPAM, keypad application mode, and DECKPNM, keypad numeric mode. This determines whether the number keypad sends control sequences, or normal numbers (i.e. consider it similar to the Numlock feature).
smkx/rmkx control whether the keypad will transmit numbers or escape code. Also, it is "keypad-transmit-mode" not "keyboard-transmit-mode"
I found out that the Bash shell supports a type of autocompletion that is different from the "traditional" autocompletion, where all possibilities get listed on the following line.
With the "traditional" autocompletion, if I type ch and then press the Tab key, I get something like:
$ ch
chacl chgrp chmod chown chvt
But if I add the following line to my /etc/inputrc (which remaps the Tab key to the built-in menu-complete function):
Tab: menu-complete
then the behavior of the shell changes: the word to be completed is replaced "inline" with a single match from the list of possible completions, and if I press the Tab key again, the word gets replaced with the next match.
I found this useful, but I still wanted to keep the traditional autocompletion and have it bound to the key combination Ctrl + Tab. So I added the following line to my /etc/inputrc file, according to what the readline library documentation suggests:
Ctrl-Tab: complete
However, adding this line only seems to make both Tab and Ctrl-Tab call the traditional complete function.
Does anyone know what I am doing wrong?
Thanks in advance!
To start with, I'm not a massive expert in this area, but I think I can answer your question. First of all, while you are using Bash, Bash is a shell which interprets keyboard commands that it receives from a terminal / console. While you are informing Bash how to react to specific key combinations in the inputrc file, your Terminal determines precisely which character is 'sent' to the Shell before the inputrc file even enters the equation.
Unfortunately, on my system (granted, it's OSX - but I don't think this is strange behaviour when compared to Linux), both Tab and Ctrl-Tab send the same keyboard input to the shell. Infact, both Tab and Ctrl-Tab send a Ctrl-I command to the shell, and indeed, if I enter Ctrl-I when using the terminal, it performs the completion as if I hit Tab.
The software (installed on most Linux systems by default), showkey will tell you what keys the shell is receiving when you press specific keyboard inputs as you push them.
Anyway, my suggestion to you is to use Shift-Tab, which does appear to send it's own key-code to the shell. Shift-Tab on my computer shows up (using showkey) as '<ESC>[Z', which I think is pretty standard across the board. As such, your inputrc file with the following bindings should allow you to use shift-tab instead of ctrl-tab to achieve what you desire:
Tab: menu-complete
"\e[Z": complete
The \e in the second binding represents the escape character, and the [Z are simply the characters as shown using showkey. You can get a similar effect on OSX by simply using cat, running cat from within a terminal and pressing Shift-Tab will show you "^[[Z", where ^[ represents the escape character and the other characters are as before.
I know this doesn't resolve your question precisely, but as I don't think you are able to use Ctrl-Tab as a key combination, without re-mapping Ctrl-Tab to another keybinding within your terminal (more likely to be easier if you are using a GUI terminal), this is likely as close as you can get without significant effort!
I have ShiftTab bound to menu-complete-backward, so it goes back one step if I skipped the right completion, and I've mapped Ctrlq to complete, so if there are several possible completions I hit Ctrlq to list them without having to cycle through them.
# Make Tab cycle between possible completions
# Cycle forward: Tab
# Cycle backward: Shift-Tab
TAB: menu-complete
"\e[Z": menu-complete-backward
# Make C-q display the list of possible completions
Control-q: complete
# Display the list of matches when no further completion is possible
set show-all-if-unmodified on
Edit: Ctrlq is bound to quoted-insert by default, that is, it tells the shell to take the next key literally. quoted-insert is also bound to Ctrlv, so you don't lose that functionality if you rebind Ctrlq. Anyway, I've found that AltESC also works, by default, for showing the possible completions (as far as I can tell it is equivalent to TAB); note that it may be seized by Gnome, then either double press ESC or rebind "Switch windows directly" in Settings → Devices → Keyboard → Navigation.
The following should achieve what you're looking for (if I understand correctly!)
In your .inputrc
# display all possible matches for an ambiguous pattern at first tab
set show-all-if-ambiguous on
# next tab(s) will cycle through matches
TAB: menu-complete
# shift tab cycles backward
"\e[Z": menu-complete-backward
Where to start, if you can or cant do this is dependent your keyboard and your drivers and there isn't one catch all answer. Each key press and release generates a sequenced key pair (key down and release) (scancode) these codes are then translated by the kernel into keycodes for example on my laptop keyboard 0x3a 0xba are translated to keycode 15 (down and up) these are then translated into actions such as return letter c a / you can assign actions to keysyms using the keycode/hex/binary/octal notation which codes match which letters is determined by the kernel translation table which is fairly standardized, however the first part signal that's translated to keycodes is different for most keyboards.
Continuing with the earlier example for me shift tab (and alt and control and any combination) produce keycode 15 however in hex it produces 0x2a 0x2a 0x2a 0x2a 0x2a 0x2a 0x2a 0x2a 0x2a 0x2a 0x2a and this is because shift alt and control are special keys (modifiers) these multiply out against the keycodes and fill out the dumpkeys table the kernel is limited to the number of assignments as well this is determined by your choice of keymap and shares resources with your terminal colors (if your char set its defined above the threshold it limits your terminal color scope). And this all goes out the window if your in an xserver and has a whole new system. Most of these things can be changed,modified and manipulated by the user and programs installed. My point to all this is to emphasize that there is no catch all for the mapping of the tab key and its going to vary keyboard drivers to kbd drivers (now if you find a solution that happens to work for you excellent :)) but chances are it won't be portable and might not work if you change keyboards and might not translate between xserver and tui. What i recommend is learning the steps to modify your kbd on the go.
will give you the decimal octal hex notation for a key press on the same line
--full-table -1 >> keytable
will give you a documented with your full list of keycode->keysym pairing in a format that will give you a better picture of your layout and from there you can either use loadkey to change a keys value or ad an entry in .inputrc or your main rc file. You can also create a custom key.map file.
Further escape sequence translation is determined by the "$TERM" variable and each virtual terminal emulator can be different
infocmp "$TERM"
will give you a list of your terminal escape sequences
Resources:
https://man7.org/linux/man-pages/man4/console_codes.4.html
https://www.gnu.org/software/screen/manual/html_node/Input-Translation.html
http://kbd-project.org/docs/scancodes/scancodes.html
https://www.vt100.net/
So to sum up.
Your keyboard drivers
Your kemap choice
Your virtual terminal emulator
and your kernel
form the backbone of remapping dificult keys (tab/s-tab/a-tab)
I'm not sure Ctrl-Tab is a real character; my terminal, for instance, ignores the combination. I think the only way to use Ctrl-Tab is to use your terminal emulator to map it to some otherwise unused escape sequence, then bind that sequence to complete.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 1 year ago.
Improve this question
I can see that Ctrl+left/right jumps to the beginning/end of line. How to change this to Cmd+left/right arrow?
Add in iTerm2 the following Profile Shortcut Keys
FOR
ACTION
SEND
⌘ ←
"SEND HEX CODE"
0x01
⌘ →
"SEND HEX CODE"
0x05
⌥ ←
"SEND ESC SEQ"
b
⌥ →
"SEND ESC SEQ"
f
Here is a visual for those who need it
To jump between words and start/end of lines in iTerm2 pick one of the two solutions below.
1. Simple solution (recommended)
Open Preferences
Click "Profile" tab
Select a profile in the list on the left (eg "Default")
Click "Keys" tab
Click "Key Mappings" tab (if it exists)
Click the "Presets" dropdown and select "Natural Text Editing"
Note: if you have several profiles (f.e. Default and Hotkey Window) and want the same modification to be applied for all profiles, use these steps instead:
Click "Keys" tab
Choose "Key Bindings"
2. Mapping keys manually (Advanced)
If you don't want to use the "Natural Text Editing" preset mentioned above, you can map the keys you need manually:
Open Preferences
Click "Profile" tab
Select a profile in the list on the left (eg "Default")
Click "Keys" tab
Click "Key Mappings" tab (if it exists)
Click the [+] iconjuimp
Add the shortcuts from the table below
SHORTCUT
DESCRIPTION
ACTION
SEND
⌘ ←
Jump left to beginning of line
"SEND HEX CODE"
0x01
⌘ →
Jump right to end of line
"SEND HEX CODE"
0x05
⌘ ← Delete
Delete line
"SEND HEX CODE"
0x15
⌥ ←
Jump left to beginning of word
"SEND HEX CODE"
0x1b 0x62
⌥ →
Jump right to end of word
"SEND HEX CODE"
0x1b 0x66
⌥ ← DELETE
Delete word
"SEND HEX CODE"
0x1b 0x08
⌘ z
Undo
"SEND HEX CODE"
0x1f
Note
If keyboard bindings already exists for the shortcuts above, they must be removed for the new ones to take effect.
I see there's a lot of good answers already, but this should provide the closest to native OSX functionality as possible in more than just your shell. I verified that this works in ZSH, Bash, node, python -i, iex and irb/pry sessions (using rb-readline gem for readline, but should work for all).
Open the iTerm preferences ⌘+, and navigate to the Profiles tab (the Keys tab can be used, but adding keybinding to your profile allows you to save your profile and sync it to multiple computers) and keys sub-tab and enter the following:
Delete all characters left of the cursor
⌘+←Delete Send Hex Codes:
0x15 More compatible, but functionality sometimes is to delete the entire line rather than just the characters to the left of the curser. I personally use this and then overwrite my zsh bindkey for ^U to delete only stuff to the left of the cursor (see below).
or
0x18 0x7f Less compatible, doesn't work in node and won't work in zsh by default, see below to fix zsh (bash/irb/pry should be fine), performs desired functionality when it does work.
Delete all characters right of the cursor
⌘+fn+←Delete or ⌘+Delete→ Send Hex Codes: 0x0b
Delete one word to left of cursor
⌥+←Delete Send Hex Codes:
0x1b 0x08 Breaks in Elixir's IEX, seems to work fine everywhere else
or
0x17 Works everywhere, but doesn't stop at normal word breaks in IRB and will instead delete until it sees a literal space.
Delete one word to right of cursor
⌥+fn←Delete or ⌥+Delete→ Send Hex Codes: 0x1b 0x64
Move cursor to the front of line
⌘+← Send Hex Codes: 0x01
Move cursor to the end of line
⌘+→ Send Hex Codes: 0x05
Move cursor one word left
⌥+← Send Hex Codes: 0x1b 0x62
Move cursor one word right
⌥+→ Send Hex Codes: 0x1b 0x66
Undo
⌘+z Send Hex Codes: 0x1f
Redo typically not bound in bash, zsh or readline, so we can set it to a unused hexcode which we can then fix in zsh
⇧+⌘+Z or ⌘+y Send Hex Codes: 0x18 0x1f
Now how to fix any that don't work
For zsh, you can setup binding for the not yet functional
⌘+←Delete and ⇧+⌘+Z/⌘+y by running:
# changes hex 0x15 to delete everything to the left of the cursor,
# rather than the whole line
$ echo 'bindkey "^U" backward-kill-line' >> ~/.zshrc
# binds hex 0x18 0x7f with deleting everything to the left of the cursor
$ echo 'bindkey "^X\\x7f" backward-kill-line' >> ~/.zshrc
# adds redo
$ echo 'bindkey "^X^_" redo' >> ~/.zshrc
# reload your .zshrc for changes to take effect
$ source ~/.zshrc
I'm unable to find a solution for adding redo in bash or readline, so if anyone know a solution for either of those, please comment below and I'll try to add them in.
For anyone looking for the lookup table on how to convert key sequences to hex, I find this table very helpful.
In iTerm 3.0.12 you can switch to Natural Text Editing preset:
iTerm → Preferences → Profiles → Keys
Warning As it is a preset, it can override the keys you have binded before. So it's better to save your current key bindings before applying a preset.
For quick reference of anyone who wants to go to the end of line or start of line in iTerm2, the above link
http://hackaddict.blogspot.com/2007/07/skip-to-next-or-previous-word-in-iterm.html
notes that in iTerm2:
Ctrl+A, jumps to the start of the line, while
Ctrl+E, jumps to the end of the line.
Follow the tutorial you listed above for setting up your key preferences in iterm2.
Create a new shorcut key
Choose "Send escape sequence" as the action
Then, to set cmd-left, in the text below that:
Enter [H for line start
OR
Enter [F for line end
I used Travis answer and I created a dynamic profile you can import based on its instructions.
GabLeRoux/iterm2-macos-dynamic-profile
Instructions are in the readme and it's a lot faster to import this than it is to add them all manually. I made this an answer as per #gooli's request because this was hidden in a comment. Hope you enjoy this 🍻
Just to help out anyone that is having the same issue but specifically using Zsh shell with iTerm 2. It turns out that Zsh doesn't read /etc/inputrc properly, and so fails to understand any key bindings you set up through the preferences!
To fix this, you need to add some key bindings to your .zshrc file, such as:
# key bindings
bindkey "\e[1~" beginning-of-line
bindkey "\e[4~" end-of-line
Note the backslashes in the example above before the "e", the linked article does not show them, so add them into your .zshrc file when adding bindings.
The only things that work for for moving to the beginning and end of line are
⌘← "SEND ESC SEQ" OH - to move to the beginning of line
⌘→ "SEND ESC SEQ" OF - to move to the end of line
The old fashion emacs bindings can still work in iterm2 and os x terminal:
Preferences -> Profiles -> Keys (sub tab in profiles)
Set Left/Right option <kbd>⌥</kbd> key acts as +Esc (similar in os x terminal)
This should enable alt-f and alt-b for moving words by words. (Still ctrl-a and ctrl-e always work as usual)
If set as meta those old bindings will work while some iterm2 bindings unavailable.
As Explains in here, you can do it with a simple steps:
By default, word jumps (option + → or ←) and word deletions (option +
backspace) do not work. To enable these, go to "iTerm → Preferences →
Profiles → Keys → Load Preset... → Natural Text Editing → Boom! Head
explodes"
bind -p will show a list of bound escaped keys in your shell, that might help giving you more ideas / search terms.
explained in https://aaronaddleman.com/articles/hexcodes-and-iterm/
you can use xxd -psd to get key hex code.
For me, the following combination worked:
Key
Action
Esc+
End result
⌘←
Send Escape Sequence
a
Send ^[ a
⌘→
Send Escape Sequence
e
Send ^[ e