2

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?

aszswaz
  • 277

2 Answers2

2

: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.

romainl
  • 23,415
-1

I managed to add a shortcut to apply changes with Ctrl + S, I leave my config in case it helps

enter image description here

Greenonline
  • 2,390