How to remap C-x prefix in emacs to a dedicated key? - emacs

Many emacs commands start with C-x or C-c. I found that I never use the right shift key. So I was thinking if it's possible to remap C-x to Shift. To open a file, I can do Shift-Ctrl-f instead of C-x C-f. Here I would prefer Shift-Ctrl-f than Shift Ctrl-f.

The link created by SSH between machines does not transmit the pressing and releasing of the shift key; only when another key is pressed in conjunction with Shift is a character transmitted, and the character — upper case H when Shift and “h” have been pressed, for example — looks the same to the remote machine whether left or right shift was used.
Therefore, to make right Shift visible, you will have to tell the terminal program to consider it to be a different key — or maybe even have to tell the Mac system settings that it is no longer Shift?
Is it possible to explain to your Mac that pressing Shift sends the character Control-X? That would kill both birds with one stone!

Related

Are RET and C-m really the same exactly?

In the graphical mode, RET does the same as C-m, namely newline.
However, when I use M-a or M-e, they seem to distinguish between them. The newline produced by RET, they skip all to a double-RET point, and with the newline produced by C-m, they move the cursor line by line. Why so?
Description (C-h k) for both keys shows the same.
If it matters, it is Emacs23.3.1 on Ubuntu 12.04.
The answer could be dependent on the mode you're in as well as in the key codes generated by your operating system. When I hit Ctrl-h k Ctrl-m in the *scratch* buffer on my Windows box, I'll get the info for (newline) with the information that it is bound to RET. Theoretically, in some other mode, C-m and RET could be set to different functions. This requires, of course, that the OS doesn't generate the same key code.
What Emacs writes as RET (or as <RET>) is, yes, the same character as C-m - it is the ASCII control character 13. This is so regardless of what keyboard etc. you have.
However, the logical key (aka "key sequence") that Emacs sees when you hit the phisical (keyboard) key named Enter or Return might be different from RET (aka C-m). To see what key Emacs recognizes when you hit that keyboard key, use C-h k and hit the key. If Emacs says RET then this is the typical case, and yes, hitting that key is then identical to pressing Control and hitting m (assuming the key labeled Control does what it does typically).
In the graphical mode, the answer is yes (unless keys are redefined, of course).
Careful examination of my file showed that the effect I observed was a coincidence. It was exactly in those paragraphs which I C-m'ed that all lines would end in a dot (it was a poem).
Actually, C-h k key description says the same thing for both keys. Thanks to schaueho's answer for pushing me in this direction.

Can I bind something to ALT (Meta)

I've got:
(global-set-key '[f11] 'menu-bar-mode)
How can I bind it to left ALT / Meta and will there be conflicts of using alt as meta?
You can't bind a function to a modifier key, because Emacs does not receive any input when a modifier key is pressed on its own (or more accurately, when one or more modifier keys are pressed without a non-modifier key also being pressed).
n.b. Your operating system determines which keys are modifiers, not Emacs.
You could probably tell your OS not to use the left Alt key as the Meta modifier and to instead send some sequence which you could then configure Emacs to recognise. You would want to configure some other key as the Meta modifier in that case of course, unless you are happy using right Alt exclusively.
I'm unsure precisely how you'd do that, but in a Unix-like OS reading up on xmodmap is typically the first port of call.

Caps lock rebound to ctrl generates Ctrl-Shift in emacs

I've rebound my caps lock key to be an additional ctrl key, but in emacs using the rebound key generates the C-S key combination. Pressing caps-p generates the sequence C-S-p, whereas using the the ctrl key to do the same generates C-p.
This results in some weird behaviour, such as C-n and C-p setting a mark and then highlighting the region that I go through.
I have not changed the definition of the caps key in X, instead using the setting built into my window manager (Cinnamon). Could this be what is causing the problem, or is this the intended behaviour of this key?
This question is probably relevant, basically just use xmodmap to set the keys directly. It worked for me when I had caps lock set to control and I think I was using gnome3 classic (which Cinammon is based on) at the time.
On a related note I'd also recommend having a look at space2ctrl, I found that reaching for caps lock all the time still hurt my fingers.
I'm running CrunchBang 10 "Statler" (derived from Debian 6 "Squeeze") on an Asus laptop
(yeah, I'm a little behind right now)
I've currently got GNU Emacs 23.2.1. It didn't even recognize the Caps Lock key as a keypress until I re-mapped it to Ctrl using xmodmap.
So first I created file ~/.Xmodmap:
! attempting to redefine the <Caps Lock> key to do <Ctrl>
remove Lock = Caps_Lock
add Control = Caps_Lock
Apparently Debian uses .xsession, vs..xinitrc.
file .xsession is where the window manager (Openbox) gets started with exec
I inserted the xmodmap call before the exec:
#!/bin/sh
# gonna modify the keys so <Caps Lock> is <Ctrl>
xmodmap /home/tom/.Xmodmap
exec openbox-session
The Caps Lock key seems to be working just like the Ctrl key
within Emacs now.
I also faced this problem before, my keyboard has problem with CTRL key. Maybe you have the same problem.

emacs: remapping C-[ (currently ESC)

I'm using emacs 23 on ubuntu 10.04. I would like to remap the "C-[" binding. Currently, when I press it, it gives me "ESC". Is there a way to remap it?
This is not an Emacs binding, but has global effect in X and it's used as handier substitute for ESC for people practicing touch typing. I guess you'll have to modify the X keymap if you want to use it in another fashion, but I wouldn't advice that.
C-[ is the ASCII ESCAPE character, which Emacs usually writes as ESC.
There is no key involved here (it's a character), and there is no key binding involved here. Or rather, your keyboard's Escape key sends the control character ESCAPE (also written C-[ and ESC).

How can I select or highlight a block in Emacs?

I want to select or highlight a block in Emacs without using the mouse, but doing it from the keyboard like Vim's visual mode. What is the easiest way to do this from a keyboard?
If I understand the question correctly, it is not about rectangular regions originally.
C-Spc puts a mark at the current position.
Wherever your cursor is afterwards, the text between the last mark and the current position is "selected" (you can highlight this by activating transient-mark-mode, but this will also mean that marks have to be deleted when you don't want highlight).
You can operate on that region with commands like:
C-w . . Kill region. This deletes and puts the region into the kill ring.
C-y . . Yank. This inserts the last snippet from the kill ring.
M-y . . Cycle kill ring. Immediately after C-y, this replaces the yanked part by the other snippets in the kill ring.
M-w . . Save region into kill ring. Like C-w, but doesn't delete.
This is just the basic usage. Marks have other uses, too. I recommend the tutorial (C-h t).
Take a look at region-rectangle in Emacs.
In short, you start selection like usual with Control-Space, then kill region with Control-x r k and paste (or yank) killed block with Control-x r y.
Emacs 24.4 now has rectangle-mark-mode. Use Ctrl + X, Space to invoke it.
Although C-SPC is a common way to start marking something from
wherever your point is, there are often quicker/easier ways that don't
involve explicitly moving to start/end points...
Built-in selection shortcuts
M-h — an important means to mark a paragraph. A "paragraph"
often means a block of code.
C-M-h and C-M-# — for marking sexps and defuns,
respectively. This works for several languages, not just lisps.
hold down shift — another slick way to highlight during
movement. E.g., M-S-f selects forward a whole word. This is
shift-select-mode,
and it is enabled by default in Emacs 24+. On some (non-chiclet)
keyboards, you should be able to hold down C-S- with a single
pinky.
You can press any of these repeatedly to grow the selection.
There are also a few special ways to mark things:
C-x h — mark the whole buffer
C-x SPC — enter rectangle mark mode
(NOTE: use C-g often to cancel marking while
experimenting.)
Add-ons
There are a few add-on packages that improve selecting regions and
things. These are all play nicely together and fit different use
cases. Use them all!
expand-region:
Expand region increases the selected region by semantic units. Just
keep pressing the key until it selects what you want. C-= is a
recommended binding for it. Hit it a few times to get what you
need.
easy-kill: Use M-w and
a mnemonic to select different types of things, like words, sexps,
lists, etc.
zop-to-char:
Like zap-to-char, but provides nice selection and other
menu-driven actions.
diff-hl: Highlight uncommitted changed regions. Use diff-hl-mark-hunk to select/mark a hunk.
symbol-overlay: Select symbol at point with a keystroke (M-i). Then you can do other things with it, like copy, search, jump, replace, etc.
Use Control-Space to set a mark and move your cursor.
The transient-mark-mode will highlight selections for you. M-x transient-mark-mode.
You can setup Emacs to enable this mode by default using a customization. M-x customize-option RET transient-mark-mode.
... and in case you are using Ubuntu and Ctrl + space is not working for you: you need to clear the Intelligent Input Bus (IBus) "next input method" key binding, as in
run ibus-setup and change the key binding for
"next input method" to something else (or delete it entirely by
clicking the "..." button and then the "Delete" button).
The quote is taken from an answer to a Stack Overflow question.
To expand answer of Edin Salkovic, if you use CUA mode, you can use Ctrl + Enter to begin a visual block selection. There are plenty of shortcuts to control block selection described in the documentation of CUA.
With Emacs 25, simply press Ctrl + Space and then move your cursor wherever you want to highlight/select the region of text which interests you. After that, you may need these commands:
Ctrl + W for cutting.
Alt + W for copying.
Ctrl + Y for pasting.