You can use the following mappings:
inoremap <left> <esc><left>
inoremap <right> <esc><right>
inoremap <up> <esc><up>
inoremap <down> <esc><down>
inoremap <PageUp> <esc><<PageUp>
inoremap <PageDown> <esc><PageDown>
Or just for fun:
let escapeInsertModeKeys = [ '<left>', '<right>', '<up>', '<down>', '<PageUp>', '<PageDown>']
for key in escapeInsertModeKeys
execute 'inoremap ' . key . ' <Esc>' . key
endfor
However I think what you are describing is a sign that you didn't grok Vim. To make the best out of Vim you are supposed to spend most of your time in normal mode. You should only be in insert mode when you actually need to type some characters in your buffer. After each edit you should go back to normal mode: That will allow you to have a better undo history (so that u
and ctrl-r
and the dot command work really efficiently) as well as a better navigation thanks to all the available motions in normal mode.
So my advice would be not to use these mappings but instead force yourself to leave insert mode as often as possible.
This is also why some people remap <CapsLock>
to <Esc>
(not in Vim, at the OS level) or use mappings like the following: To make it easier to switch from insert mode to normal mode
" Switch to normal mode when you type jk in a buffer
inoremap <silent> jk <Esc>
it's forgotten which mode Vim was left in
It is helpful to have some visual indicator to indicate which mode Vim is in. Do you have, for example,--INSERT--
at the bottom left corner; Or does the cursor change it's appearance when you're in insert mode?:help guicursor
.--INSERT--
or something similar. But I find my brain is not thinking about the indicator. It's thinking about a bug, or feature request, or ... Maybe a different color or something would work better for me.