Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Map space key to go into insert mode

Tags:

vim

I am trying to map my space key to make the Vim go into insert mode from normal mode.

The reason I want to do this is because sometimes I forget that I'm in normal mode and start typing as if I'm in insert mode. When I press the space key in between or even in the start of the page, it moves down and something or the other types due to the possibility of a press a or i in what I just typed.

So to avoid this I want to map my space key to insert mode from normal mode as we press i to do so.

I tried the following:

map space :i
map <space> :i

But these doesnt seem to work.

like image 460
Kumar Alok Avatar asked Feb 27 '13 11:02

Kumar Alok


2 Answers

You're mixing up the modes in your mappings; that's an important concept in Vim. Though there's a :startinsert Ex command in Vim (where your mapping would indeed start with a :), it's more straightforward to use the normal mode i command:

:nnoremap <Space> i

You only want a normal mode mapping here, so :nmap, not :map; cp. :help map-modes. And see :help key-notation for why it's written <Space>.

Finally: You should always use :noremap; it makes the mapping immune to remapping and recursion.

like image 64
Ingo Karkat Avatar answered Oct 18 '22 20:10

Ingo Karkat


strange requirement, but, you have your reason. :)

try this line out:

nnoremap <space> i
like image 41
Kent Avatar answered Oct 18 '22 18:10

Kent