开发者

Is it possible to copy code from Visual Studio (VB.NET) without indentation?

As I am copying something from within a method, and pasting it into a word document, the code I am copying is already indented. When I paste it开发者_Go百科 I therefore end up with a load of white space next to each line.

I need to copy without this. In C# I can just unindent my code, hit copy, and then indent it back again using the buttons in the IDE. But Visual Basic automatically forces indentation so any attempts to change it don't work.


Visual Studio supports block selection. Press the alt key and drag the cursor to start block selection.

Visual Studio Select Block Text

This is a very useful feature, specially when pasting code here on SO. Visual Studio 2010 will even support multi-line editing using the box selection.


Unfortunately, it seems VB doesn't support the Edit.Advanced.Tabify/Untabify or Increase / Decrease Indent commands.

Here is what you can do:

  1. Go to Tools -> Options -> Text Editor and uncheck "pretty listing (reformatting) of code"
  2. Select the text block you wish to copy without indentation
  3. Go to Edit -> Advanced and click "Delete Horizontal White Space" (or: Ctrl K, Ctrl )
  4. Copy and paste your code in Word.
  5. Turn the "pretty listing" option back on.

the "Delete Horizontal White Space" command will unindent the entire selected text so that there is no tab/whitespace to the left of any line (unlike Block Selection, as prorposed by João Angelo, which will unindent the selected block but keep any indentation within the block).


You may use the Visual Studio extension Copy for review. Besides some formatting, it removes unnecessary whitespace. It works for Visual Basic, among other languages.

Disclosure: I am the author of that extension. Please notify me, if I can improve it to your needs.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜