I'm trying to make it so I can write a buffer to disk with one keystroke.

(Side note: ideally, I'd like this to work in all modes, but for the moment as a start I'm just trying to get it to work in normal mode.)

On the Vim wiki it says...

Vim supports representing control characters using symbolic notation like <F1>, <C-W>, <C-S-F1>, etc.

And also...

A key with the Ctrl key modifier is represented using the <C-key> notation. For example Ctrl-R is represented using <C-R>. A key with the Shift key modifier is represented using the <S-key> notation. For example Shift-F2 is represented using <S-F2>. A key with the Alt key modifier is represented using <A-key> or <M-key> notation. You can combine one or more key modifiers. For example, to represent Ctrl+Shift+F3 you can use <C-S-F3>.

That seems to be saying that if I put this in my .vimrc it should work...

 nnoremap <S-C-k> :w<CR>

But it has no effect. When I reload .vimrc and press shift+control+K no [File] written message appears in the bottom area.

I also tried this one but then option+K had no effect either...

 nnoremap <M-k> :w<CR>

No error messages.

I'm on OS X.


Ok I just tried this...

inoremap <M-s> Hey whats up

Then when I go into insert mode and press option+S, Vim outputs...


Is OS X intercepting my keystrokes before Vim even receives them? Is that why this isn't working?

If so, is there a way to make it stop doing that other than buying a different computer?


Your keyboard response can be different than you expect. For e.g. it can provide some special characters of your language.

To check out what your system does by pressing any combination:

ctrl+v in insert mode and then option+k or alt+k

Use the output symbol in your vimrc mapping instead of <M-k>

WARNING: this method is rough - symbols depend on system, terminal ect. So you have to put in your .vimrc conditions like:

if has("gui_running")
    if has("x11")
    if has("gui_gtk2")

or to detect systems (OS X) like here


Change it to <C-S-k>. It works fine for me. You can give some other key also, like <F10> for :wq!

:map <F10> :wq!<CR>
  • S-C-k also works for me in nnoremap mode.
    – SibiCoder
    May 9 '16 at 11:58
  • Which OS and terminal?
    – Tom Hale
    Aug 3 '16 at 4:44
  • Linux and vim 7.2
    – SibiCoder
    Aug 3 '16 at 5:47

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.