Shift + Enter no longer adds a new line in Visual Studio - visual-studio

I installed the Visual Studio 2010 productivity power tools, and since then Shift + Enter does not add a new line in the text editor. I've tried disabling all of the productivity tools settings and even uninstalling the productivity power tools entirely, but Shift + Enter still does nothing. I can't find the setting for this.
How can I re-enable shift + enter to add a space (just like enter alone does)?

Go to Tools/Options/Environment/Keyboard.
Switch the "Use new shortcut in:" dropdown to "Text Editor".
Pick the Edit.BreakLine command.
In the Press shortcut keys edit pane press Shift+Enter.

From Options menu, select "Environment", then "Keyboard" that gives you the option of setting keyboard shortcuts. The one you want should be "Edit.BreakLine" - you can search for them. Selecting this, you can then add/remove assosciated shortcuts.

In new versions it was changed to Ctrl+Shift+Enter, And you easily can change it as sbi suggested

Try Ctrl + Shift + Enter to add a line bellow.
Ctrl + Enter will add a line above.

Related

Set Add Class shortcut key in Visual Studio

I used to used the shortcut Ctrl + Shift + C to add a new class in Visual Studio 2015. This seems to have gone away when I'm using a different machine. How do I set this?
I've looked in Options > Environment > Keyboard but I can't see anything obvious...
Navigate to Tools >> Options >> Environment >> Keyboard, search for commands containing Project.AddClass and setup the shortcut you want
Steps to setup a shortcut
Search any command like AddClass in Show commands containing box
Select a desired command
Click on the blank Press shortcut keys box
Press desired key / key combination for shortcut using your keyboard
Also, see article Visual Studio Shortcuts and Add on Tools...
This article explains the same in more detail with some other interesting (and perhaps even relevant) points.

Rearrange Code shortcut in Resharper doesn't work in VS2015

When I try to use the shortcut for moving lines up/down (Ctrl+Alt+Shift+↑/↓), it highlights the code and shows the tooltip message "Use Up/Down to move text line" but nothing happens. If however I try the same command via the menu bar (Resharper > Edit > Rearrange Code > Move Up) it moves the selected lines as expected.
I used to use this feature all the time so I find this bug very annoying. Apparantly, others also experience this (see comments for Resharper move line up down not working) but I haven't been able to find a solution for it. Resetting keyboard layouts and reapplying VS keyboard schemes doesn't work.
Has anyone been able to resolve this issue?
[EDIT]
Reason of this is issue (when you are logging to machine with VS and Resharper via Remote Desktop) is that Ctrl-Alt-Left Arrow/Ctrl-Alt-Right Arrow combinations are not sent to your virtual machine
There are two workarounds:
My first soultion (change combination see below)
You can use AutoHotKey script as stated in thread:
https://superuser.com/questions/327866/remote-desktop-sending-ctrl-alt-left-arrow-ctrl-alt-right-arrow-to-the-remote-p
[/EDIT]
Reason is
duplication of the same hotkeys which could be found in 'Shortcut currently used by:' combobox
Fix is
I described process for _MoveRight shortcut - for other shortcuts it works the same
STEP 1 Check for conflicting changes
seeImage
go to Tool --> Options --> Keyboard
in field 'Show commands containing' find your command (moveright in example)
click in field 'Press shortcut keys' press ALT + RIGHT ARROW
in field Shortcut currently used by you will find conflicting shortcut -
Edit.CompleteWord...
STEP 2 Now we need to delete this shortcut
in field 'Show commands containing' write Edit.CompleteWord
you should see ALT + RIGHT ARROW shortcut in field 'Shortcuts for selected command
click Remove button
STEP 3 Now we need to add our shortcut to _MoveRight function
in field 'Show commands containing' find your command (moveright in example)
click in field 'Press shortcut keys' press ALT + RIGHT ARROW
click Assign

Visual Studio: how to make pressing tab key indent the whole line

Is there a way to configure a keyboard shortcut in Visual Studio such that tab (or some other key combo) indent the whole line (rather than insert a tab character/spaces at the cursor)?
Trying to determine whether Visual Studio is the dream editor
EDIT
I'm an experienced VS user, I know about the standard behavior, just curious whether it can be configured with the interesting tab behavior described in the link.
Increase indent:
Select / highlight line(s) or press Home
Press tab
Decrease indent:
Select / highlight line(s) or press Home
Press shift + tab
If you want to add a shortcut to do the same from anywhere in the line without selecting it then you can add a shortcut in Options -> Environment -> Keyboard. There'll be a list of commands including Edit.IncreaseLineIndent and Edit.DecreaseLineIndent. I couldn't find a good key combination for a shortcut though which wasn't already being used for something else. You can't use just tab by itself.

How do you auto format code in Visual Studio?

I know Visual Studio can auto format to make my methods and loops indented properly, but I cannot find the setting.
To format a selection: Ctrl+K, Ctrl+F
To format a document: Ctrl+K, Ctrl+D
See the pre-defined keyboard shortcuts. (These two are Edit.FormatSelection and Edit.FormatDocument.)
Note for macOS
On macOS, use the CMD ⌘ key instead of Ctrl:
To format a selection: CMD ⌘+K, CMD ⌘+F
To format a document:
CMD ⌘+K, CMD ⌘+D
For Visual Studio 2010/2013/2015/2017/2019
Format Document (Ctrl+K,Ctrl+D), i.e. press&hold Ctrl, press&release K then tap D as it is a sequence
Format Selection (Ctrl+K,Ctrl+F)
Toolbar Edit -> Advanced (If you can't see Advanced, select a code file in solution explorer and try again)
Your shortcuts might display differently to mine as I am set up for C# coding but navigating via the toolbar will get you to your ones.
If it isn't working, look for errors in your code, like missing brackets which stop auto format from working
I have installed an extension named "Format document on Save" which formats the whole document every time you save it.
For installing it in Visual Studio 2015 or Visual Studio 2017, on Tools just click the "Extensions and Updates...":
And then just go to "Online" at the left panel and search for "Format document on save":
Go to menu Tools → Extensions & Updates and type "productivity" in search:
Install 'Productivity Power Tools 2015'
Restart Visual Studio.
Go to menu Tools → Options → Productivity Power Tools → Power Commands and check "Format document on save":
Note: In VS2022 we don't have power commands.
If anyone want to have "Format document on save" and "Remove and sort using on save" install Mads Kristensen extension for VS2022 https://marketplace.visualstudio.com/items?itemName=MadsKristensen.CodeCleanupOnSave
After installing this extension it will automatically "Format document on save", "Remove and sort using on save" and "Apply file header preferences".
If we want to customize default settings click on "Configure Code Cleanup" menu item to add/remove any available fixers.
Visual Studio 2019 & 2022
Format Document, While you're holding down Ctrl button, first press K then D
Format Selection, While you're holding down Ctrl button, first press K then F
or just click Edit => Advanced => Format Document / Format Selection
Follow the steps below:
Go to menu Tools
Go to Options
Go to the Text Editor options
Click the language of your choice. I used C# as an example.
See the below image:
You can define new key bindings by going to Tools → Options → Environment → keyboard:
On mac : Shift + Option + F
On ubuntu : Ctrl + Shift + I
SinceVisual Studio 2022 17.1 there is a builtin Feature to run code formatting on save (see devblogs.microsoft), meaning there is no need to install extensions like Format document on Save.
In Visual Studio 2017, 2019, 2022
Format Document is Ctrl + E, D.
But...if you want to add the Format Document button to a tool bar do this:
Right click on tool bar.
Select "Customize.."
Select the "Commands" Tab.
Select the "Toolbar" radio button.
Select "Text Editor" from the pull down next to the radio button (or whatever tool bar you want the button on)
Now...
Click the Add Command button.
Categories: Edit
Commands: Document Format
Click OK
I used to use these combinations. I automated this process on Save of a document. You can try my extension Format Document on Save.
If you display the HTML Source Editing toolbar, there is a "Format the Whole Document" button as well.
The solution provided in accepted answer does not apply to Microsoft Visual Studio 2012.
In case of Visual Studio 2012, the shortcuts are:
For a highlighted block of code:
Ctrl + K, Ctrl + F
For the document-wide formatting:
Ctrl + K, Ctrl + D
In Visual Studio 2019 , "Code Cleanup" (RunDefaultCodeCleanup) is more advanced (taken from ReSharper):
Ctrl + K, Ctrl + E
Options dialog box: Text Editor → C# → Code Style → Formatting
Auto formatting settings in Visual Studio
Select the text you want to automatically indent.
Click menu Edit → Advanced → *Format Selection, or press Ctrl + K, Ctrl + F. Format Selection applies the smart indenting rules for the language in which you are programming to the selected text.
Step (1): Ctrl + A
Step (2): Ctrl + K
Step (3): Ctrl + F
Under menu Tools → Options → Text Editor, then going to the Formatting → General section of whatever language you wish to format you will find General. Check all three formatting check-boxes.
Under menuTools → Options → Text Editor, then going to the TABS section of whatever language you wish to format you will find Indenting. Select Smart and it will activate automatic formatting whenever you use one of the closing elements ; ) } within that block.
There isn't any need for keystrokes.
You can add the buttons to your toolbar by clicking the little drop down arrow to the right of the last toolbar button, select "Add or Remove Buttons" and then click the buttons you want to add a tick to them. The button(s) you select will appear on your toolbar ...
Then you just select text and click the Increase Indent or Decrease Indent buttons. I tested this on Visual Studio 2013 only.
In newer versions, the shortcut for the document-wide formatting is: Shift + Alt + F
Right click:
It works in Visual Studio 2015, maybe earlier version.
The original question said "I cannot find the setting."
Simple answer is: Look at top menu, then
Edit --> Advanced --> Format Document
You will also see the currently assigned key strokes for that function. Nothing special to memorize. This really helps if you use multiple developer environments on different operating systems.
Select the data and the right click and you will find this option.
Format Document and Format Selection:
Just to further Starwfanatic and Ewan's answers, you can customise your IDE to add any button to any toolbar - so you can add the Format button (as the HTML Source Editing toolbar has) to any other toolbar (like Text Editing with all the other edit controls like increase/decrease indent).
Click the arrow to the right of the toolbar → Add or Remove Buttons → Customize... → Commands tab → button.
Document Format and Selection Format are both under the Edit group.
(Tested in Visual Studio 2010 and Visual Studio 2013)
Windows Shift + Alt + F
MacOS Shift + Option + F
Linux Ctrl + Shift + I
With the Continuous Formatting extension (commercial, developed by me), the code is formatted really automatically as you type.
Visual Studio Extension - CodeMaid is pretty fine.
In Visual Studio 2015 and 2017 for C# code.
Scroll to the end of the file
Remove the last "curly bracket", }
Wait until the line above it shows an error
Replace the "curly bracket", }
Fini. :)
If it's still not working then you can select your entire document, copy and paste and it will reformat.
So ...
Ctrl + A
Ctrl + C
Ctrl + V
This is the only thing that I have found that works in Visual Studio Community Edition on Mac.
It's Shift + Alt + F in Windows.
But you can always double check by doing following.
Go to menu View → Command Palette or press Ctrl + Shift + P
Search for Format Document
You can press that to Auto Format Code or its hot key, written in front of it.
You can also use the CodeMaid Extension.
You can get the extension from Visual Studio Market Place.
Here is the link to the extension. CodeMaid
If you can afford it (or if you're eligible for the 30-day free trial) JetBrains' ReSharper can reformat a whole project directory.
Just install → right-click a directory → select Cleanup Code from the context menu.

Keyboard shortcut for Show All Files

Has anyone found a keyboard shortcut for the "Show All Files" in the Solution Explorer ?
And a related question ... is there any tool that can show the keyboard shortcut for any operation you're doing in VS ?
Cheers,
SteveC.
There is none by default. But:
Go to Tools / Options / Environment / Keyboard.
In 'Show commands containing", type:
showall
Scrolling in the list of commands reveals: Project.ShowAllFiles.
Select it and type the shortcut you want in the "Press shortcut keys" edit box. I used Ctrl + Shift + A.
If what you type as shortcut already has an associated command, you will see it in the bottom of this dialog.
In Visual Studio 2013, use alt + p + o.

Resources