8

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.


UPDATE

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?

6
  • 5
    Note that mapping Control + Shift + key separate from Control + key doesn't work. See: Can I map a Ctrl + upper-case letter separately from Ctrl + lower-case letter? (keys like F1 are special cases). That being said, the mapping looks fine. Which Vim are using? MacVim? Mar 6, 2016 at 18:20
  • Ok, thanks for letting me know. I'll try using <M> instead of <S-C>. I'm not using MacVim. I'm using regular Vim 7.4.1129 installed via MacPorts.
    – Ethan
    Mar 6, 2016 at 18:38
  • 1
    Also asked on Stack Overflow Mar 7, 2016 at 17:25
  • 4
    OS X will interpret Option-S as ß. To map it in Vim, you need to do :inoremap ß Hey whats up.
    – Amadan
    Mar 8, 2016 at 5:03
  • 1
    <S-C-k> is three keystrokes. Just sayin'.
    – Antony
    Aug 4, 2016 at 19:53

2 Answers 2

1

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")
        <map_command_here>
    if has("gui_gtk2")
        <map_command_here>

or to detect systems (OS X) like here

0

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>
3
  • S-C-k also works for me in nnoremap mode.
    – SibiCoder
    May 9, 2016 at 11:58
  • Which OS and terminal?
    – Tom Hale
    Aug 3, 2016 at 4:44
  • Linux and vim 7.2
    – SibiCoder
    Aug 3, 2016 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.