Why does pressing the arrow keys while something is running in bash produce "^[[A^[[C^[[B^[[D"? - bash

Let's say you run the command
find . -iname bob
While it is running, pressing various letters on your keyboard inserts it before the standard output of the next line produced by "find". However, pressing the up arrow produces "^[[A". Is this some keyboard shortcut for the arrow keys?
I am currently imagining it is something like CTRL + ? + A since CTRL + C produces "^C".

Is this some keyboard shortcut for the arrow keys?
Correct. The terminal generates these character sequences when extended keys are pressed, and it is up to the software (e.g. readline) to interpret these sequences appropriately.
I am currently imagining it is something like CTRL + ? + A since CTRL + C produces "^C".
Also correct. It is Ctrl[, just as shown.

Related

I don't understand the format selection (cmd + K cmd + F) shortcut keys in VS Code

Can someone please explain to me how the "format selection" (cmd + K cmd + F) shortcut keys - and other shortcuts that seemingly have multiple button press combinations - work in VS Code.
I tried pressing cmd + K and cmd + F simultaneously (though, cmd is listed twice so I am really pressing cmd + K + F in this case) and I have tried hitting them in order. If someone could explain what they mean here, then it would be much appreciated. I am sure it's a simple solution that I have been overlooking for all these years.
The written format for shortcut expressions use the operators '+' (plus) and ' ' (space) to define whether the expressions on each side of the operator should be pressed simultaneously, or sequentially.
'+' represents two keys pressed then held simultaneously, in left-to-right order.
This is the same as typing an uppercase letter using the shift key: Shift+a -> A
' ' represents concatenating the right-hand-side key combo after the left-hand-side combo.
This is the same as typing an uppercase word using the Shift key: Shift+h Shift+i -> HI
In the second example above, note that you can either keep holding Shift, or you can release it and press it again for each letter. The same applies with VSCode shortcuts.
In the case of Format Selection (Cmd+k Cmd+f), Cmd should be held while first k then f are pressed. Pressing k and f together is a different shortcut entirely (Cmd+k+f), as is pressing f and k together (Cmd+f+k). Since the left-hand-side key (Cmd) is the same for both expressions, you don't need to release it between typing the k and f.
To get a better grasp of how keyboard shortcuts are expressed, I'd suggest opening the the VSCode Preferences for Keyboard Shortcuts either using the command palette, or using the shortcut: Cmd+k Cmd+s: (type ks while holding Cmd).
Then activate the Record Keys mode (Alt+K). Now type different key sequences, and it will show you the textual representation in the search bar, along with any shortcuts that match what you typed.

Remap ctrl+c to cmd+c

By default zsh suggest ctrl+c as interruption hotkey. I need to remap to cmd+c. I tried to do it via bindkey, but can't find interrupt-action id. What can I do with that? Thank you much.
This is not a problem of zsh itself - it's actually a setting of underlying terminal emulator. You can view your current terminal settings using stty -a command. Output of this command will most probably contain intr = ^C somewhere, which is the currently used control character for interrupt.
Yes, you read it right - it is in fact a single character.
That's where the main problem lies with your proposed new key combination - key combination Command + C (sometimes called Super + C) produce unmodified c character - there is no way for terminal to actually recognize if the Command key was pressed or not.
So I'm afraid you can't changed it, at least not on shell level.
This will make you keyboard works like Mac.
Remaps Left Ctrl with AltGr
sudo vi /usr/share/X11/xkb/symbols/ctrl
Change the section
// Map Ctrl to the left Alt key, Alt to the left Win key,
// and Super to the left Ctrl key.
when it says "replace key " with
replace key { [ ISO_Level3_Shift ] };
Open Tweaks
On Additional Layout Options -> Ctrl , mark "Map Ctrl to the left Alt key, Alt to the left Win key, and Super to the left Ctrl key."
On your shell configuration .zshrc in my case, remap to intr check if you have the cent symbol there before. Add this to the file :
stty intr 0xA2
On gnome-terminal remap the copy and paste shortcuts to "Ctrl C" "Ctrl V"
And move physically your keys to make sense

How can I remap broken arrow key via hidutil?

I have the arrow keys of the keyboard broken so I though to use the combination Ctrl + "asdw" instead. As an example, if we want to change the down arrow key, my question is: how can I remap it to Ctrl + s. Through KeyCode I got that Ctrl + s is:
Also,
How can I add it to hidutil code knowing that the down arrow code is 0x700000051?
Thanks,
At the end, since I want to replace the arrowkeys for Ctrl + "asdw", I decided to employ a specific third-party app which I read in the comments of a post: BetterTouchTool. Since the remap is done easily, at the end I replaced all the arrows with Fn + "asdw", as well as any combination of Opt/Ctr/Cmd + arrow with Opt/Ctr/Cmd + Fn + "asdw". It is not the best solution but it works nicely fine!

Set shortcut for command Debug.DisableAllBreakpoints

I am using VS2015. I would like to have shortcut Ctrl + Shift + D for disabling all breakpoints. It should be easy, but under Environment - Keyboard after pressing Ctrl + Shift + D I have only limited amount of choices to pick from. Is it possible to set this shortcut to command Debug.DisableAllBreakpoints?
That bottom list is not your set of choices...it is what is currently assigned to the key sequence you are trying to use.
If you click "Assign", the key sequence should be assigned to your command and overwrite the sequence in the commands in the bottom list, i.e. remove the shortcut from those commands.

Mac OS X Terminal: Map option+delete to "backward delete word"

Tried to map it from Preferences -> Settings -> Keyboard, but the "key" combo box has only "forward delete" but no "delete". My keyboard on the other hand has only "delete" and no "forward delete"!
Is there some other way to do it except from the preferences?
Enable option key as meta key
Go to Terminal > Preferences > Profiles > Keyboard
Check Use option key as meta key.
Image
On macOS High Sierra 10.13.6, captured on October 23, 2018.
Notes
Many applications (including bash and tcsh) treat Meta-Delete as "backward delete word."
OS X's terminal runs bash, which includes readline support. Follow Glomek's advice and tell terminal to use option as meta key (or else use Esc) and then you've got a bunch of handy options: Ctrl+w deletes prev word (as does Meta+delete as mentioned), but you can also use Meta+f and Meta+b to walk forward and backwards thru words, Ctrl+a and Ctrl+e to beginning and end of line, Ctrl+k delete (kill) from cursor to end of line, and a bunch more.
See http://www.bigsmoke.us/readline/shortcuts for a nice little reference table.
Delete a word going back:
Ctr-w.
Command Editing Shortcuts
Ctrl + a – go to the start of the command line
Ctrl + e – go to the end of the command line
Ctrl + k – delete from cursor to the end of the command line
Ctrl + u – delete from cursor to the start of the command line
Ctrl + w – delete from cursor to start of word (i.e. delete backwards one word)
Ctrl + y – paste word or text that was cut using one of the deletion shortcuts (such as the one above) after the cursor
Ctrl + xx – move between start of command line and current cursor position (and back again)
Alt + b – move backward one word (or go to start of word the cursor is currently on)
Alt + f – move forward one word (or go to end of word the cursor is currently on)
Alt + d – delete to end of word starting at cursor (whole word if cursor is at the beginning of word)
Alt + c – capitalize to end of word starting at cursor (whole word if cursor is at the beginning of word)
Alt + u – make uppercase from cursor to end of word
Alt + l – make lowercase from cursor to end of word
Alt + t – swap current word with previous
Ctrl + f – move forward one character
Ctrl + b – move backward one character
Ctrl + d – delete character under the cursor
Ctrl + h – delete character before the cursor
Ctrl + t – swap character under cursor with the previous one
Command Recall Shortcuts
Ctrl + r – search the history backwards
Ctrl + g – escape from history searching mode
Ctrl + p – previous command in history (i.e. walk back through the command history)
Ctrl + n – next command in history (i.e. walk forward through the command history)
Alt + . – use the last word of the previous command
Command Control Shortcuts
Ctrl + l – clear the screen
Ctrl + s – stops the output to the screen (for long running verbose command)
Ctrl + q – allow output to the screen (if previously stopped using command above)
Ctrl + c – terminate the command
Ctrl + z – suspend/stop the command
Bash Bang (!) Commands
Bash also has some handy features that use the ! (bang) to allow you to do some funky stuff with bash commands.
!! – run last command
!blah – run the most recent command that starts with ‘blah’ (e.g. !ls)
!blah:p – print out the command that !blah would run (also adds it as the latest
command in the command history)
!$ – the last word of the previous command (same as Alt + .)
!$:p – print out the word that !$ would substitute
!* – the previous command except for the last word (e.g. if you type _find somefile.txt /, then !* would give you _find somefile.txt)
!*:p – print out what !* would substitute
⌃W (control+W) is not the same thing than meta + delete (ESC+delete if you don't have checked use option as meta key)
meta+delete will treat / _ as word delimiter where ^W will consider space as delimiter.
e.g.
using ESC+Bakcspace on (cursor at the end)
rm /dira/dirb/file1
gives
rm /dira/dirb/
while ^W on the same will give
rm
So it is better to use \033\177 rather than ^W when defining the modifying the terminal profile.
That way you are really mapping ⌥⌫ to what esc⌫ is doing and you keep having ^W to erase word based on space delimiter.
I would love to be able to post an image on how do this but as a newbies I can't.
refer to bouke comment to see how to modify terminal profile.
By default meta backspace does a backwards word yank in most shells. If you press escape and then press backspace, that pretty much works everywhere.
In your Terminal's profile, you can bind ⌥⌫ (option+delete) to ⌃W (control+W), so it works similar to other apps.
If you are using Iterm2 (which is like the regular terminal of OSX just better :)
you can use this like to change this behavior:
You need to set your left ⌥ key to act as an escape character. This can be done going to iTerm2 > Preferences > Profiles > Keys.
With Natural Text Editing preset enabled in Profile -> Keys.
You can simply remove the word
Backward with alt + delete
Forward with fn + alt + delete

Resources