Mapping `ALT + m` to `Esc` in Vim - vim

I'm trying to map ALT+m to Esc in Vim, to exit insert mode. I've tried with:
map <A-m> <Esc>
but it is not working as expected (i.e. it exits insert mode, but the next key pressed is ignored). That's because, apart from exiting insert mode, m gets "pressed" or executed as well (i.e. if i remap ALT+j to Esc instead, then apart from exiting insert mode, it will jump to the next line).
Is there any way to map ALT+m to Esc in insert mode without having other side-effects? (avoiding to execute m after exiting insert mode)
Using Fedora 21 (GNU/Linux distribution), with GNOME Terminal 3.14.3 and VIM - Vi IMproved 7.4.

inoremap <Esc>m <Esc>

Related

How do I get the google cloud shell to recognize the Esc key correctly in vim

The Esc key is heavily used in vim to get back to normal mode from insert, command or visual mode. When you press the Esc key inside vim on the cloud shell the cursor changes shape and vim blocks. If you continually press on Esc key or if you click on the cursor itself then vim works again.
I am in the habit of using the Esc key for changing back to normal in vim and so this makes using vim on the cloud shell very painful.
I do not have to use the Esc key (I can use Ctrl+c or Ctrl+[ and that works except that the banner prompt still claims vim is in INSERT mode when it has switched to NORMAL mode) but it is hard to change my habits.
vim cursor in INSERT mode just before pressing Esc key
vim cursor becomes hollowed out just after Esc is pressed but still in INSERT mode
NORMAL mode can be obtained by pressing Esc two or three more times and waiting
I have investigated remapping the Esc key inside vim but this messes up vim and I get strange behaviour (see warning not to change Esc key mapping in How to disable Esc and cursor keys in vim).
The backspace key does not work in vim either but that can be fixed inside .vimrc with:
inoremap <bs> <left><del>
If there is no fix for the Esc key mapping then I will have to force myself to learn not to use the Esc key.
The best alternative to the Esc key on the cloud shell seems to be Alt+Space - as that invokes a return to NORMAL mode and switches off the --INSERT mode message on the bottom too.
You'll have to hit escape twice (quickly) to enter ESC mode.

Can I auto-exit Insert mode when saving in MacVim?

I would like to be able to setup MacVim so that it switches back to Normal mode after saving a buffer. For example: lets say I am adding some text in Insert mode and I hit "Command + S" to save, I would like to be in Normal mode after the save operation has completed.
Is this possible?
Note: Incase the above is unclear, I do not want to spend more time in Insert mode, but less. I would like to exit Insert mode automatically upon save.
Adding the following lines to your .gvimrc will disable MacVim's [Cmd + S] shortcut, and switch the mode back to Normal before saving.
It will also block Vim from entering Insert mode when hitting [Cmd] + [S] keys (as this would have activated the substitute command). Note: you will still be able to substitute hitting the [S] key as usual.
" Disable MacVim save shortcut
macmenu File.Save key=<nop>
" Exit to Normal mode upon [Cmd+S]
inoremap <D-s> <Esc>:w<CR><Right>
vnoremap <D-s> <Esc>:w<CR>
" Save in Normal mode (block Substitute)
nnoremap <D-s> :w<CR>
Thanks to #Amadan for pointing me in the right direction.
Wanting to typically be in insert mode is using Vim wrong. If it works for you, that's fine; but you will never reach the potential of Vim while sticking to that habit; might as well use Notepad++/SublimeText3/...
If you really really want it, you can have something like :inoremap <C-s> <C-o>:w<CR> to save and stay in insert mode, or :inoremap <C-s> <Esc>:w<CR> to save and move to normal mode. (It will work only on graphical Vim, as terminal Vim typically won't ever receive Ctrl-S.)

Vim EasyMotion: Insert mode after movement?

I have remapped the EasyMotion commands ,,w and ,,b with the following:
imap ,w <ESC><leader><leader>w
imap ,b <ESC><leader><leader>b
This way i'm able to use EasyMotion in Insert mode and navigate quickly without entering Normal mode.
Though, after the move, Vim stays in Normal mode (naturally). How can I specify that after EasyMotion's
employment, Vim should enter Insert mode, in order to continue typing without delay?
Thanx!
You can use <C-o> to execute one normal mode command from insert mode. Once this command has been executed, you will be returned to insert mode:
imap ,w <C-o><leader><leader>w
imap ,b <C-o><leader><leader>b

How to let vim keep in insert mode when pressing Alt - h to move in insert mode?

In order to edit fast in insert mode, we can use mapping keys to navigate in insert mode, for example
:inoremap <A-h> <Left>
with this mapping, user can press Alt + h in insert mode to let the cursor move left and then do insert, we don't need to exit edit mode, then move cursor. this will save some time for us, my question is when I use this mapping key, the cursor moves correctly, but vim switch to normal move after moving, it should keep in insert mode, I use vim 7.3 in Sun OS. I tried this in gvim 7.3 on windows, everything is good, so I wondered is there anything i lost?
First of all: if you think navigation in insert mode is speeding up your vim, you're using it wrong (i.e. like any other non-modal editor, when its biggest benefit is specifically modality).
That said, we can't say too much without you showing us your mapping. I suspect it is something like this:
inoremap <M-H> <Esc>h
Try changing to
inoremap <M-H> <C-O>h
I got the answer here, http://vim.wikia.com/wiki/Fix_meta-keys_that_break_out_of_Insert_mode, this will happened on Unix or Putty.

Vim insert mode: unambiguous key binding that always works as expected?

Background:
Sometimes when editing in vim it is possible to have extra characters in a file that the user did not expect to be there because he was in "insert mode" when in a hurry and rushing to get something finished.
Fortunately, even if the user is rushing, pressing ESC a couple of times is always sufficient to get them out of insert mode and into normal mode, with no surprises.
Question:
Is there a key binding that works the same way for insert mode? Pressing "i" can get you into insert mode, but if you press it multiple times, you will start inserting the letter "i" into the file.
Goal:
The goal is to have some key binding for getting back into insert mode that the user can even press multiple times with eyes closed, and still not worry about "surprises" of unexpected characters being put into the file.
<C-o>i should do the trick. <C-o> gets you temporarily to normal mode, but for only one command, if that command is "go to insert mode" than well, you simply return there.
Edit: I could reproduce your error message now, and it seems the easiest thing to do is this:
:nmap <C-i> i
:imap <C-i> <C-o>i
If do not map <C-i> in insert mode, but in normal mode only, then repeatedly hitting <C-i> will be idempotent.
Thanks to Benoit for mentioning that <C-i> inserts a tab in insert mode.
You should do a mapping that behaves differently in the distinct modes:
:inoremap <F1> <NOP>
:nnoremap <F1> i
:vnoremap <F1> <esc>i
:cnoremap <F1> <C-C>i
:onoremap <F1> <esc>i
Hitting F1 will go to insert mode then.
You can also toggle the 'insertmode' setting (:set insertmode): in this mode, the Insert mode is the default mode (to which you switch with Escape, and you go to normal mode with CTRL-L.
The answer given by bitmask works, but it apparently has the side-effect of producing the error message:
E37: No write since last change (add ! to override)
Unless you have configured your vimrc to turn that message off.
But another alternative that seems to work without producing error messages:
CTRL-C i
Which seems to work on standard vim.

Resources