Original
nnoremap <F2> :w<CR> inoremap <F2> <Esc>:w<CR>a
map sometimes does not set it for all modes. I do not know the exact reason, therefore, to be sure that I want to explicitly set the entire mapping to my configuration file. I suggest you do the same thing as when you can get something unexpected due to different modes. Therefore, it is important to carefully monitor each reassignment that you do for each particular mode.
Also, use the *noremap instead of everything *map wherever you can, since recursive mapping is a known source of errors, especially for beginners.
Finally, I don’t know what you are trying to achieve by attaching a file record in visual mode. Are you aiming for a partial write to the buffer (this is when you selected something in visual mode, and then click this shortcut to write files and only the selected text)? Or do you want the whole file to be recorded when you are in visual mode, regardless of whether you have selected something or not when you click on the shortcut to save the files? Provide more information about this. Personally, in any case, this is a strange display for the visual mode, because for this it really does not back down. It is much better to store such things in normal mode.
Update
Since others have already given comprehensive answers to your question, I just thought it would be useful to add my 2 cents, but in a slightly different direction. If you look at what you are trying to do, namely display navigation functions using the arrow keys in insert mode, I can conclude that you are very new to Vim. As you probably already know, the philosophy of Vim is that you should never ever touch the mouse while working inside Vim - call it a kind of golden rule .
Now I want to point out what I call the silver rule , and it basically looks like this:
noremap <Up> <Nop> noremap <Down> <Nop> noremap <Left> <Nop> noremap <Right> <Nop> inoremap <Up> <Nop> inoremap <Down> <Nop> inoremap <Left> <Nop> inoremap <Right> <Nop>
In other words, disable the use of the arrow keys (everywhere except in command line mode). Your fingers should always be in the symbol area only. Wim is all about modes. The insert mode is not intended for navigation - it is intended for input bursts . When you work with code or just with text (it doesn’t matter), you spend most of your time in normal mode - navigation - browse the file, looking for where to land nearby to edit something, add something, i.e. make the next next input packet for which you switch to insert mode, and when you are done, you will return to normal mode to find some more meat - like a predator . :)
So what's the deal? I just want to direct you in the right direction from the very beginning. Thus, you can become an intermediate user of Vim very quickly - just a few days. To better understand all of the above, I suggest you definitely watch the Vim Novice Video Tutorials from Derek Wyeth, where he talks about all these things in more detail and shows him in action in the screenshots. There are also Intermediate and Advanced study guides of it, which you can also see at your convenience.
I wish you happiness!:)