Solved

remap keys in vim

Posted on 2011-01-12
12
792 Views
Last Modified: 2012-05-10
Hello,

could you advise me how to remap the keys in vim editor in the following way?
1) caps lock should be instead of escape and vice versa
2) I don't want to press : before I enter some command. Instead of : I'd like to use quickly twice caps lock
or quickly twice space bar or shift (similar as you type dd when you want to delete a line)

thank you
0
Comment
Question by:xRalf
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
12 Comments
 
LVL 2

Expert Comment

by:JustinDavidow
ID: 34537896
AFAIK unfortunately, caps lock is not really a key, it's a key modifier.  as such you won't get a response from "double tapping" they key.
0
 
LVL 6

Author Comment

by:xRalf
ID: 34537957
I'd like to remap it so escape would be the key modifier and caps lock will have the functions as escape before. I heard that it's possible, but the discussion from that time was deleted.
0
 
LVL 13

Expert Comment

by:Superdave
ID: 34540729
It's possible to do that with xmodmap, but it is not possible within vim.
0
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
LVL 13

Assisted Solution

by:Superdave
Superdave earned 500 total points
ID: 34540791
For switching the keys try putting this in a file and running xmodmap on it:

remove Lock = Caps_Lock
keycode   9 = Caps_Lock
keycode  37 = Escape
add Lock = Caps_Lock


I don't think there is an easy way to assign a key to hitting a key twice fast.

This is for X Windows; if you want to do the same in the console you'd use loadkeys.
If you wanted to do the same in MS Windows there is a way to do it by setting registry keys.


0
 
LVL 13

Assisted Solution

by:Superdave
Superdave earned 500 total points
ID: 34541770
Sorry, I think it should be 66 instead of 37 above for the Caps Lock key.  I already remap my own keys so I got myself confused experimenting with it.
0
 
LVL 6

Author Comment

by:xRalf
ID: 34542207
No problem,

if it's done globally in all operating system it's even better.

In vim, I'd like to replace the pressing of : for something convenient. Would it be problem to use spacebar? There should be no collisions with usefull keys and it should be easily pressable.
0
 
LVL 6

Author Comment

by:xRalf
ID: 34542223
I ran xmodmap on the file
remove Lock = Caps_Lock
keycode   9 = Caps_Lock
keycode  37 = Escape
add Lock = Caps_Lock

but now in vim does not work escape and caps lock
0
 
LVL 13

Expert Comment

by:Superdave
ID: 34546144
Try the same but use 66 instead of 37; I copied the wrong line.  Restart X-Windows first if it's still messed up.

You could always change the ":" to " " in the Vim source code and recompile it.
0
 
LVL 6

Author Comment

by:xRalf
ID: 34546522
Thanks, with 37 it works (I overlooked it).
Recompilation could be solution, but
1) There should be no collisions with usefull keys and it should be easily pressable.
2) I haven't done this before. So it's quite possible that I won't have happy end. Could you navigate me, what do download, commands to use and what to edit? Isn't there easier solution with editing something in .vimrc?
0
 
LVL 13

Expert Comment

by:Superdave
ID: 34549379
It should normally be possible to do something like that in .vimrc, but I couldn't figure out a way syntactically to specify a :map command to map space because it treats a space as whitespace and ignores it.  I had no luck trying to escape it with quotes, backslash or ^V.  There could be a way but I don't know what it is.

I just downloaded the Vim source; I'll take a look at it later tonight.
0
 
LVL 13

Accepted Solution

by:
Superdave earned 500 total points
ID: 34554557
Aha!  I found it; just add to your .vimrc:

map <Space> :


The <Space> is typed literally just like that with the angle-brackets and word Space.
0
 
LVL 6

Author Comment

by:xRalf
ID: 34578534
That's great, thank you.

If you would now please write me how to do it, to make the settings with xmodmap durable (after restart). Now I have to run xmonmap file.txt/
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question