Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mapping function keys in insert mode

Tags:

vim

I"m trying to map my compile and run commands to F5, It works fine in normal mode with the following:

nmap <F5> :<C-U>make<CR>:!%:r.exe<CR>:redraw<CR>

but when I try to do the same in insert mode:

imap <F5> :<C-U>make<CR>:!%:r.exe<CR>:redraw<CR>

It just prints out the characters F5 into my source code.

Is there a way I can have it work in both modes?

like image 534
teknix Avatar asked Dec 08 '12 14:12

teknix


People also ask

How do I navigate in vim insert mode?

Vim does have some keybindings to navigate in insert mode. Check :h ins-special-keys . ctrl-h : backspace, ctrl-w : delete word, ctrl-u : delete to beginning of line, alt-b : go back a word.

What is insert mode in Vimium?

The use case of insert mode (entered while pressing i ) is documented in the README: > i enter insert mode -- all commands will be ignored until you hit Esc to exit. This may be useful to temporarily disable keybinds so it does not conflict with webpages implementing their owns.


1 Answers

How about this:

imap <F5> <Esc>:<C-U>make<CR>:!%:r.exe<CR>:redraw<CR>i

So it switches into normal mode and then back again.

like image 95
Matthew Strawbridge Avatar answered Oct 03 '22 06:10

Matthew Strawbridge