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 ?

statox
  • 49,782
  • 19
  • 148
  • 225
Alex
  • 1,205
  • 2
  • 10
  • 12

1 Answers1

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

statox
  • 49,782
  • 19
  • 148
  • 225