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?
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With