Visual Studio 2012令人恼火的默认设置:Ctrl-C会复制空行清空剪贴板
在之前发布过的“来!一起给 Visual Studio 2012 找找茬”一文中,竟然忘了这个“茬”,它容易出现的场景如下:
- Ctrl-C 复制一段代码(Ctrl-X也是同样的问题)
- 光标移至想要粘贴代码的空行位置(一般都是在空行上粘贴)
- 按下 Ctrl 键,在接着准备按 V 键时,一走神或者手一抖,手指落在了 C 键上。
- 你回过神来一看,什么也没粘贴出来,只是光标下移一行。
- 你以为没按上键,然后又连续多次Ctrl-V,只见光标依次下移一行,依然什么也没有。
- 这时,如果你知道 Shift-Ctrl-V (cycle clipboard ring) 这个快捷键,可能不会怎么恼火,按两下 Shift-Ctrl-V 就能解决问题;但是如果你不知道这个快捷键,你会很恼火,只能重新复制;如果是剪切,你的恼火会加倍。
2011年7月,有人在微软的 visualstudio.uservoice.com 网站上反馈过这个问题:
stop processing Ctrl+C on empty selections
After copying a large chunk of text to the clipboard with Ctrl+C, I move the cursor to the correct spot in another file and paste it with Ctrl+V. Oh wait, except instead of Ctrl+V my fingers hit Ctrl+C. Even though I didn't highlight any new text, the editor threw my entire careful clipboard in the garbage and replaced it with the current line, forcing me to go back to the other file which I might have closed by now. This is an EXTREME pain in the backside, something I can't turn off (the existing setting only claims to work on blank lines, and doesn't even get THAT right), and something that Visual C++ never used to do before Visual Studio .NET or whatever you call this. Will I have to write an extension that stops the editor from mindlessly performing the copy hotkey on any text that isn't even selected?
微软对这个反馈没有置之不理,在 VS2012 中提供解决了方法(在 stackoverflow 上找到的):
It's not copying an empty block, it's copying the blank line. You can change this setting in Tools > Options > Text Editor > All Languages > 'Apply Cut or Copy Commands to blank lines when there is no selection'.
解决方法很简单,只需取消'Apply Cut or Copy Commands to blank lines when there is no selection'的选择。
虽然不能理解为什么会有复制空行的需求,但如果有,是可以接受的。
但是,为什么默认设置为复制空行,这有违大家的日常操作习惯。在我使用过的编辑器中,除了 Visual Studio,还没遇到会复制空行的编辑器,即使是 Windows 自带的记事本也不会这么做。这个实在无法理解!