What approach would be preferred to allow a cmd-s to trigger a save, regardless of mode:

" Allow i,c to call normal mode
noremap  <leader>S    :silent call SaveFile()<CR>asdfidfo
inoremap <leader>S    <C-O><leader>S
cnoremap <leader>S    <C-c><leader>S

Or, everyone for themselves:

noremap  <leader>S         :silent call SaveFile()<CR>
inoremap <leader>S    <C-o>:silent call SaveFile()<CR>
cnoremap <leader>S    <C-c>:silent call SaveFile()<CR>

Why would one approach be preferred over another?


If it's a very personal, mapping I'd go with either solution 2,

" For instance I have
nnoremap <silent> <C-s> :<c-u>update<CR>
inoremap <silent> <C-s> <c-o>:update<CR>
vnoremap <silent> <C-s> <c-c>:update<CR>gv

or use non-nore mappings (corrected solution 1).

nnoremap <silent> <C-s> :<c-u>update<CR>
imap     <silent> <C-s> <c-o><c-s>
vmap     <silent> <C-s> <c-c><c-s>gv

BTW, the visual mappings are incorrect, and normal mode will need to clear possible counts.

For distributed pluggins, I use plug-mappings and I even define helper functions and commands to define several mappings (and menus) at once.

| improve this answer | |

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.