这是我写的关于VS2010和.Net4的 博客系列 的第27篇。 今天的文章继续上星期我的 调试技巧文章 ,并谈谈Visual Studio里比较有用的搜索和浏览的技巧。我的朋友 Scott Cate (他写了很多关于VS使用技巧和窍门的 博客 )最近向我强调了这些很好的技巧,大部分使
这是我写的关于VS2010和.Net4的博客系列的第27篇。今天的文章继续上星期我的调试技巧文章,并谈谈Visual Studio里比较有用的搜索和浏览的技巧。我的朋友Scott Cate(他写了很多关于VS使用技巧和窍门的博客)最近向我强调了这些很好的技巧,大部分使用VS的开发人员好像不知道这些技巧(即使他们大部分都在产品开发组呆过一阵子)。
如果你还没有使用过这些技巧,希望这篇博文能帮你发现它们。 它们学起来很容易,能帮你节省很多时间。
Ctrl + i渐进搜索
大多数使用Visual Studio的程序员都习惯了在IDE里按“Ctrl + F”键来打开“查找窗口”。但令人惊讶的是,有很多程序员不知道Visual Studio里的“渐进搜索”这个功能。它可以让你在当前文档里进行搜索,而且允许你不用打开对话框就可以搜索。
使用渐进搜索
在编辑器里按“Ctrl + i”即可启用渐进搜索。它会换掉鼠标图标,并将IDE状态栏的左下角改成“渐进式搜索:(搜索关键字)”—你可以键入要搜索的关键字,并且编辑器会从你在源代码的位置开始搜索(不用打开对话框)。
下面我们搜索“action”,VS会在文件里高亮第一次使用到它的地方。
我们可以接着按“Ctrl + i”来搜索下一个用到它的地方(可以重复多次):
按“Ctrl + Shift + i”可以反方向搜索,这样避免回溯。
你可以通过“Esc”键跳出渐进式搜索。这里有关于渐进式搜索更详尽的资料。
F3和Shift + F3 –使用以前的关键字查找
关于渐进式搜索的一个很炫的技巧是,当你按下ESC键退出搜索时,它会将关键字添加到IDE的查找栈里。在VS的标准工具栏上的“查找”下拉框,你可以看到用过的搜索关键字:
在Visual Studio里,按F3键可以让你重复上次的搜索。这在你查找一些东西,改一下代码,然后要从改动过的地方继续搜索的时候非常有用。只要按下F3,你就可以在文档新的位置上重复上次的搜索(例如“action”)—不需要重新键入搜索关键字。
按“Shift + F3”可以使用 上次搜索关键字进行反向搜索(从光标在编???器的当期位置开始)。你可以很方便地用F3/Shift+F3的组合在文档里向前向后搜索。
Ctrl + F3—搜索当前选择的文本
另外一个搜索技巧是,为了避免键入关键字,你可以在代码编辑器里选中一个单词(或单词的一部分),然后按“Ctrl + F3”来在当前文件搜索下一个用到它的地方:
按“Ctrl +F3”搜索选中文本的下一个实例—这样避免你键入它:
跟前面讲的类似,你可以用“Ctrl + Shift + F3”来进行反向搜索,即从文本里回溯搜索。
Ctrl + Shift + F –在解决方案里搜索
有时你会想在整个解决方案里进行搜索。
“Ctrl + F”打开的查找对话框默认是在当前文档进行搜索。“Ctrl + Shift + F”打开的查找对话框默认在整个解决方案里进行搜索:
执行一个这样的搜索,会打开IDE里的“查找结果”窗口,你可以在里面定位到搜索关键字的每个实例:
你可以在“查找结果”窗口里双击一项来跳到关键字出现的地方。
有一个很多人都不知道的技巧,就是按“F8”或者“Shift + F8”可以在列表的前后项之间切换。这使得在里面定位变得更快更容易,这样就不用使用鼠标来进行移动了。
Shift + F12 –查找用途
大部分使用Visual Studio的程序员都知道选中一个类型,然后按F12来“转到定义”。它会跳转到定义类型的地方,这样查看类型定义就变得很方便。
但大部分程序员都不知道“Shift + F12”—它会找出所有用到一个特定类型的地方。让你快速找到一个类型的用法。要用它,只要选中或者把光标放在一个类型,然后按“Shift + F12”:
然后它会打开“查找符号结果”窗口,并列出当前解决方案里所有用到这个类型的地方:
跟前面一样,按“F8”或者“Shift + F8”可以在列表的前后项之间切换。
Ctrl +减号和Shift + Ctrl +减号–向前/向后定位
打开另一个代码文件,查看一些东西,然后想回到前面文件的位置,这样的经历你有过吗?比如说,用F12“转到定义” 后,然后要跳回原来用到类型的代码那里?
一个很多人都不知道的VS的功能,就是“回溯定位”组合键—“Ctrl + (减号键)”。它会在导航栈中跳转到以前的文档或者位置。
要看它是如何工作的,请先在Visual Studio里选中一个类型。下面我选中了“IController”接口:
按F12跳到它的定义处,会打开一个新的编辑器窗口并显示选中类型的源代码:
现在要回到我们当初的位置,按“Ctrl + (减号键)”,然后VS就会把我们带回原来的地方:
而如果你想要在导航栈里往前走(也就是要回到IController.cs文件),那就按“Shift + Ctrl + (减号键)”。
Sara Ford有一篇不错的文章深入讲解了这个功能,还解释了将新的位置压入导航栈的条件。
Ctrl + Alt +(向下键)-定位一个打开的文件
曾经在IDE里打开了数不清的文件,想要找到一个容易的方法漫步其中?
一个很有用的按键组合就是“Ctrl + Alt + (向下键)”—这时VS会显示一个下拉框并列出所有打开的文件:
你可以使用箭头键来选择要浏览的文件—或者最好开始敲文件名,Visual Studio会为你在列表里高亮它。比如说,上面我敲了“Mo”,Visual Studio高亮“ModelBinder.cs”。按下“Enter”键就会帮我打开那个文件:
这是一个在文件之间很好的、便利的浏览方式,不需要使用鼠标,或者要让你的手离开键盘。另外记住“Ctrl + (减号)”可以让你回到原来的位置。
定位到,调用层次结构和引用高亮功能
Visual Studio 2010提供了一大批新的代码定位和查找功能—包括新的“定位到”对话框,“查看调用层次结构”功能和引用高亮功能:
我在之前的博客里提到了VS 2010这三个新功能。如果你还没有读过这篇文章并体验它们的能量,我非常推荐你去试试—它们是很好的补充。
编辑器其他方面的改进
VS 2010里面有数不清的改进—我在之前的博客里也提到很多。这使我之前的几篇VS 2010编辑器的文章:
·改进过的C#/VB代码智能感知
·改进过的JavaScript代码智能感知
·框选和多行编辑支持
·ASP.NET, HTML和JavaScript代码片段支持
另外也请看看我关于VS 2010和.NET 4改进系列的其他博客。
总结
上面大部分功能实际在Visual Studio已经存在了好几个版本—但还是有非常多的程序员不知道他们。希望这篇博客提供了一条捷径帮你了解它们。如果你需要记住这些按键—打印一份VS 2010快键招贴画,并贴在你显示器旁边。
如果还要学习更多的Visual Studio技巧,请订阅Scott Cate的Visual Studio技巧系列文章(里面已经有83个超棒的技巧了),也可以订阅Sara Ford的博客—历年来,她也有一个很棒的技巧集。
希望这能对您有所帮助。
Scott
原文:http://weblogs.asp.net/scottgu/archive/2010/08/24/search-and-navigation-tips-tricks-with-visual-studio.aspx
中文翻译:http://blogs.msdn.com/b/scottgu/archive/2011/10/08/visual-studio-1.aspx

MySQLoffersvariousstorageengines,eachsuitedfordifferentusecases:1)InnoDBisidealforapplicationsneedingACIDcomplianceandhighconcurrency,supportingtransactionsandforeignkeys.2)MyISAMisbestforread-heavyworkloads,lackingtransactionsupport.3)Memoryengineis

Common security vulnerabilities in MySQL include SQL injection, weak passwords, improper permission configuration, and unupdated software. 1. SQL injection can be prevented by using preprocessing statements. 2. Weak passwords can be avoided by forcibly using strong password strategies. 3. Improper permission configuration can be resolved through regular review and adjustment of user permissions. 4. Unupdated software can be patched by regularly checking and updating the MySQL version.

Identifying slow queries in MySQL can be achieved by enabling slow query logs and setting thresholds. 1. Enable slow query logs and set thresholds. 2. View and analyze slow query log files, and use tools such as mysqldumpslow or pt-query-digest for in-depth analysis. 3. Optimizing slow queries can be achieved through index optimization, query rewriting and avoiding the use of SELECT*.

To monitor the health and performance of MySQL servers, you should pay attention to system health, performance metrics and query execution. 1) Monitor system health: Use top, htop or SHOWGLOBALSTATUS commands to view CPU, memory, disk I/O and network activities. 2) Track performance indicators: monitor key indicators such as query number per second, average query time and cache hit rate. 3) Ensure query execution optimization: Enable slow query logs, record and optimize queries whose execution time exceeds the set threshold.

The main difference between MySQL and MariaDB is performance, functionality and license: 1. MySQL is developed by Oracle, and MariaDB is its fork. 2. MariaDB may perform better in high load environments. 3.MariaDB provides more storage engines and functions. 4.MySQL adopts a dual license, and MariaDB is completely open source. The existing infrastructure, performance requirements, functional requirements and license costs should be taken into account when choosing.

MySQL uses a GPL license. 1) The GPL license allows the free use, modification and distribution of MySQL, but the modified distribution must comply with GPL. 2) Commercial licenses can avoid public modifications and are suitable for commercial applications that require confidentiality.

The situations when choosing InnoDB instead of MyISAM include: 1) transaction support, 2) high concurrency environment, 3) high data consistency; conversely, the situation when choosing MyISAM includes: 1) mainly read operations, 2) no transaction support is required. InnoDB is suitable for applications that require high data consistency and transaction processing, such as e-commerce platforms, while MyISAM is suitable for read-intensive and transaction-free applications such as blog systems.

In MySQL, the function of foreign keys is to establish the relationship between tables and ensure the consistency and integrity of the data. Foreign keys maintain the effectiveness of data through reference integrity checks and cascading operations. Pay attention to performance optimization and avoid common errors when using them.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

Atom editor mac version download
The most popular open source editor

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software
