Understanding Virtual Space

Tips Search

If you like the tips then you'll love the book!

Order your copy today:
http://www.amazon.com/gp/product/0735649928

Understanding Virtual Space

  • Comments 4

Menu:  Tools -> Options -> Text Editor -> All Languages -> General -> Settings
Versions:  2008,2010
Published:  2/28/2010
Code:  vstipEdit0023

 

image

 

Okay.  Virtual space is a little funky to understand if you aren't from the Old School.  You see, a loooooong time ago in this galaxy we used to have (and some people still have) editors that treat everywhere as editable space.  Let me explain:  Without virtual space on the line ends where the code ends.  Now you can have some really long lines of code but, until you press Enter, the line just keeps on going.  Like this:

image

 

If I move my cursor to the end of any of these lines and hit my Right Arrow key then it will go to the next line.  So, for the short line the cursor will jump down to the next line at column  44.  For the longer line it will jump down the next line at column 68.  And for the super duper long line it will jump to the next line at column 176.  This is the way editors have been for a while now and isn't really new to folks.

 

However, this way wasn't always the case.  There was a time when you could type anywhere you wanted any time you wanted without restriction.  Some text editors still do this today.  Virtual space allows you to go back to the old style of editing which is preferred by some coders.  Go to Tools -> Options -> Text Editor -> All Languages -> General -> Settings and check the "Enable virtual space" checkbox to turn this feature on.  When you do, you will be able to type anywhere on a line regardless of whether the code ends or not:

image

  • I think the description is a bit misleading.

    So long as word wrap is off, code lines can continue for as long as you want until you hit return; the virtual space option doesn't need to be on for that.

    When virtual space is off the text cursor is restricted to the areas where text exists but there's no limit on the length of lines.

    When virtual space is on you can use the arrow keys, or mouse clicks, to position the cursor off the end of lines, past their carriage returns and then start typing in that "space".

  • Leo is correct, virtual space and word wrap are really not related, except that they are generally not used together because word wrap can make viritual space a bit odd.

    One of the main behaviors that virtual space changes is that it allows you to use the arrow keys to navigate up and down through the file while keeping your cursor in the same column, for doing things like aligning text.  If virtual space is off, moving the cursor to a different line will also move the cursor to a different column if the line you're moving to is shorter than the column where the cursor is positioned.

  • Good points Leo and Greg.  I'll incorporate the info into the description to make it less misleading.  I did notice that you can't have both virtual space and word wrap as the IDE won't allow it.  I get the reason for word wrap but, to be honest, haven't (or don't) see a compelling reason for virtual space.  Does anyone use it?

    Z

  • Yes, I use it all the time, and have for many years.  A lot of the places where it is useful are the same kinds of places where column select, and the VS2010 enhancements to it, are useful.

Page 1 of 1 (4 items)
Leave a Comment
  • Please add 3 and 3 and type the answer here:
  • Post