Having used text editors (mainly Notepad/++) and some IDEs on MS Windows, I've become familiar with their Alt and Ctrl shortcuts to the point that I use them automatically. Having used nano
on a GNU/Linux machine for many years, I tend to automatically use its Ctrl key shortcuts (particularly ^O
and ^X
as nano
represents them) when editing text in either nano
or insert mode in vim
. Consequently, text I type in vim
tends to be littered with ^S
and ^O
, instead of actually saving (writing out the buffer to file) at that point. (It seems to me that <C-s>
currently isn't mapped to anything, despite the fact that some terminals use it for a special purpose.)
To stop that happening, I'd like to create the following mappings in ~/.vimrc
, but my efforts so far result in vim
issuing a warning about not finding a mapping (because I'm clearly doing it wrong):
<C-s>
to map to "in INSERT MODE,press <ESC>
to enter NORMAL MODE;type ':w';<Enter>
and return to INSERT MODE to append text"<C-o>
(letter O, not zero) to do the same. (It seemsvim
has already mapped this to<Esc>
.)- If I can't use
<C-s>
or<C-o>
, then use<F2>
. <Alt-X>
(or<Alt-F>X
) to map to "In INSERT MODE,press <ESC>
to enter NORMAL MODE;type ':q';<Enter>
"<C-x>
to do the same as above.
What I have is this: imap <C-s>=<C-[>:w<Enter>a
(or inoremap <C-S> <Esc>:w<CR>a
)
Even if I precede <C-[>
with <C-V>
, pressing <C-s>
results in ^S
being typed instead of saving the file.
I have read the Mapping Keys in Vim tutorial on Vim Tips, but I haven't gleaned anything helpful from it. (I'm not sure whether I need to include the =
, type
or press
instructions.) I've yet to try the solution proposed to this question that seems to describe the issue I'm facing (because it's not clear if it resolves the issue).
I don't want to read two books (one on vim
itself and another on VimScript) just to be able to create shortcuts for common commands that require a few more keystrokes. (The irony of typing all this here instead of just getting on with using colon commands is not lost on me.)
In case it makes a difference, I'm using vim
8.2.1847 on Ubuntu 22.04 running through WSL.
vimtutor
should be enough to get you started.