Make Bash Differentiate Between Ctrl-<Letter> and Ctrl-Shift-<Letter>

Make bash differentiate between Ctrl-letter and Ctrl-Shift-letter

A terminal doesn't interact directly with your keyboard; it interacts with a stream of bytes that it receives, which are usually (but not necessarily) generated by your keyboard. For the printable ASCII values, there is an obvious correspondence between the value and a key (or combination) on your keyboard. ASCII 97 is a, ASCII 65 is Shifta, and so on.

However, there are the 32 non-printing control characters from ASCII 0 to ASCII 31, called which because they were intended to control a terminal. In order to enter them, the Control was added to allow you, in combination with the other keys, to generate these codes. A simple scheme was used. Pressing Control-x will generate the control code corresponding to subtracting 64 from x. Since @ generates ASCII 64, Control@ generates ASCII 0. The same mapping holds true for A through _ (consult your favorite ASCII reference to see the rest of the correspondences).

However, whether or not you need a shift key to generate ASCII 64 through ASCII 95 depends on your keyboard. On my US keyboard layout, only [ and ] can be typed without a shift key. (Remember, it's the uppercase-letter ASCII range we're using here, not the lowercase.) So to simplify, I suspect it was decided that Shift would be ignored in determining which keycode is sent with Control-x. (Note that if for some reason your keyboard had two of the characters between 64 and 95 generated by a key/Shift-key pair, your terminal would need to define an alternate mapping for the associated control character.)

All this is simply(?) to explain why ControlShift-x and Control-x are typically the same. Obviously, your modern operating system can distinguish all kinds of keyboard combinations. But out of the myriad possibilities, only 256 of them can send unique values to a terminal; the rest must necessarily duplicate one or more of the others. To be useful, they need to be configured to send some multiple-byte sequence to the terminal, typically beginning with ASCII 27 (ESC). When terminals receive that byte, they pause for a moment to see if any other bytes are coming after. Keys like function keys, arrow keys, etc. have fairly standard sequences they send, which the terminal interprets in various ways. Other keys (like ControlShiftn in your example) have no agreed-upon meaning, and so your terminal emulator must assign one. Most emulators should allow you to do this, but how they do so is, obviously, program-specific.

How do you copy and paste into Git Bash

Press Insert.

Also, to copy from the window, try clicking the console's window icon (topleft) and choosing Edit -> Mark, then drag a box on the text, then press Enter. (You can also paste via the window icon menu, but the key is faster.)

UPDATE

Starting from Windows 10 the CTRL + C, CTRL + V and a lot of other feature are implemented in conhost.exe so they should work with every console utility on Windows. (You have to enable Properties -> Option tab -> Quick Edit Mode)

Ref: http://blogs.windows.com/buildingapps/2014/10/07/console-improvements-in-the-windows-10-technical-preview/

How to map Ctrl+A and Ctrl+Shift+A differently?

Gvim doesn't do it because vim cannot do it (under normal circumstances). Sorry, but that's just how it is.


However...

Some terminals (e.g., xterm and iterm2) can be configured to send an arbitrary escape sequence for any combination of keys.

For example, add the following to .Xresources for xterm to send <Esc>[65;5u for CtrlShiftA. You can then map that in Vim to <C-S-a>. (65 is the decimal Unicode value for shift-a and 5 is the bit for the ctrl modifier. The u in this case stands for "unicode".)

! .Xresources
XTerm*vt100.translations: #override Ctrl ~Meta Shift <Key>a: string(0x1b) string("[65;5u")

iTerm and [u]rxvt can also be configured to do this (examples not provided).

More info: http://www.leonerd.org.uk/hacks/fixterms/

How do I bind to s-up?

Named keys should be written in angle brackets like this:

(kbd "s-<up>")

The exceptions to this are RET, SPC, TAB, DEL, LFD, ESC, and NUL, which must be in uppercase. See the documentation for edmacro-mode (C-h f edmacro-mode) for a more complete explanation of the syntax kbd accepts.

Also note that the s- prefix is for the super modifier, and S- is for shift.

VS Code: bring up the Ctrl+Shift+P Command Pallette but without in it

You can look the shortcuts just type Keyboard Shortcuts in the command pallet (or magic textbox :D) and search for "Go to File", default it is CTRL+P

How do I use Bash on Windows from the Visual Studio Code integrated terminal?

  1. Install Git from https://git-scm.com/download/win

  2. Open Visual Studio Code and press and hold Ctrl + ` to open the terminal.

    Sample Image

  3. Open the command palette using Ctrl + Shift + P.

  4. Type - Select Default Profile

  5. Select Git Bash from the options

  6. Click on the + icon in the terminal window

  7. The new terminal now will be a Git Bash terminal. Give it a few seconds to load Git Bash

    Sample Image

  8. You can now toggle between the different terminals as well from the dropdown in terminal.

    Sample Image

Where is the Insert mode command Control-Shift-U documented in Vim?

C-S-U is not a Vim function: it is for inserting Unicode characters based on their HEX values.

Because it is a functionality of the OS, it is not in the Vim documentation (it's like C-S-V for pasting text, which is a function of the terminal and also not documented in Vim).

Copy Paste in Bash on Ubuntu on Windows

Update 2019/04/16: It seems copy/paste is now officially supported in Windows build >= 17643. Take a look at Rich Turner's answer. This can be enabled through the same settings menu described below by clicking the checkbox next to "Use Ctrl+Shift+C/V as Copy/Paste".


Another solution would be to enable "QuickEdit Mode" and then you can paste by right-clicking in the terminal.

To enable QuickEdit Mode, right-click on the toolbar (or simply click on the icon in the upper left corner), select Properties, and in the Options tab, click the checkbox next to QuickEdit Mode.

With this mode enabled, you can also copy text in the terminal by clicking and dragging. Once a selection is made, you can press Enter or right-click to copy.



Related Topics



Leave a reply



Submit