Underlying Concept Behind Keyboard Mappings

2

I am frustrated with key mapping issues.

On my Linux box, if I type Home/End in Vim, then the cursor actually moves to the beginning/end of the line. On my Mac when I am on TextEdit, if I do Fn + Left or Fn + Right, it takes me to beginning/end of the line.

But if I am on Vim on my Mac terminal, then the same key combinations don't work. Why? I see online all the different cryptic settings that I have to paste in .vimrc to make this work, but I can't find any explanation for those cryptic map, imap settings.

What is the underlying issue here, and how can I fix it?

Thanks!

user855

Posted 2013-11-05T05:40:04.933

Reputation: 163

I don't use Vim or Mac, but if your Vim configuration includes keybindings (such as Home,End,etc.), you will need to make sure that inputs from both types of terminal are accounted for. Running just cat (Ctrl-C to terminate) and typing the key combinations might help you in viewing the differences in how both terminals see the keys. – bitflips – 2013-11-05T06:16:50.057

Answers

0

(this was supposed to be a comment, but I ran out of space)

I'd guess a significant part of the difference between the linux way of doing things, and the OS X way of doing things is that your traditional *nix box, and most regular keyboards don't predictably have fn keys, so designing a keymap that assumes so wouldn't make sense.

Vim has its own, old school unix keybindings you can modify, so uses the old, reliable way linux and most classic unixes use.

Apple controls all aspects of mac hardware so, they can reliably assume fn is there. TextEdit is OS X only, and well the home as go to the top of the line option is an os x ism. The fn left/right key for start/end is probably a workaround for it. You can always change ~/Library/KeyBindings/DefaultKeyBinding.dict to get textedit and other apple flavoured applications to work consistantly with other unix flacoured applications.

Interestingly, there's nothing on this in the OS X human interface articles, so its pretty hard to guess what apple was thinking doing this.

Journeyman Geek

Posted 2013-11-05T05:40:04.933

Reputation: 119 122

Whether a keyboard has an Fn key or not isn't really material here. That key just happens to be part of how you hit Home and the like on a smaller-size Mac keyboard. Nothing to do with Unix tradition vs. Apple innovation. – echristopherson – 2013-11-05T07:06:32.650

Well, I haven't seen fn left and right working that way on other laptops. On the other hand, apple hasn't said anything about it, and it seems unique to OS X from my sources. I wouldn't mind (nay!, I'd bounty) a proper definitive answer on the subject – Journeyman Geek – 2013-11-05T08:41:01.767

0

Vim responds to the keycode associated with <End>. Since there's no <End> key on your Macbook's keyboard, that keycode has to be emulated in some way: via fn+right. That combination works in Macvim so, if you use Vim in a terminal, chances are that it's interrupting that combination before Vim gets a chance to receive it.

If you used a real keyboard, you wouldn't have any reason to complain: Vim gets <End> and <Home> perfectly without anything to do.

romainl

Posted 2013-11-05T05:40:04.933

Reputation: 19 227

0

I'm not sure if I answer :

There is already a key mapping for this in vim :

In normal mode, press ^ to go at the beginning, and $ to go at the end (think about regex)

If you want to go in insert mode at the beginning of line, type I (Insert)

If you want to go in insert mode at the end of line, type A (Append)

Hettomei

Posted 2013-11-05T05:40:04.933

Reputation: 182

In insert mode, if I type "I", it just types "I" and does not go to beginning of line. – user855 – 2013-11-07T04:47:18.840

You use a knife to cut, not to make holes, use vim as it should be. ok : inoremap II <Esc>I inoremap AA <Esc>A inoremap OO <Esc>O taken here : http://vim.wikia.com/wiki/Quick_command_in_insert_mode

– Hettomei – 2013-11-07T08:19:09.627