Remapping Alt+` to ESC - keyboard

My Esc key is broken on my keyboard, and I would like to remap it to Alt+` (that's Alt and ` grave accent, same button as the ~ tilde). However:
!`::Esc
will trigger Alt+Esc when pressed (!Esc) because the Alt key is held down. How do I remap Alt+` so that, when pressed, it will trigger Esc rather than Alt+Esc?
EDIT: I am not opposed to using an entirely different program to remap my keys. I just want to remap ALT+` to
the Esc key in all of my Windows.

Use SendPlay:
!`::sendplay {Esc}
SendPlay [...] buffers any physical keyboard or mouse activity during the send, which prevents the user's keystrokes from being interspersed with those being sent.

I found two possible ways to achieve this.
Use BlockInput
Disables or enables the user's ability to interact with the computer via keyboard and mouse.
!p::
BlockInput On
send {Esc}
BlockInput, Off
return
You might need to run the script as administrator and the alt and/or p may get stuck down, which led me to the second solution.
Use KeyWait
Waits for a key or mouse/joystick button to be released or pressed down.
!p::
KeyWait, Alt
send {Esc}
return

This should work:
!`::
SendInput, {Alt Up}{Esc}
Return

Related

How to remap keys after Alt+Tab/Ctrl+Tab while Alt/Ctrl is currently being held?

I am trying to use VIM a lot in my day to day life, and I prefer not to move my hands away from the home row. That being said I do alt tab/ctrl tab a lot, but its tedious to keep pressing TAB to cycle applications. When you press Alt+tab and keep alt pressed down, i would like to remap hjkl to the arrow keys only when ALT is currently held down AFTER pressing ALT+Tab. Is it possible to do this in AutoHotKey?
Yes, it is possible. I'd suggest doing some research about hotkeys within hotkeys and come back with a script we can help you tweak.
when you press Alt+Tab you enter a new framework called the MultitaskingViewFrame
so you need to work from within this context.
try this:
#IfWinActive ahk_class MultitaskingViewFrame
i::up
j::left
k::down
l::right
#IfWinActive

How to map reparted sequence in VIM?

I want to map 'space+u' as 'Ctrl+u', I have this at my config:
nnoremap <space>u <C-u>
But it isn't work as Ctrl+u. When I press 'space+u', firstly it works fine, but when I press 'u' second time - it works an 'undo' (I'm holding 'space' since first time). I want to make it works as , when I press 'Ctrl', hold it and can hit 'u' any times I want.
What can I do?
The mapping you made means "space first, then u in succession". Not simultaneous action there, which explains the behavior for subsequent calls.
Vim listens to key press events; the system reports it that this-and-that key was typed, with that-and-that modifier (ctrl, super). Few applications would understand to check arbitrary combinations of keys being held (outside of games).
For this sort of hacks there is an established project for Linux systems called https://github.com/alols/xcape. In combination of xcape and xmodmap you can basically map <space> as a modifier key like less used Hyper key (this is the part for xmodmap). Then you would use xcape to make sure that pressing space in isolation would result in a space character. People have used xcape to map return as a right Ctrl key (while Caps Lock would act as the left Ctrl).

How to enter C-M-b in Emacs under a windows keyboard?

I am running Linux on a VM under Windows. When I am using Emacs on Linux, since my keyboard doesn't have the meta key, I will do my meta key command by pressing Esc, release it, and then press the subsequent letter key.
What if the command is Ctrl-Meta-b? My previous Esc way wouldn't work since it cancels the Ctrl. Any suggestion will be welcome. (Emacs and Linux noob here, so please don't laugh and be specific.)
First hit Esc, and then Ctrl+b. The escape keypress applies to the entire following key combination.
Depends a little what your meta key is mapped to in Windows, in my (pretty "stock") Emacs 24.3 setup, "Alt" serves as the Meta key.

how to remap <C-;>

I want to use the following code to quickly go from insert mode -> command mode. The problem is it just doesnt seem to be registering my keys. I've tried with control (nothing happens) and i've also tried with command (D) and it just says spellcheck not activated.
" Quick command mode from insert
imap <C-;> <esc>:
How do i go about doing this? is there an easier vim way that I'm not aware of?
Certain Ctrl chords can't be mapped, including Ctrl-;.
This is mentioned in this FAQ, see also the Vim FAQ:
20.4. I am not able to create a mapping for the <xxx> key. What is wrong?
First make sure that the key is passed to Vim. In insert mode, press Ctrl-V
followed by the desired key. You should see the keycode corresponding to
the key. If you do see the keycode, then you can create a mapping for the
key using the following command:
:map <C-V><xxx> <your_command_to_be_mapped>
For more information, read
:help map-keys-fails
:help :map-special-keys
:help key-codes
The tip about trying to print the character using Ctrl-V is good to remember if you run into this problem with another key combo.
I tried it, however it doesn't seem to work, also as pb2q said, it just can't be mapped. But there are other ways to escape using a Ctrl key combination.
For example, you can also escape insert mode with the following key presses:
Ctrl-[
Ctrl-c
On OS X (I think Lion and above), you are able to map alt - ; using this method, alt - ; on OS X outputs รง, which you can map.
But at a MacBook, I prefer to use PCKeyboardHack to map caps lock to esc. Or at Windows, use a tool I've created myself for that or even Ctrl2Cap.
EDIT
oh sorry, I thought you wanted to switch to normal mode, that's why I talked about caps lock mappings.

Return to normal mode without leaving the home row

I've been trying out vim, and the emphasis on speed and accessibility makes sense for the veteran programmer. I've previously used emacs, and currently use a combination of nano, and stuff like gedit or geany.
I'm confused by the need to constantly switch modes, and that returning from insert mode to normal mode requires leaving the home row to press Esc. I've read that previously, this key was Tab on some systems where vim was first used, which makes a lot more sense, but not on current systems where tab is expected to participate in smart indenting when coding.
Returning to normal mode is an operation that you need to perform all the time. Is there some alternative key mapping that makes this quicker, or mappings that I simply don't know about that do this?
Ctrl+C also return you to normal mode
You can also use ^[. If you've mapped your caps lock key to control (highly recommended), this becomes a rather easy keystroke.
I personally use the Capslock key as the second Esc key, so it is very comfortable. You can do it by adding the following lines to your .xmodmap file:
remove Lock = Caps_Lock
keysym Caps_Lock = Escape
You can map whatever you like to escape:
imap kj <Esc>
I haven't yet run across a situation where I need to type kj next to each other, besides when I talk about this mapping. I've seen other people use jk or jj, but kj works best for me.
I personally use ii to get out of insert mode while staying on the home row, but it is only a matter of personal preference:
inoremap ii <Esc>
i to go in insert and ii to go out. This is easy for your finger to remember. (I tend to still use <Esc> though)
I personally use Left Control as escape and Caps Lock as Left Control. It is not vim mapping, but some xmodmap+setxkbmap magic:
! ~/.Xmodmap
! Control_R
keycode 37 = Escape
and ctrl:nocaps in X keyboard options. You may have different keycode though.
Use Alt/Meta In a Terminal
If you use Vim in a terminal, simply press alt/meta+normal_mode_key. Most terminals send an escape character followed by the normal_mode_key that you pressed, removing the need to press escape yourself.
The terminals konsole and gnome terminal send the escape by default when you press alt/meta+normal_mode_key. For Xterm you can ctrl+click and select the option "Meta sends escape" or "Alt sends escape".
Thus in insert mode pressing alt+h alt+j alt+k alt+l all take you to normal mode and move in the expected direction. You can hold down alt when moving even while in normal mode since the additional ESC that is sent does no harm.
The advantage of using this scheme is that you can use the alt/meta+key combination with any normal mode key, e.g.
Alt+o opens a new line below the one you are currently editing,
Alt+A appends to the end of the current line,
Alt+p pastes at the current insert location.
Alt+k moves up
Thus using vim via a terminal gives you these short cut powers on any stock standard system without the need to edit each systems vim mappings.

Resources