Understanding Virtual Space
Menu: Tools -> Options -> Text Editor -> All Languages -> General -> Settings
Versions: 2008,2010
Published: 2/28/2010
Code: vstipEdit0023
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:
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:
Comments
Anonymous
February 27, 2010
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".Anonymous
February 28, 2010
The comment has been removedAnonymous
February 28, 2010
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? ZAnonymous
February 28, 2010
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.Anonymous
November 02, 2012
The comment has been removedAnonymous
February 01, 2013
The comment has been removedAnonymous
November 26, 2013
To answer an earlier question: one potential use for this is for easily lining up code or comments in a tabular or multi-column format. So if you had something like this: for (string str in strings) { //This is the start of the outer loop for (int i in integers) { //This is the start of the inner loop Console.WriteLine(str + i); //This is the body of the loop } //This is the end of the inner loop } //This is the end of the outer loop Whether this is your coding style or not, this is much easier to do if virtual space is turned on.Anonymous
December 03, 2013
What's the benefit of not using "virtual space"? It confuses me when the cursor jumps when I move it up/down and I am loosing the track of the column it was before I started to move. And what do I get in exchange?Anonymous
March 10, 2014
Much better explanation than I got on MSDN. Thanks!