未加星标

Preparing Vim for Apple’s Touch Bar

字体大小 | |
[系统(linux) 所属分类 系统(linux) | 发布者 店小二05 | 时间 2017 | 作者 红领巾 ] 0人收藏点击收藏
Written by Harry Roberts on CSS Wizardry .

Apple recently announced their updated MacBook line, introducing the Touch Bar that would be replacing the physical function row, including the escape key. If, like me, you’re a Vim user, that might have quite an impact: how best to prepare for it?

Background

Vim is a modal editor . Unlike most text editors―where you’re ready to type as soon as it opens―Vim loads itself in Normal mode, and you have to make a conscious choice to enter Insert mode in order to begin typing. Once you’ve finished typing, you need to get yourself back into Normal mode again. To do this, one of the most common options is to hit Escape, or <Esc> .

The reason <Esc> is used is because Bill Joy, the author of Vim’s predecessor, Vi , used an ADM-3A terminal whose <Esc> key was located where today’s <Tab> is ―far more convenient than its top-left location today.

There are actually many other modes besides Insert and Normal, and switching from them back into Normal mode usually requires hitting <Esc> as well. Here you can see Vim users’ predicament… the Escape key is very important to us.

How can we switch between modes without having an Escape key?

Remap Other Keys

For almost as long as I’ve been using Vim―which isa long time now―I’ve been using jj and jk to leave Insert mode. These mappings are on the Home Row , so always easy to reach, and the letter pairs very rarely (if ever) occur in the English language. If there were words that contained jj and jk next to each other then I would be flung straight into Normal mode any time I tried to write them. (The reason I haven’t mapped kk to Escape is because it does occur within words, e.g. bookkeeper . (Although I think that might be the first time I’ve ever actually written the word bookkeeper. (Interestingly, bookkeeper is the only English word that has three consecutive double letters.)))

This means that any time I’m typing, hitting either jk or jj gets be back into Normal mode and leaves my fingers primed for moving up or down. I always use this instead of <Esc> to get from Insert to Normal.

You can do this too by adding these lines to your .vimrc :

" Make `jj` and `jk` throw you into normal mode inoremap jj <esc> inoremap jk <esc>

This creates an i nsert mode no n- re cursive map from jj and jk to <Esc> . For more information on mapping either run :help map.txt , or see the online documentation .

This only really helps us out if we’re in Normal mode though: if we’re in Visual mode it’s just going to move our selection up or down, and Command mode will literally write the characters out. What else can we do?

Alternatives to <Esc>

Where as jj and jk are remapped to act like <Esc> , it turns out that there are some native alternatives to <Esc> that we can use across modes.

As I mentioned, hitting jj and jk in Command mode will be interpreted literally, and in Visual mode they will navigate, so in these modes we can use either Ctrl+[ (or <C-[ > in Vim-speak) or Ctrl+C (or <C-c > in Vim-speak).

The Vim help even says:

Note: If your <Esc> key is hard to hit on your keyboard, train yourself to use CTRL-[ . So, whenever you’re in any modes other than Insert, reach for Ctrl-[ or Ctrl-C instead of <Esc> . Ctrl-C is probably going to be a little easier to remember, because you probably recognise it as the cancel signal in from your shell, however there are some subtle differences between the two… What’s the Difference? Ctrl-[ acts almost universally identically to Esc , so there’s nothing real of note there. What does need a little further mention is Ctrl-C .

Ctrl-C is a cancel signal, so its job is just to get you straight out of whatever you’re doing and back into Insert mode as fast as possible. This means that Ctrl-C will not complete any pending abbreviations or send the InsertLeave signal back to Vim (which some of your plugins may depend on).

This doesn’t mean that Ctrl-C is bad or should be avoided; it’s just the most heavy handed of the two. Your mileage may vary.

Expert Mode

We’ve got alternatives to the <Esc> key now, so we can gradually begin phasing it out of our workflow, but how about we make things a little more difficult for ourselves? We could disable the <Esc> key fully. Let’s take the training wheels off.

To do this, we can just map <Esc> to no operation , or <nop> . There isn’t a remap-in-every-mode command, so we need to drop both of these into our .vimrc which will cover all possibilities:

" Map `Escape` to ‘nothing’ in Normal, Visual, Select, Operator-pending modes noremap: <esc> <nop> " Map `Escape` to ‘nothing’ in Insert and Command modes noremap!: <esc> <nop>

Again, you’ll want to exercise some caution with this: there can be some unexpected side-effects as outlined in this Stack Overflow answer .

本文系统(linux)相关术语:linux系统 鸟哥的linux私房菜 linux命令大全 linux操作系统

主题: AppleCSSMacBookADM
分页:12
转载请注明
本文标题:Preparing Vim for Apple’s Touch Bar
本站链接:http://www.codesec.net/view/521606.html
分享请点击:


1.凡CodeSecTeam转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
登录后可拥有收藏文章、关注作者等权限...
技术大类 技术大类 | 系统(linux) | 评论(0) | 阅读(77)