6

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 ?

  • 3
    <CR> is Enter, not Control ... and I think you will need to remap Ctrl to Space at OS level. – VanLaser Jul 24 '15 at 23:08
  • oh…i think i mistake one for another – Alex Jul 24 '15 at 23:13
  • @VanLaser But,even when I change the <CR> to <C>, it still doesn't work. Why? – Alex Jul 24 '15 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. – EvergreenTree Jul 25 '15 at 1:13
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.