0

I want to configure a shortcut key that can be used in both edit mode and normal mode, usually two commands are required:

:nnoremap <C-s> :w<cr>
:inoremap <C-s> <esc>:w<cr>a

Is there any way to combine them into one instruction that can act on multiple modes at the same time?

1
  • "Compile mode"?
    – romainl
    Jan 31 at 21:06

1 Answer 1

0

:help map-table:

         Mode  | Norm | Ins | Cmd | Vis | Sel | Opr | Term | Lang |
Command        +------+-----+-----+-----+-----+-----+------+------+
[nore]map      | yes  |  -  |  -  | yes | yes | yes |  -   |  -   |
n[nore]map     | yes  |  -  |  -  |  -  |  -  |  -  |  -   |  -   |
[nore]map!     |  -   | yes | yes |  -  |  -  |  -  |  -   |  -   |
i[nore]map     |  -   | yes |  -  |  -  |  -  |  -  |  -   |  -   |
c[nore]map     |  -   |  -  | yes |  -  |  -  |  -  |  -   |  -   |
v[nore]map     |  -   |  -  |  -  | yes | yes |  -  |  -   |  -   |
x[nore]map     |  -   |  -  |  -  | yes |  -  |  -  |  -   |  -   |
s[nore]map     |  -   |  -  |  -  |  -  | yes |  -  |  -   |  -   |
o[nore]map     |  -   |  -  |  -  |  -  |  -  | yes |  -   |  -   |
t[nore]map     |  -   |  -  |  -  |  -  |  -  |  -  | yes  |  -   |
l[nore]map     |  -   | yes | yes |  -  |  -  |  -  |  -   | yes  |

shows that Vim has *map commands that cover more than one mode but it doesn't a have one that covers all modes. You can thus cover all modes with:

  • :map,
  • :map!,
  • :tmap,
  • :lmap,

and you must use two :*map commands for normal mode and insert mode.

But the RHS of your two mappings are not identical so, even if such a :*map command existed, you couldn't use it anyway.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.