Visual Studio 2010 Emacs Tab deletes characters - visual-studio-2010

In VS2008 with Emacs keybindings, hitting Tab would activate "auto indent", ie indenting the line correctly no matter where the cursor is. However, in VS 2010, it is still attempting to auto indent, but it is also erasing characters from the beginning of the line. So if I have a line like this (using | to represent cursor location):
var i = 180.0|0;
after hitting tab, it looks like this:
0;
This is really frustrating behavior....

Related

What does the underline that is automatically put under the end brace by IntelliSense brace completion denote? [duplicate]

Visual Studio 2013 frequently marks my code with a green _ ( green underscore bar).
What does it represent and is there a feature that it's linked to, like auto complete or intellisense ?
This is the automatic brace completion feature that was introduced in Visual Studio 2013 (although, like so many new features in Visual Studio, it was actually in the Productivity Power Tools extension first).
When you write an opening brace, Visual Studio 2013 inserts a closing brace for you automatically. The underline simply indicates that the code editor is still in brace-complete mode. While in this mode, Visual Studio is waiting to see if you close the brace yourself, in which case it will remove the redundant brace and move the text cursor if necessary. While in this mode, you can also press tab to move the cursor past the closing brace; although, this only seems to work when both braces are on the same line and there is nothing (except whitespace) between the cursor and the closing brace. Moving the cursor outside of the braces exits this mode.
This feature works not only for braces, but also parentheses, square brackets, and quotes (single and double).
You can enable or disable this feature by checking or unchecking the Automatic brace completion checkbox located in:
Tools → Options → Text Editor → All Languages* → General
* or a specific language, e.g. C#
Just go to tools, then options.
You will see the item fonts & Colors there you can choose what you wanna do in such part of your code, such as choosing the type of text and color.

How do I explicitly set the code editor width in Visual Studio 2013 to 80 characters?

This is an IDE tools question.
I want to adhere to a specific style guide which wants me to have my code lines wrap to the next line if they exceed 80 characters on one line. When I select the word wrap option in Visual Studio 2013 text editor, it wraps the current window width of my project. How can I explicitly change my code editor window to be 80 characters in width without having to eyeball it?
Try this VS extension to add a visual guideline at the desired number of chars, then you can break your lines as needed when you approach the line. I'm reinstalling my laptop at the second so can't check, but I assume that the Visual Studio line-wrap option is only visually wrapping the text on your screen rather than actually breaking the line onto a subsequent line when it's over 80 (or width of screen in your case), which isn't really what the style guide you're following will be trying to get you to do.
If you had ReSharper installed, there is an option in that which allows the breaking of lines automatically at a given width.

Visual Studio removes whitespace after closing tag

I have the problem that Visual Studio (or Resharper) removes whitespace after the tag when I use the formatting shortcut ctrl + k + d.
Example - before using the formatting shortcut:
<p>Sample text <b><span class="sometext"></span></b> fooo</p>
Example - after using the formatting shortcut:
<p>Sample text <b><span class="sometext"></span></b>fooo</p>
Ctrl+K+D runs Visual Studio formatter. To use ReSharper one, use Ctrl+E+C. But please note, that in HTML it can only fix indents for you - other spaces or new lines would stay intact.
P.S. One more shortcut for reformatting is Ctrl+E+F. First time when you invoke it you select profile (choose Reformat only and turn on using this profile by default for silent cleanup). Next time when you press Ctrl+E+F it would just silently reformat you code, without dialog.

Is there a shortcut to move the cursor as shown in the following figure?

I am using a notebook without a mouse.
After typing prop and pressing tab, Visual Studio will automatically give me a property template. Pressing tab will move the cursor between type and propertyname placeholders.
I want to move the cursor to a new line after completing the property template.
Is there a shortcut to do so?
Press the Enter key twice.
I tried to post this answer 3 times before I left the comment. It wouldn't let me, too short. That's why I'm typing this otherwise useless verbiage.
It's not specific to snippets, but you can press Ctrl+Shift+Enter to start a new line below where the cursor currently is.
To insert a new line above where the cursor currently is, use Ctrl+Enter.
Both of these work anywhere in the editor. Both of these are handy because they work no matter where you are horizontally on your current line.
Update: Productivity PowerTools for VS2010 (Woot! 2012 too) provides the keyboard shortcut Tools.AddEndTokenAtEnd. (Thanks Ben.)
For some reason, magically, my VS2010 does this with Shift-Enter (which I prefer from my experience with TextMate.) Looking at my keyboard bindings (Tools > Customize > Keyboard) I see that this shortcut is assigned to the command Tools.AddEndTokenAtTheEnd. So if that command appears in your list of commands, assigning a keyboard shortcut to it should work. I have Productivity Power Tools, PowerCommands for Visual Studio 2010, and ReSharper installed. But I can't find any setting from the first two that would be responsible, and, in my experience, all of ReSharper's commands contain its name, so I don't think it added the command. Ooo, and I just discovered that the reason it is named that is because the command also ensures there's a semicolon at the end of the initial line before moving the cursor down; just like the useful keyboard shortcut in Textmate.
I'm interested, but baffled by the 2x-Enter solution. When I press enter twice I get two line breaks followed by whatever code was after the cursor on the first line. Can anyone explain how that shortcut/key-combination works? Is it time-sensitive so that the two enters must be pressed in rapid succession? What if the user wants to quickly insert some lines above some code and hits Return multiple times!?

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 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:
Go to Tools -> Options -> Text Editor and uncheck "pretty listing (reformatting) of code"
Select the text block you wish to copy without indentation
Go to Edit -> Advanced and click "Delete Horizontal White Space" (or: Ctrl K, Ctrl )
Copy and paste your code in Word.
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.

Resources