How to get Vim to never insert escape codes
If I am in insert mode and hit C-l (which clears my search in normal mode), Vim inserts ^L into the buffer. I never want this behavior. How do I disable it? I don't want to mapi every possible command, I just don't want garbage inserted every time I make a mista开发者_运维问答ke.
If you're having problems with a particular Ctrl combination in insert mode, you can always turn it off:
:imap ^L <Nop>
Here Nop is "no operation".
If it's frustrating you, I'd recommend turning it off while trying stop the habit. It probably acts as some kind of reinforcement every time you see the ^L and think "D'oh I've done that again".
Having said that, in insert mode there are lots of really useful Ctrl combination that you can use to do useful operations with, so I wouldn't recommend turning them all off.
Ctrl-L (and Ctrl-Z for that matter), are really useful keys to remap to something you find useful. They're really only used when you make insert mode the default mode, rather than normal mode - see :h insertmode
Ctrl-L is also really nice to remap as it's easy to press being on the home row and it remapping it shouldn't interfere with anything.
Using it for something that you find useful will build up muscle memory and should stop you pressing it by accident.
So why don't you
:inoremap <C-l> <C-o><C-l>
and be a happy chappy? C-o temporarily 'suspends' insert mode, so you can do 'normal mode' command without actually leaving insert mode.
Highly underrated
:he <C-o>
:wq
精彩评论