visual-studio 在按 ctrl 和光标键时让 Visual Studio 理解 CamelCase
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 
原文地址: http://stackoverflow.com/questions/314095/
Warning: these are provided under cc-by-sa 4.0 license.  You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Make Visual Studio understand CamelCase when hitting ctrl and cursor keys
提问by serg10
Is there a way that I can configure Visual Studio 2008 to understand CamelCase?Specifically, I'd like to be able to get ctrl + rightor leftcursor to take me to a subsection of a variable or type name.
有没有办法可以配置 Visual Studio 2008 来理解 CamelCase?具体来说,我希望能够使用 getctrl + right或leftcursor 将我带到变量或类型名称的子部分。
i.e., if my cursor was at the start of this line:
即,如果我的光标在这一行的开头:
LongNamedExampleClass longNamed = new LongNamedExampleClass();
and I hit ctrl + right, I'd like to jump to "Named" in the class name, rather than the start of the variable name.  If I hit it again, I'd like to go to "Example".  I hope that makes sense...
我点击了ctrl + right,我想跳到Named类名中的“ ”,而不是变量名的开头。如果我再打一次,我想去“ Example”。我希望这是有道理的...
I used this navigational feature in eclipse quite a lot, and find it difficult to unlearn something so ingrained.
我在 eclipse 中经常使用这个导航功能,发现很难忘记一些根深蒂固的东西。
回答by serg10
Thanks for those who suggested Resharper. Gives me another reason to love it even more. Just to be specific about where this lives - JetBrains call it CamelHumps(cute) and you can switch it on using the menu:
感谢推荐 Resharper 的人。给了我另一个更爱它的理由。只是为了具体说明它的位置- JetBrains 称它为CamelHumps(可爱),您可以使用菜单打开它:
Resharper -> Options -> Environment -> Editor -> Editor Behavior -> Use CamelHumps
Resharper -> 选项 -> 环境 -> 编辑器 -> 编辑器行为 -> 使用 CamelHumps
... in older versions of Resharper, it is;
...在旧版本的 Resharper 中,它是;
Resharper -> Options -> Editor -> Use CamelHumps
Resharper -> 选项 -> 编辑器 -> 使用 CamelHumps
回答by jsea
Anyone stumbling across this page after Nov 25, 2008 (who don't want to pay for ReSharper or CodeRush which no longer has a free version), the following free Extension adds this functionality: Subword Navigationby Olle Westman
任何在 2008 年 11 月 25 日之后偶然发现此页面的人(不想为不再有免费版本的ReSharper 或 CodeRush 付费),以下免费扩展添加了此功能:Olle Westman 的子词导航
(Alternatively, the VSTricksextension includes Sub-word Navigation in its list of nifty features. There is also a different Subword navigationextension created by Lauri Vasama not to be confused with Olle Westman's which this answer uses.)
(或者,VSTricks扩展在其漂亮功能列表中包含子词导航。还有一个由 Lauri Vasama 创建的不同子词导航扩展,不要与本答案使用的 Olle Westman 混淆。)
The Subword Navigation project page states:
子词导航项目页面指出:
Look up Edit.Subword in keyboard bindings to set things up.
在键盘绑定中查找 Edit.Subword 以进行设置。
Here's how I set it up in Visual Studio 2019:
这是我如何设置它Visual Studio 2019:
- Navigate to Tools > Options > Environment > Keyboard
- 导航到工具 > 选项 > 环境 > 键盘
- Under Use new shortcut in, select Text Editor
- 在 下Use new shortcut in,选择文本编辑器
- Under Show commands containing, type Edit.Subword. This should pop up an autocomplete field with the listed commands below.
- 在 下Show commands containing,输入Edit.Subword。这应该会弹出一个带有下面列出的命令的自动完成字段。
- Select one of the following commands you want to set its shortcut keys for. Once selected, follow the rest of the numbered steps. Then come back to Step 4to set another one.- Edit.SubwordNext- Traverses camelcases to the right [Alt + Right Arrow]
 
- Traverses camelcases to the right [
- Edit.SubwordPrevious- Traverses camelcases to the left [Alt + Left Arrow] ????????????????????????????????????????????????????????????
 
- Traverses camelcases to the left [
- Edit.SubwordNextExtend- Selects camelcases to the right [Alt + Shift + Right Arrow]
 
- Selects camelcases to the right [
- Edit.SubwordPreviousExtend- Selects camelcases to the left [Alt + Shift + Left Arrow] ?????????????????????????????????????????????????????????????
 
- Selects camelcases to the left [
- Edit.SubwordDeleteNext- Deletes camelcases to the right [Alt + Delete]
 
- Deletes camelcases to the right [
- Edit.SubwordDeletePrevious- Deletes camelcases to the left [Alt + Backspace]
 
- Deletes camelcases to the left [
 
- Edit.SubwordNext
- 选择要为其设置快捷键的以下命令之一。选择后,请按照其余的编号步骤进行操作。然后返回Step 4设置另一个。- Edit.SubwordNext- 向右遍历驼峰 [ Alt + Right Arrow]
 
- 向右遍历驼峰 [ 
- Edit.SubwordPrevious- 向左遍历驼峰 [ Alt + Left Arrow] ??????????????????????????????????????????? ?????????????????????
 
- 向左遍历驼峰 [ 
- Edit.SubwordNextExtend- 选择右侧的驼峰 [ Alt + Shift + Right Arrow]
 
- 选择右侧的驼峰 [ 
- Edit.SubwordPreviousExtend- 选择左侧的驼峰 [ Alt + Shift + Left Arrow] ???????????????????????????????????????????? ??????????????????
 
- 选择左侧的驼峰 [ 
- Edit.SubwordDeleteNext- 删除右侧的驼峰 [ Alt + Delete]
 
- 删除右侧的驼峰 [ 
- Edit.SubwordDeletePrevious- 删除左侧的驼峰 [ Alt + Backspace]
 
- 删除左侧的驼峰 [ 
 
- Edit.SubwordNext
Note:When assigning these Subword Navigation commands to these new shortcut keys, preserve any already-existing shortcut-key functionality you want to keep beforehand by setting them to different keys. It should not conflict with any default-installed shortcut keys.
注意:将这些子词导航命令分配给这些新快捷键时,请通过将它们设置为不同的键来保留您希望预先保留的任何现有快捷键功能。它不应与任何默认安装的快捷键冲突。
- Under Press shortcut keys, press Your Shortcut Keys
- 在 下Press shortcut keys,按您的快捷键
- Click Assignand overwrite the existing shortcut
- 单击Assign并覆盖现有的快捷方式
回答by keremispirli
If you have ReSharper installed you can also configure Visual Studio keyboard shortcuts "Alt-Right" and "Alt-Left" for CamelHump, without losing standard Visual Studio behaviour for "ctrl-right" and "ctrl-left".
如果您安装了 ReSharper,您还可以为 CamelHump 配置 Visual Studio 键盘快捷键“Alt-Right”和“Alt-Left”,而不会丢失“ctrl-right”和“ctrl-left”的标准 Visual Studio 行为。
- Open the Visual Studio Optionswindow from Tools –> Options
- Expand Environmentand scroll down to Keyboard
- In Show commands containingbox, type "hump". This will show all commands related to CamelHumps.
 
- Map the commands to the key mappings you wish by selecting the command from the list and entering the key mapping in the Press shortcut keystextbox, then click Assign.
- 从工具 -> 选项打开 Visual Studio选项窗口
- 展开环境并向下滚动到键盘
- 在显示包含框的命令中,键入“hump”。这将显示与 CamelHumps 相关的所有命令。
 
- 通过从列表中选择命令并在按下快捷键文本框中输入键映射,将命令映射到您希望的键映射,然后单击分配。
Caveats:
注意事项:
- Assign the mappings for Text Editor, not Global.
- Make sure the Use CamelHumpsoption from Resharper -> Options -> Editor -> Editor Behaviour is turned off.
- 为Text Editor分配映射,而不是Global。
- 确保Resharper -> Options -> Editor -> Editor Behavior 中的Use CamelHumps选项已关闭。
Details here: http://davidrcook.wordpress.com/2009/11/05/working-with-camel-case-in-visual-studio/
详情请见:http: //davidrcook.wordpress.com/2009/11/05/working-with-camel-case-in-visual-studio/
回答by Stewart Johnson
It's not native to Visual Studio, but you can get it for free using CodeRush Express. (ReSharper and CodeRush require payment).
它不是 Visual Studio 原生的,但您可以使用CodeRush Express免费获得它。(ReSharper 和 CodeRush 需要付费)。
回答by Steve Brouillard
Visual Studio does not support this behavior. However, DevExpres'sCodeRush! product supports navigation like this (using Alt-Left & Alt-Right), along with tons of other features to aid in navigation. The CodeRush! product is also bundled with their Refactor tool. They also offer a free CodeRush! & Refactor Express product, though I'm not certain if the Camel Casing navigation is part of the express product.
Visual Studio 不支持此行为。然而,DevExpres 的CodeRush!产品支持这样的导航(使用 Alt-Left 和 Alt-Right),以及大量其他有助于导航的功能。CodeRush!产品还与他们的重构工具捆绑在一起。他们还提供免费的 CodeRush!& 重构 Express 产品,虽然我不确定 Camel Casing 导航是否是 Express 产品的一部分。
回答by ozan k
Add the macro below to the visual studio.
将下面的宏添加到视觉工作室。
http://visualstudiomacros.blogspot.com/2008/03/getting-ctrl-right-arrow-to-respect.html
http://visualstudiomacros.blogspot.com/2008/03/getting-ctrl-right-arrow-to-respect.html
回答by Mehrdad Afshari
I don't think Visual Studio supports this feature internally, as it seems to be using the normal way Ctrl+Right and Ctrl+Left work in Windows environment. But it's probably possible with some kind of extension or plugin.
我认为 Visual Studio 内部不支持此功能,因为它似乎在 Windows 环境中使用 Ctrl+Right 和 Ctrl+Left 的正常方式工作。但是使用某种扩展或插件可能是可能的。

