Vim Tips Wiki
Line 93: Line 93:
 
Please note that we regard comments as temporary, and all discussions such as this one will be deleted in due course (after a week or two). That does not apply to user talk pages, but it does apply to tips and their talk pages because we want to present simple-to-follow text and don't have the contributors to justify talk pages. I'm just warning you that this discussion is also likely to be cleaned away. [[User:JohnBeckett|JohnBeckett]] 00:40, 1 August 2009 (UTC)
 
Please note that we regard comments as temporary, and all discussions such as this one will be deleted in due course (after a week or two). That does not apply to user talk pages, but it does apply to tips and their talk pages because we want to present simple-to-follow text and don't have the contributors to justify talk pages. I'm just warning you that this discussion is also likely to be cleaned away. [[User:JohnBeckett|JohnBeckett]] 00:40, 1 August 2009 (UTC)
   
Windows up until XP, and Vista (I think) do not have a nice UI for changing the mappings of the keyboard. Over the years that I have been using vim, every time I installed or re-installed Windows, one of my first stops has always been to install vim and then map the CAPS key to the control key and make the old control key the CAPS key.
+
:Windows up until XP, and Vista (I think) do not have a nice UI for changing the mappings of the keyboard. Over the years that I have been using vim, every time I installed or re-installed Windows, one of my first stops has always been to install vim and then map the CAPS key to the control key and make the old control key the CAPS key.
   
 
:On Linux/BSD/... these things are a small afterthoughts no doubt. The original realization that you could actually do this on Windows, however, was life changing for me as far as vim on Windows is concerned. Anyways, long story short: I would periodically go back to the vim site and dig up my old tip. It's the kind of thing you do and forget about for the next three years.
 
:On Linux/BSD/... these things are a small afterthoughts no doubt. The original realization that you could actually do this on Windows, however, was life changing for me as far as vim on Windows is concerned. Anyways, long story short: I would periodically go back to the vim site and dig up my old tip. It's the kind of thing you do and forget about for the next three years.

Revision as of 20:55, 2 August 2009

The tip page is intended as a summary of the best methods for using the Windows operating system to remap keys.
This talk page will hold details that are not appropriate for the main tip.

Registry

Following are some examples of settings to map the keyboard in different ways.

Map CapsLock as Escape (press CapsLock to generate Escape):

REGEDIT4
[HKEY_CURRENT_USER\Keyboard Layout]
"Scancode Map"=hex:00,00,00,00,00,00,00,00,02,00,00,00,01,00,3a,00,00,00,00,00

The above applies to the current user (log off and log on to apply). Alternatively, an administrator can apply the change to all users (reboot to apply) by replacing [HKEY_CURRENT_USER\Keyboard Layout] with [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout]

Swap CapsLock and Esc (press Capslock to generate Escape; press Esc to generate CapsLock):

"Scancode Map"=hex:00,00,00,00,00,00,00,00,03,00,00,00,01,00,3a,00,3a,00,01,00,00,00,00,00

Map CapsLock to LeftCtrl (press CapsLock to generate LeftCtrl):

"Scancode Map"=hex:00,00,00,00,00,00,00,00,02,00,00,00,1d,00,3a,00,00,00,00,00

Swap CapsLock and LeftCtrl:

"Scancode Map"=hex:00,00,00,00,00,00,00,00,03,00,00,00,3a,00,1d,00,1d,00,3a,00,00,00,00,00

Map LeftAlt as CapsLock, LeftCtrl as LeftAlt, and CapsLock as LeftCtrl (useful for some laptops):

"Scancode Map"=hex:00,00,00,00,00,00,00,00,04,00,00,00,3a,00,38,00,38,00,1d,00,1d,00,3a,00,00,00,00

Registry scancodes

This section is an explanation of the format used for "Scancode Map", from Scan Code Mapper for Windows and Keyboard scan codes.

More information is at Remap the F12 Key, CapsLock Key or any Key in Windows XP, 2000, Vista and 2003.

"Scancode Map" is a registry binary value with the following format (each value is a 32-bit integer in little-endian order):

<00000000> <00000000> <NumberFollowingIntegers> <Mapping1> <Mapping2> ... <00000000>

A mapping consists of two 16-bit scancodes. The second scancode (high word) from the keyboard is replaced with the first scancode (low word). Some relevant scancodes:

0x01 Esc
0x1D L-Ctrl
0x38 L-Alt
0x3A CapsLock
0x46 ScrollLock

For example, the following line:

"Scancode Map"=hex:00,00,00,00,00,00,00,00,02,00,00,00,01,00,3a,00,00,00,00,00

consists of one mapping (01,00,3a,00) which replaces the scancode 0x003a with 0x0001. That means that pressing CapsLock (0x3a) will generate Escape (0x01).

Utilities

This section is for other Windows utilities relevant to mapping keys. Brief notes on other useful utilities are in the tip.

  • On Windows XP, and possibly other versions, a resource kit utility named remapkey.exe provides a GUI to create needed registry entries to remap keys.
  • KeyTweak is a free program that automates changing the registry to map keys.
  • Ctrl2cap from Sysinternals is a kernel-mode driver to perform keyboard input filtering to turn CapsLock into LeftCtrl.

Comments

Or instead:

Use <CTRL-[> to generate an escape sequence. Mapping the escape key to the CAPS-LOCK is simply counter-productive on windows since the CTRL key is used all the time: see copy and paste. It is FAR more useful to have the caps key be a control key. Vim users can find this tip on the vim tips section at vim.org which I wrote many years ago. Not sure why somebody felt the need to blow away that tip here.

There is a reason why original UNIX keyboards have the CONTROL key in that spot.

Which tip got "blown away"? All tips of the kind you mentioned have been merged to 285: Avoid the escape key. Some of these titles have been kept as redirects, some have not. John and I are in slight disagreement as to whether or not to keep old titles around (my opinion is "yes, yes, yes") whereas he likes to cull the less useful titles so yours may have been the victim of a less-than-stellar title. If you want, recreate the page as a redirect to Avoid the escape key by making a page of the correct title with content, #REDIRECT [[Avoid the escape key]]. Or respond here with the old title and I'll do it.
This reminds me of another reason I've had but never mentioned for keeping titles around. In my experience (and I assume other people's as well), an editor may create a page on a wiki, but not really check on the wiki or become very active. But, that's "their" page (no, it doesn't really belong to anyone, but a lot of effort went into crafting it so there is some sense of ownership) and they will check on it from time to time. If they don't check often enough, or don't understand the wiki policies or culture, they may miss the notice that the page is being merged/deleted. So they go to check on it later, see it's deleted, and the only thought is "those jerks deleted MY page for no good reason!" This is probably less important than preventing link rot, but I'm sure it turns off a user or two from time to time. I didn't contribute to wikipedia for a long time after my first article, "Grancrete", got deleted because it looked like a corporate promotion of a product (it wasn't, I did it in good faith after seeing an article on a news site and thinking it was pretty cool). Had I been involved in the community, I may have noticed the discussion going on about the new page and argued against deletion (or maybe not considering the size of wikipedia), but I wasn't so I never had the chance.
Anyway, sorry your tip got deleted. John and I have sort of met in the middle as far as keeping titles go, so I'll probably continue to let him delete some titles I think shouldn't be, he'll continue to keep some titles as redirects to merged content, and I'll continue to restore pages as redirects if someone notices and complains.
--Fritzophrenic 17:19, 31 July 2009 (UTC)

I have edited the tip so the introductory section makes it clear that VimTip285 is probably a better choice for avoiding the escape key (the suggestion about using Ctrl-[ for Esc is the first item at 285). In the 1250 tips imported from vim.org in July 2007, there were many tips and comments with advice (often conflicting) re Esc + Ctrl + CapsLock. It was scattered over more than ten pages, and was very hard to find and difficult to read. I think it's much better to have the advice condensed and cleaned, resulting in VimTip285 to avoid the escape key, which starts with links to this tip for maps to change key layout for Windows, and a link to VimTip166 for similar info for Unix.

Originally it was planned that vim.org would maintain the old tips indefinitely (but changes were disabled to prevent spam). However, the vim.org system crashed with a database corruption (a year ago?) and Bram decided that it was too hard to resurrect the tips. Therefore, there are no tips on vim.org now.

Since it was never possible to edit text at vim.org, a large majority of the imported tips were in a shocking state. Some tips were simply wrong, others obsolete (not applicable to Vim 7), many misguided, and most had contradictory advice (often a tip would have some script, and the comments would have several attempts by various people to correct bugs, or to improve the script). A fantastically large amount of work has been done here to correct many of these problems, and there may be some unfortunate consequences such as original tip authors not being able to find their work.

Please note that we regard comments as temporary, and all discussions such as this one will be deleted in due course (after a week or two). That does not apply to user talk pages, but it does apply to tips and their talk pages because we want to present simple-to-follow text and don't have the contributors to justify talk pages. I'm just warning you that this discussion is also likely to be cleaned away. JohnBeckett 00:40, 1 August 2009 (UTC)

Windows up until XP, and Vista (I think) do not have a nice UI for changing the mappings of the keyboard. Over the years that I have been using vim, every time I installed or re-installed Windows, one of my first stops has always been to install vim and then map the CAPS key to the control key and make the old control key the CAPS key.
On Linux/BSD/... these things are a small afterthoughts no doubt. The original realization that you could actually do this on Windows, however, was life changing for me as far as vim on Windows is concerned. Anyways, long story short: I would periodically go back to the vim site and dig up my old tip. It's the kind of thing you do and forget about for the next three years.
I made the original title so that it would be easy to search for: Windows, Registry and CAPS. Perhaps my tip should have also included the way to avoid using the escape key, but in the end I noticed somebody else had already written one.
So the registry information is useful to I think. I still occasionally (every few years or so) have needed to dig it up. Where should I place it?
-- Jacques