I'm looking for a solution to swap the Ctrl and Alt keys under FreeDOS OS. Does anybody know anything about this? Maybe there is a program similar to 'loadmap' that is used in GNU OS.
I have not tried that, but the command to use to make your own keyboard mappings file is KC and the command to load a keyboard mapping (typically called from AUTOEXEC.BAT) is KEYB.
If it is only for a limited number of shortcuts you want to modify you can also have a look at XKEYB and KEYMAN that together will allow you to make your own keyboard macros that can include the use of CTRL and ALT keys.
Related
The question:
How can I remap (swap) modifier keys system-wide on Linux?
Explanation:
I want to install Debian Jessie on my PC to use it with Emacs. I have a MacBook with Emacs and use it primarily. Here is how keys are arranged on laptop:
fn ctrl alt cmd spacebar cmd alt
fn is unused in my Emacs workflow, other keys configured as listed below:
ctrl acts as Hyper
alt acts as Meta
cmd acts as Control
These configuration eases for me Emacs experience (big thumb hits Control cmd key) and I got used to this kind of key bindings.
by default alt is used as Meta, while ctrl is used as Control, the keys are swapped and big thumb lays on Meta
I want to configure my keys on Linux same way, here is what I have on my PC's keyboard:
ctrl win alt spacebar alt win menu ctrl
So, to correspond to my laptop keys, I want win keys to be mapped to Alt modifier, and alt keys to be mapped to Control modifier. In this case ctrl could be used as Super modifier, while menu could be kept untouched.
Is it possible to make such configuration system-wide on Linux (Debian)?
Finally, I have managed to achieve my goal with following configuration:
!file ~/.Xmodmap
clear control
clear mod1
clear mod4
keycode 37 = Super_L
! left Ctrl becomes Super
keycode 64 = Control_L
! left Alt becomes Control
keycode 133 = Alt_L Meta_L
! left Win becomes Alt
keycode 108 = Control_R
! right Alt becomes Control
keycode 134 = Alt_R Meta_R
! right Win becomes Alt
keycode 105 = Super_R
! right Ctrl becomes Super
add control = Control_L Control_R
add mod1 = Alt_L Meta_L
add mod4 = Super_L Super_R
Also, here is similar question with quite helpful and simple guides.
Additionally to and possibly easier than using xmodmap might be to check in the keyboard layout options given by setxkbmap. These options implement common xmodmap changes, so they might well contain what you want.
For example, I like -option ctrl:nocaps which adds me another control where the caps lock was. Consider the file /usr/share/X11/xkb/rules/base.lst for a list of the standard options.
However, neither xmodmap nor setxkbmap include keyboard settings for the text-only tty terminals (non-X).
xmodmap is the place to start, keeping in mind that X knows nothing about Hyper or Meta, so you have to investigate to see which numbered modifier (mod4, mod5, etc), emacs uses for these modifiers.
Here are a few useful links:
XModMap
How to separate alt and meta keys in emacs
MetaKeyProblems
Emacs does not use swapped alt&win after xmodmap runs? (GUI emacs)
Full Disclosure
I am the author of Kinto.
You may find Kinto to be useful. It's a project I recently created, after a few years of tackling this problem a few different ways and I just now feel like it's solid enough to share.
The Kinto installer simply uses python to do the initial install, after that it's just a systemd service, bash, xprop, setxkbmap and xkbcomp. As far as I am concerned it is the fastest and most native solution to this problem that you are going to find.
Also Xmodmap is defunct, it will not work going forward with Wayland.
https://github.com/rbreaves/kinto
https://medium.com/#benreaves/kinto-a-mac-inspired-keyboard-mapping-for-linux-58f731817c0
Here's a Gist as well, if you just want to see what is at the heart of it all, it will not alternate your keymap when needed though. The Gist also does not include custom xkb keymap files that setup macOS style cursors/word-wise manipulations that use Cmd and the arrow keys.
https://gist.github.com/rbreaves/f4cf8a991eaeea893999964f5e83eebb
gist content
# permanent apple keyboard keyswap
echo "options hid_apple swap_opt_cmd=1" | sudo tee -a /etc/modprobe.d/hid_apple.conf
update-initramfs -u -k all
# Temporary & instant apple keyboard keyswap
echo '1' | sudo tee -a /sys/module/hid_apple/parameters/swap_opt_cmd
# Windows and Mac keyboards - GUI (Physical Alt is Ctrl, Physical Super is Alt, Physical Ctrl is Super)
setxkbmap -option;setxkbmap -option altwin:ctrl_alt_win
# Windows and Mac keyboards - Terminal Apps (Physical Alt is Super, Physical Super is Alt, Physical Ctrl is Ctrl)
setxkbmap -option;setxkbmap -option altwin:swap_alt_win
#
# If you want a systemd service and bash script to help toggle between
# GUI and Terminal applications then look at project Kinto.
# https://github.com/rbreaves/kinto
#
# Note: The above may not work for Chromebooks running Linux, please look
# at project Kinto for that.
#
# If anyone would like to contribute to the project then please do!
#
xmodmap/setxkbmap methods are great until you have 2nd keyboard that doesn't require any remapping. For example laptop and external keyboard.
I found swapping via udev hwdb the best because it changes only specific keyboard. For example in case of Framework laptop and Pop!OS (also should work on most Debian derivatives) to swap alt and win keys it is required to create a file /etc/udev/hwdb.d/99-fw-meta-alt.hwdb:
evdev:input:b0011v0001p0001*
KEYBOARD_KEY_38=leftmeta
KEYBOARD_KEY_db=leftalt
and then run
sudo systemd-hwdb update
sudo udevadm trigger
This makes alt-win swap only on internal laptop's keyboard only without remapping all other keyboards I connect to my laptop.
if you're using KDE you can assign the command key to Alt using the following method, but it will render the option key useless.
meaning you'll end up with two alts in command and option keys, but still better than the default
you can go to settings > keyboard > advanced tab > alt/win key behavior > check Alt is mapped to Win and the usual Alt > OK
I have a custom Swedish Dvorak keyboard layout which relies heavily on the AltGr modifier on Swedish keyboards. However, when I hit e.g. AltGr+u (which should generate a forward slash), PyCharm interprets it as Alt+Ctrl+u, which is apparently bound to something special.
Since I'd rather not play whack-a-mole with PyCharm...is there any way to solve this in any way other than removing all taken Alt+Ctrl key bindings manually?
You might want to give AutoHotKey a try. The command sequence <^>! listens for the AltGr modifier key, like so:
<^>!u::Send {/}
This line should listen for the AltGr + U key sequence and send the forward slash as expected. Because AutoHotKey listens to the keyboard and then intercepts keystrokes and sends characters separate from the underlying applications, it should be able to grab the keystroke you use and send the correct character to PyCharm, before PyCharm has a chance to interpret and alter the keystroke on its own.
This suggestion is based on similar situations I have dealt with. I have neither PyCharm nor a Swedish keyboard (Dvorak or otherwise) with which to test this.
I had the same problem with a german keyboard layout.
I need to press AltGr + 8 in order to print a '[', which I need for programming all the time. PyCharm interprets this as a shortcut for jumping in the code. This was really annoying.
For me it works fine, when I switch from 'Visual Studio' to 'Eclipse' keymap settings in PyCharm.
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.
I think that using Menu key to quit vim's insert mode would be a great thing. It would be also nice to use Super key for that, but I'm not sure if it possible since Super key is a modifier.
Anyway, I couldn't find anything related to this. Looking for your help and thanks in advance!
I don't think there's any way you can configure Vim to pay attention to the Menu key as such,
but depending on your system there are various ways to turn the Menu key into an Escape key.
If you're using X11 on Linux:
The command xmodmap -e 'keycode 135 = Escape' will turn your Menu key into an Escape key for the current session, but is not permanent. To make it permanent under Gnome, you might try adding it under System → Preferences → Startup Applications.
The xkeycaps program will give you a GUI for similar remappings.
For more information:
http://46dogs.blogspot.com/2008/05/remap-keys-in-ubuntu-804-hardy-heron.html
http://ubuntuforums.org/archive/index.php/t-106209.html
I haven't found a way to map it in gVim yet, but I was able to successfully map the Menu key in a urxvt+screen+vim stack by the following method:
In a terminal, type Ctrl+v and press Menu. This is mapped to the quoted-insert function in Zsh and in Readline-based tools like Bash.
It will generate an escape sequence like ^[[29~ at the prompt. (The initial ^[ must be translated to <Esc> for use in .vimrc.)
Open up .vimrc and add a line like this:
imap <Esc>[29~ <Esc>
(or imap <Esc>[29~ <Esc><Esc> if you don't want it to wait for further input like the Escape key does.)
Note that not all keys return something usable from Ctrl+v. This is a limitation of terminal emulators and can be remedied by remapping the key. You may be able to do that at the level of the terminal emulator rather than for all X apps.
For example, for urxvt, I had to add the following lines to ~/.Xresources and run xrdb -merge ~/.Xresources to apply them:
! Unbreak zsh keys in URxvt
URxvt*keysym.Home: \033[1~
URxvt*keysym.End: \033[4~
(\033 is <Esc> in ~/.Xresources syntax.)
Just try using ctrl+[ instead of binding another key. This combination is a standard one in vim, btw.
This is even easier when having rebound capslock into an additional ctrl.
I am an emacs user (on linux laptop) looking to make better use of my keyboard settings. The windows key is unused on my keyboard... is there any way to map it to m-x? This might make many emacs commands faster.
Thanks,
SetJmp
Use xmodmap to make it the Menu key, as in
keycode 115 = Menu
You will have to use xev to find out if the Windows key is key 115 on your keyboard.
Just to provide a little more info, here's a link to a quick series of steps to remap the CapsLock Key in both X and Virtual Consoles:
The steps can be identically followed for Windows key or whatever else you may wish to remap.