---
title: "Visual Studio 2008 每日提示(十一)"
author: "cjc"
date: "2008-12-19T00:38:00Z"
tags: []
slug: "visual-studio-2008"
draft: false
lastmod: "2008-12-19T00:38:00Z"
id: 402676
url: "https://cjc.iteye.com/blog/402676"
---

&lt;script&gt;function StorePage(){d=document;t=d.selection?(d.selection.type!='None'?d.selection.createRange().text:''):(d.getSelection?d.getSelection():'');void(keyit=window.open('http://www.365key.com/storeit.aspx?t='+escape(d.title)+'&u='+escape(d.location.href)+'&c='+escape(t),'keyit','scrollbars=no,width=475,height=575,left=75,top=20,status=no,resizable=yes'));keyit.focus();}&lt;/script&gt;

本篇包括tip101-tip110  
[http://www.watch-life.net/visual-studio/visual-studio-2008-tip-day-11.html](http://www.watch-life.net/visual-studio/visual-studio-2008-tip-day-11.html)

## #101、块缩进和智能缩进的差异

原文链接：[what's the difference between smart indenting and block indenting](http://blogs.msdn.com/saraford/archive/2007/12/06/did-you-know-what-s-the-difference-between-smart-indenting-and-block-indenting.aspx)

**操作步骤：**  
缩进的设置，菜单：**工具+选项+文本编辑器+所有语言+制表符**，在“缩进”选项下有三个选项：无、块缩进、智能缩进。或者在各个语言的制表符也可以设置缩进方式。

块缩进和智能缩进的区别：  
块缩进是上一行和下一行对齐，比如输入 foo(),然后回车，只会在第一行产生缩进，下一个新行光标就转到行首。  
智能缩进所使用的编程语言决定了所使用的相应缩进样式，比如c#语言，输入if（{},那么在花括号里包括的代码里就会自动缩进。

**评论：一般都会选择只能缩进**。

## #102、如何保留制表符或插入空格

原文链接：[How to keep tabs or to insert spaces](http://blogs.msdn.com/saraford/archive/2007/12/07/did-you-know-how-to-keep-tabs-or-to-insert-spaces.aspx)

**操作步骤：**  
制表符的设置，菜单：**工具+选项+文本编辑器+所有语言+制表符**，在“制表符”选项下有二个选项：插入空格和保留制表符。也可以按不同的语言来设置。

![](http://blogs.msdn.com/blogfiles/saraford/WindowsLiveWriter/Didyouknow.Howtokeeptabsortoinsertspaces_C6AF/KeepTabsOrInsertSpace_thumb.jpg)

**评论：我一般使用插入空格，这样即使换了编辑器也不至于格式会变乱**。

## #103、用Ctrl+K, Ctrl+X 插入代码段

原文链接：[Ctrl+K, Ctrl+X inserts a code snippet](http://blogs.msdn.com/saraford/archive/2007/12/10/did-you-know-ctrl-k-ctrl-x-inserts-a-code-snippet.aspx)

**操作步骤：**  
按快捷键**Ctrl+K, Ctrl+X**，根据需要选择插入需要的代码段。

![](http://blogs.msdn.com/blogfiles/saraford/WindowsLiveWriter/Didyouknow.CtrlKCtrlXinsertsacodesnippet_C1EA/CodeSnippetInsertionUICSharp_thumb.jpg)

**评论：使用好代码段，可你让你的编程速度加快很多**。

## #104、修改代码段的变量和默认值

原文链接:[How to change default values and variables in a code snippet](http://blogs.msdn.com/saraford/archive/2007/12/11/did-you-know-how-to-change-default-values-and-variables-in-a-code-snippet.aspx)

通常在使用代码段的时候，变量和默认值都是给定的，同时变量都是高亮显示的

![](http://blogs.msdn.com/blogfiles/saraford/WindowsLiveWriter/Did.Howtochangedefaultvaluesandvariables_C2DD/ForLoopSnippetCSharp_thumb.jpg)

此时你可以把第一“i”改成“j”，然后按Tab键，则所有的变量都变成了“j”。

避过如何光标移到代码段外面后，就无法这样批量来修改了。

**评论：代码段都是有固定的模板生成的，用此方法你可以在编辑的时候批量来修改变量和默认值**。

## #105、使用快捷键来插入代码段

原文链接:[You can insert a code snippet via its shortcut keyword](http://blogs.msdn.com/saraford/archive/2007/12/12/did-you-know-you-can-insert-a-code-snippet-via-its-shortcut-keyword.aspx)

**操作步骤：**  
在输入一个单词的时候，出现智能提示，按两次Tab键后，会自动代码段，比如输入“for” 如下图所示

![](http://blogs.msdn.com/blogfiles/saraford/WindowsLiveWriter/Did.Youcaninsertacodesnippetviaitsshortc_CD27/ForSnippetInStatementCompletion_thumb.jpg)

**评论：这又是一种插入代码段的方法，很方便**。

## #106、浏览和新增代码段

原文链接:[How to browse code snippets and add new ones](http://blogs.msdn.com/saraford/archive/2007/12/13/did-you-know-how-to-browse-code-snippets-and-add-new-ones.aspx)

**操作步骤：**  
1、打开代码段浏览窗口有两种方法  
菜单：**工具+代码段管理器**  
快捷键： **Ctrl+K, Ctrl+B**。

2、在代码段浏览器窗口，可以添加或导入代码段。实际上代码段就是一个xml文件，手工来编写，然后增加。

![](http://blogs.msdn.com/blogfiles/saraford/WindowsLiveWriter/Did.Howtobrowsecodesnippetsandaddnewones_C319/CodeSnippetManager_thumb.jpg)

**评论：如果你有兴趣可以定义自己的代码段，来方便编写代码。**

## #107、在你的团队共享代码段

原文链接:[How to share code snippets with your team](http://blogs.msdn.com/saraford/archive/2007/12/14/did-you-know-how-to-share-code-snippets-with-your-team.aspx)

**操作步骤：**  
1、导出环境设置：**工具+导入和导出设置向导+导出选定的环境设置**，要选中“**常规设置**”中的“**本地代码段**”，会导出一个vssettings 文件。

![](http://blogs.msdn.com/blogfiles/saraford/WindowsLiveWriter/Didyo.Howtosharecodesnippetswithyourteam_CC52/CodeSnippetImportExport_thumb.jpg)  
2、（团队其他成员）导入环境设置：：**工具+导入和导出设置向导+导入选定的环境设置**，选择导出的那个vssettings 文件即可。

**评论：这样在团队里相同的环境设置（包括代码段），如果你有多台电脑，就不必每台来单独配置了。**

## #108、在代码块里插入代码段

原文链接:[how to insert a code snippet around a block of code](http://blogs.msdn.com/saraford/archive/2007/12/17/did-you-know-how-to-insert-a-code-snippet-around-a-block-of-code.aspx)

**操作步骤：**  
1、选中一段代码。  
2、按**Ctrl+K, Ctrl+S**

如下图所示

![](http://blogs.msdn.com/blogfiles/saraford/WindowsLiveWriter/Did.howtoinsertacodesnippetaroundablocko_D2EF/CodeSnippetSurroundWith_thumb.jpg)

![](http://blogs.msdn.com/blogfiles/saraford/WindowsLiveWriter/Did.howtoinsertacodesnippetaroundablocko_D2EF/CodeSnippetSurroundWith2_thumb.jpg)

**评论：这个功能你还不知道吧，小小代码段其实隐藏在背后的小技巧挺多**

## #109、用二进制编辑器打开文件

原文链接:[how to open something in the binary editor](http://blogs.msdn.com/saraford/archive/2007/12/18/did-you-know-how-to-open-something-in-the-binary-editor.aspx)

**操作步骤：**  
菜单：**文件+打开+文件**，选择需要打开的文件，单击“打开”按钮右侧的下拉箭头，选择“打开方式”，

![](http://blogs.msdn.com/blogfiles/saraford/WindowsLiveWriter/Didy.howtoopensomethinginthebinaryeditor_F97B/OpenWith_thumb.jpg)

在“**打开方式**”对话框，选择“**二进制编辑器**”

![](http://blogs.msdn.com/blogfiles/saraford/WindowsLiveWriter/Didy.howtoopensomethinginthebinaryeditor_F97B/OpenWith2_thumb.jpg)

**评论：虽然操作有些复杂，不过就可以用vs来做做二进制编辑器了**

## #110、Visual Studio 支持MDI模式

原文链接:[Visual Studio supports a MDI mode?](http://blogs.msdn.com/saraford/archive/2007/12/19/did-you-know-visual-studio-supports-a-mdi-mode.aspx)

**操作步骤：**  
菜单：**工具+选项+环境+常规**，在“**窗口布局**”中选中“**多个文档**”。

![](http://blogs.msdn.com/blogfiles/saraford/WindowsLiveWriter/Didyouknow.VisualStudiosupportsaMDImode_F3B2/MDImodeOption_thumb.jpg)

在这种模式下，你可以对窗体进行水平或垂直平铺。

![](http://blogs.msdn.com/blogfiles/saraford/WindowsLiveWriter/Didyouknow.VisualStudiosupportsaMDImode_F3B2/MDImodeWindowMenu_thumb.jpg)

这篇可以参考[Visual Studio 2008 每日提示(四)](http://www.watch-life.net/visual-studio/visual-studio-2008-tip-day-4.html)中的tip37。

**评论：我已经习惯了选项卡式的文档，mdi方式恐怕不是很适合编程。**

更多文章见：守望轩\[[http://www.watch-life.net/](http://blog.csdn.net/www.watch-life.net)]