一种用于编程的理想键盘布局

我经常听到一些抱怨,说编程语言为了简洁而大量使用符号,特别是 C 和 C + + (我不打算触及 APL) ,因为它们需要频繁使用 shift 键,所以很难输入。一两年前,我自己也厌倦了它,下载了微软的 键盘布局创建器,对我的布局做了一些修改,从来没有回头看过。速度上的差异令人震惊; 通过这些简单的改变,我可以使 C + + 代码的输入速度快30% 左右,当然这取决于它有多毛糙; 最重要的是,我在普通运行文本中的输入速度没有受到影响。

我的问题是: 现在有哪些替代的键盘布局在编程中已经流行起来,其中有哪些仍然在现代使用,你个人是否使用过任何改变过的布局,我的布局怎样才能进一步优化?

我对标准的 QWERTY 键盘布局做了以下改动。(我不使用 德沃夏克,但有一个值得一提的 程序员德沃夏克布局。)

  • 在第一行中用符号 交换数字,因为长的或重复的文字数字通常用命名常量替换;
  • 用波浪线交换反引号, ,因为反引号在许多语言中很少见,但是析构函数在 C + + 中很常见;
  • 用下划线交换减号, ,因为下划线在标识符中很常见;
  • 用方括号交换大括号, 因为块比下标更常见; 和
  • 用单引号交换双引号, ,因为字符串比字符文字更常见。

我怀疑这最后一个可能是最有争议的,因为它干扰最多的运行文本,要求使用移位到类型常见的缩写。这种布局极大地提高了我在 C + + 、 C、 Java 和 Perl 中的打字速度,并在某种程度上提高了我在 LISP 和 Python 中的打字速度。

82801 次浏览

I still hold that typing speed is not the main factor in the time it takes for a project to be completed. If it is, there is a big problem (Weeks of coding saves us hours of planning).

Regarding your question I prefer using the standard layout as it means I don't have to spend the first 10 minutes looking stupid when presented with a standard keyboard layout.

Some of the replacements you have suggested, e.g. the top row with the special characters doesn't make a ounce of difference as the outside finger on the other hand should be moving to shift at the same time.

IMHO One thing that helps above chaining layouts is using only keyboard shortcuts. Vim and Emacs are recommended. It makes moving text around far faster.

Changing the keyboard layout is a bad idea since it would (perhaps) boost your typing speed on one keyboard, but severely damage your typing speed on other keyboards or on computers where you don't have your special keyboard layout. I've found that it is often better to adjust yourself to the defaults, that having to change them everywhere. (Personally, my fingers are heavily Emacs-biased, which causes lots of typing friction everywhere else.)

Overall, I think having a good text editor and knowing how to use it is better than trying to improve your typing speed. Being able to record and replay macros is sometimes a lifesaver, and a selection of shortcut-assigned code snippets can be handy because there's normally language-imposed limits on what can be turned into a library.

More generally, I think the real productivity enhancers are all about knowledge...

  • Knowing what tools and libraries are available and how to use them.
  • Knowing the overall structure of the code you're working on, not just your little bit.
  • Knowing key algorithms, design patterns and idioms so you don't have to reinvent them.
  • Knowing the rules well enough that you can be flexible - you know when to break them.
  • Knowing your co-workers and their strengths, weaknesses etc - ie knowing when to figure something out yourself, but also when and who to ask.

FWIW, I'm not claiming to be strong on all those. I've always been too biassed towards solving problems myself, and with too strong a tendency towards reinventing the wheel and grand architectural schemes.

Anyway, I just have this suspicion that time spent changing and learning keyboard layouts would be a distraction from more important issues.

I would approach your question in the following way. The task is to organise a keyboard in such way as to minimise key strokes and hand movement for given text.

Steps toward a possible solution. Make a program that:

  1. Takes a text file with source code. (The bigger the better and from various sources!)
  2. Counts the frequency of use of each symbol (its presence in the text).
  3. (optional) Based on step 2: The program generates key stroke count for each symbol plus how far the hand has to go from central position. As a result you will have a measure how effective your keyboard layout is.

Now manually or by writing a program Redefine your layout in the following way. Put most frequently used symbol in a central position closer to your strong hand. The second symbol goes to your weak hand in central position. The third symbol goes back to your strong hand...and so on. Then you gradually move from central position of the hands into more "distant" areas of the keyboard. When all keyboard is full then you continue the process of assigning keys but this time with Shift key pressed. The other difference would be that you do not rotate strong and weak hand for each symbol when the Shift is down. With shift key down first you would fill in central positions on the keyboard and then move to more distant positions.

When you do all that perform step 3 again for the new layout to see how the layout was improved.

You may have to carry your keyboard with you at all times. On the bright side nobody will touch your computer. It will make you look like a Pro.

Finally, don't forget to share your findings.

I'm playing with a variant of the Colemak layout at the moment with heavy changes of symbols:

without SHIFT:

` - { } [ ] ; < > ( ) _ =
q w f p g j l u y * / # \
a r s t d h n e i o '
z x c v b k m , . !

with SHIFT:

~ 1 2 3 4 5 6 7 8 9 0 & +
Q W F P G J L U Y @ ^ $ |
A R S T D H N E I O "
Z X C V B K M % : ?

Maybe I'll restore the / key...

But this is not based on any sound research, and I'd also love to see a layout optimized (Optimization including stuff like hand alteration etc, also ZXCV preservation, ...) with a sourcecode based corpus, because all these layouts seem to be optimized for prose only. For example, 'f' is a very common letter in C (if, for).

Update: I'm currently using

` - { } [ ] @ < > ( ) _ =
q w k r g y u l p * ; #
a s f t d h n e i o ' \
\ z x c v b j m , . /

with SHIFT:

~ 1 2 3 4 5 6 7 8 9 0 ^ +
Q W K R G Y U L P & ! $
A S F T D H N E I O " |
| Z X C V B J M % : ?

This is based on a 6-key-swap partial optimization taken from Carpalx with preservation of the usual Cut/Copy/Paste/Undo shortcuts and modified to give a better access to the usual programming characters.

Make a simple key logger, then count the number of times each key is pressed. Run it for a day or two, then save the output to a text file. Do this every once and a while. It doesn't matter what layout you are using, as you are just seeing which keys are being used the most.

If you want to make a good layout, you can't be afraid to go away from the norm. I'd suggest putting the top 11 keys along the home row, then the next top 11 keys as the top row (leave the 2 keys above the return key as the least used keys), then the 3rd top 11 keys as the bottom row. There should be 4 keys left over now. Take those and put them in the -= and ]\ slots. Congrats! You have now made a great keyboard layout for your purposes! =D