7

I found that it's really hard for me to hit Control and other keys simultaneously, and I discovered that the space key is rarely used, so I decided to map it to Control . Thus, when I want to hit Control+ f for scrolling, I can instead hit space+ f, which would be a lot easier. But with this line

nnoremap <Space> <C> 

nothing change.

How can I do that? Is it possible?

By the way, is it a good practice to map Space to Control ?

4
  • 3
    <CR> is Enter, not Control ... and I think you will need to remap Ctrl to Space at OS level. Commented Jul 24, 2015 at 23:08
  • oh…i think i mistake one for another Commented Jul 24, 2015 at 23:13
  • @VanLaser But,even when I change the <CR> to <C>, it still doesn't work. Why? Commented Jul 24, 2015 at 23:30
  • 6
    Because ctrl key by itself cannot be mapped in vim. It has to be in conjunction with another letter eg. <C-e>. You will have to remap it at OS level, like @VanLaser said. Commented Jul 25, 2015 at 1:13

1 Answer 1

5

Unfortunately I think that the comment of EvergreenTree is right: you can't map ctrl as a single key into vim.

Also I tried to get what you want using the langmap option which allows to substitute a key with another one in normal mode. I thought something like set langmap +=\ ^ could have worked but it doesn't (with that, Space get your cursor at the beginning of the line).

So the best I could suggest to you is to add the following lines to your .vimrc:

function! RemapSpaceToCtrl() for l:char in range(97, 122) let l:char = nr2char(l:char) execute 'nnoremap <silent> <Space>' . l:char . ' <C-' . l:char . '><CR>' endfor endfunction call RemapSpaceToCtrl() 

The function maps <Space>X to <C-X> where X is all the letters of the alphabet. This way Space + a increments a number, Space + f goes down one page etc...

That's probably not the cleanest solution and you might want to improve it but that could be a workaround.

To render unto Caesar the things which are Caesar's I get inspiration to map a prefix followed by different letters to another prefix followed by the letters from a function written by CarpetSmoker here

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.