Use Ctrl+Click to Select Word in VS Code - visual-studio

In Visual Studio, if you hold CTRL and click on word, it selects the entire word. If you drag, it selects text word-by-word.
I find this feature of Visual Studio very useful when I'm copy pasting small bits of code, since I can just keep holding CTRL, select words, and press C, X, or V to move stuff around.
In VS Code, you can't do this. Instead, CTRL+CLICK is bound to "Go To Definition".
Is there any way to match the behavior of VS Code with Visual Studio in this context?

As #phuzi said in the comments you can use double click to select the word or double click and drag to select word to word (it will snap on the last character of each word). If you triple-click on a line or click on line num, it will select the whole line (with the invisible character at last '\n').
If you press CTRL + D it will select the word where the cursor is. Also if there are multiple instance of same word you can select them all one after another using CTRL + D.

You can set multiples cursor by doing ALT+CLICK. You will then select multiples parts of your text/code that you could copy and paste very easily.

Using a keyboard hook, you could do something like this:
// release CTRL
INPUT input;
input.type = INPUT_KEYBOARD;
input.ki.wVk = VK_CONTROL;
input.ki.dwFlags = KEYEVENTF_KEYUP;
SendInput(1, &input, sizeof(input));
// double click in place
POINT client;
client.x = msStruct.pt.x;
client.y = msStruct.pt.y;
ScreenToClient(hWnd, &client);
const auto mouseLParam = MAKELPARAM(client.x, client.y);
SendMessage(hWnd, WM_LBUTTONDOWN, 0, mouseLParam);
SendMessage(hWnd, WM_LBUTTONUP, 0, mouseLParam);
SendMessage(hWnd, WM_LBUTTONDOWN, 0, mouseLParam);
SendMessage(hWnd, WM_LBUTTONUP, 0, mouseLParam);
// press CTRL
input.ki.dwFlags = 0;
SendInput(1, &input, sizeof(input));
I have implemented said feature and provided it as a free 3rd party open-source app: https://github.com/dougbenham/CtrlClick

Update for 2022. (Spoiler alert, it is still not here) but there are few catch:
Someone modded the source code
The only promising attempt I found is this attempt on github issue to modify vscode source code to support control click select.
But to really test this you need to be able to build vscode. At the time of writing, his commit is now 10 months old (10000 commits) behind latest and he did not provide any binary build, and I failed to build vscode from source myself so I cannot test this. (npm and yarn is not my domain here)
Which link to this code commit
Turning off ctrl+click for goto definition for now
Although not really a solution to what OP asked. I decided to include this in my answer as other answer did not mention it yet.
For now you can turn off this Ctrl+Click feature with workaround by setting following editor setting to 'ctrlCmd' so that it won't interfere with your copy paste action.
Side note & Background:
Note that I'm using Visual Studio Keymap because I'm still using VS for main development and don't want to lose shortcut I learned.
This extension already bring back VS F12 = 'Go to definition'
And many more such as CTRL+D for line dupe.
Thus this free up CTRLClick from 'Go to definition' because I already has F12 for that.
I also heavily used CTRLClick for 'whole word' selection and Ctrl-click-drag variant of it.

For any AutoHotkey users, here's a script that will give you the functionality (but not the +drag variant, unfortunately).
#IfWinActive ahk_exe Code.exe
~^LButton:: Send {LButton up}{Ctrl up}{Click}^{Left}^+{Right}
You'll still need to follow Wappenull's instructions to change Multi Cursor Modifier to 'ctrlCmd'.
The good thing about doing it this way is that you can use the same script for multiple programs.

I am the author of the source code change mentioned in the other reply. It appears my code will not be merged since it has been over a year.
My code changes can be found here if you want to build from source, but I also uploaded compiled binaries for Windows which can be downloaded in the Release tab.
If you build your own version you will need to modify product.json to get the Extension Gallery to work as described here. You can also install the extension Visual Studio Keymap to get similar key bindings to Visual Studio.
Once in Visual Studio Code you can enable the feature or add the JSON property:
"editor.wordSelection": true

Related

Is there any shortcut to select the current line in Visual Studio?

I couldn't find such feature in VS's shortcut list. Is there anyway?
If you want to copy a line, simply place cursor somewhere in that line and hit CTRL+C
To cut an entire line CTRL+X
#Sean found what I was looking for:
To disable this default behavior remove the checkmark (or check to re-enable)
Apply cut or copy commands to blank lines when there is no selection
Accessed from the menu bar: Tools | Options | Text Editor | All languages
You can also enter copy into the options search box for quicker access
[Tested in VS2008, 2010, 2017]
Clicking the line 3 times does the trick
If you have ReSharper you could use
Ctrl + W
- Extend Selection
Sidenote: You may have to use it multiple times depending on the context of your present text cursor position.
If you click once on the row number the entire row will be selected.
If you want to select a line or lines you can use the combination of ctrl + E then U. This combination also works for uncommenting a complete line or lines. This combination looks somewhat strange to work with, but it will get habituated very soon :)
You can also use Ctrl + X to cut an entire line. Similarly, you can use Ctrl + C to copy an entire line.
As long as you don't have anything selected, these commands will work on the entire line.
Clicking anywhere on the line and (CRTL + C) will copy entire line.
Clicking three time in quick succession also selects entire line.
There is a simple way of doing it, simple use Home or End button to reach the start or end of line, and then use home + shift or end + Shift depending on where your cursor is. Hope it helps.
Use the following:
Shift + End If cursor is at beginning of line.
or
Shift + Home If cursor is at the end of the line.
Alternatively, if you use resharper, you can also use the following
Ctrl + w while the cursor is positioned on the line you want to select
This won't solve the problem for Visual Studio, but if you're using Visual Studio Code you can use CTRL+L to select the line your cursor is currently on.
(If you're using Visual Studio, this will cut the line you're currently on—which may also be useful, but wasn't the question.)
Other answers require either using a mouse or hitting more than one combination.
So I've created a macro for those who want a VSCode-like Ctrl+L behaviour. It can select multiple lines, and that's useful for moving blocks of code.
To use it, install Visual Commander extension for macros: https://marketplace.visualstudio.com/items?itemName=SergeyVlasov.VisualCommander
Then create a new command, select C# as a language and paste this code:
using EnvDTE;
using EnvDTE80;
public class C : VisualCommanderExt.ICommand
{
public void Run(EnvDTE80.DTE2 DTE, Microsoft.VisualStudio.Shell.Package package)
{
var ts = DTE.ActiveDocument.Selection as EnvDTE.TextSelection;
if (!ts.ActivePoint.AtStartOfLine)
ts.StartOfLine();
ts.LineDown(true, 1);
}
}
Now you can assign a desired shortcut in preferences:
Tested in VS 2022.
You can use CTRL + U . This shortcut is use also for uncomment.
You can change the shortcut on this feature. Go to Tools->Options->Environment->Keyboard->Edit.UncommentSelection and assign CTRL+W (same as Resharper) or you can use what shortcut do you want.
If you want to select full row Ctrl E + U
Just click in the left margin.
If you click in the margin just left of the Outline expansions [+][-]
it will select the row.
You can also just click and drag to select multiple lines.
Necvetanov eluded to this in his answer above about clicking on the line number.
This is right...but it just happens that the line number is in the margin.
Here is a whole list of the keyboard shortcuts Default keyboard shortcuts in Visual Studio
a work around for this:
ctrl+d = duplicate line
ctrl+l = copy line
ctrl+v = paste copied text
You can enter, home then shift + end as well. What it will do is take you to the beginning of line then select the whole line till end. Or alternatively first enter end then shift + home
You can set a bind to the Edit.ExpandSelection command:
In the options. Click the shortcut until it selects the whole line.
The screenshot above is from the Edit > Advanced menu in Visual Studio 2022. I set this Alt+E, E shortcut myself and I don't remember if it's originally set to something or not.
Simply by clicking on the line number that's being shown on the left in vs-code. just a single click and a line will get selected.
In Mac, it is ⌘+L.
But if you have some specific conflicting keybindings, this won't work. In my case the VSCode Live Server extension auto registered a couple of bindings for these keys. I removed them and it worked.
I assigned a shortcut key to the following functionality. I press the shortcut until it selects the whole current line:
Edit.SubwordExpandSelection

Favorite Visual Studio keyboard remappings? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 9 years ago.
Stack Overflow has covered favorite short-cuts and add-ins, optimizations and preferences -- great topics all. If this one has been covered, I can't find it -- so thanks in advance for the link.
What are your favorite Visual Studio keyboard remappings?
Mine are motivated by the fact that I'm a touch-typist. Mouse, function keys, arrow keys, Home, End -- bleh. These are commands I do all day every day, so I've remapped them to sequences I can execute without moving my hands from the home row.
The command that is remapped in Tools => Customize => [Keyboard] is shown in parentheses.
I'm 100% positive that there are better remappings than these, so please post yours! Please include the command; oft times, figuring it out is a challenge.
-- Hoytster
Running the app and operating the debugger
Ctrl+Q + Ctrl+R Run the application, in debug mode (Debug.Start)
Ctrl+Q + Ctrl+Q Quit (stop) the application (Debug.StopDebugging)
Ctrl+T Toggle a breakpoint at the current line (Debug.ToggleBreakpoint)
Ctrl+K + Ctrl+I Step Into the method (Debug.StepInto)
Ctrl+K + Ctrl+O Step Out of the method (Debug.StepOut)
Ctrl+N Step over the method to the Next statement (Debug.StepOver)
Ctrl+K + Ctrl+H Run the code, stopping Here at the cursor position (Debug.RunToCursor)
Ctrl+K + Ctrl+E Set then next statement to Execute (Debug.SetNextStatement)
Navigating the code
Ctrl+S Move a character LEFT (Edit.CharLeft)
Ctrl+D Move a character RIGHT (Edit.CharRight)
Ctrl+Q + Ctrl+S Move to the LEFT END of the current line (Edit.LineStart)
Ctrl+Q + Ctrl+D Move to the RIGHT END of the current line (Edit.LineEnd)
Ctrl+E Move a line UP (Edit.LineUp)
Ctrl+X Move a line DOWN (Edit.LineDown)
Ctrl+K + Ctrl+K Toggle (add or remove) bookmark (Edit.ToggleBookmark)
Ctrl+K + Ctrl+N Move to the NEXT bookmark (Edit.NextBookmark)
Ctrl+K + Ctrl+P Move to the PREVIOUS bookmark (Edit.PreviousBookmark)
Ctrl+Q + Ctrl+W Save all modified Windows (File.SaveAll)
Ctrl+L Find the NEXT instance of the search string (Edit.FindNext)
Ctrl+K + Ctrl+L Find the PREVIOUS instance of the search string (Edit.FindPrevious)
Ctrl+Q + Ctrl+L Drop down the list of open files (Window.ShowEzMDIFileList)
The last sequence is like clicking the downward-facing triangle in the upper-right corner of the code editor window. VS will display a list of all the open windows. You can select from the list by typing the file name; the matching file will be selected as you type. Pause for a second and resume typing, and the matching process starts over, so you can select a different file. Nice, VS Team. The key takes you to the tab for the selected file.
OK, it's a community wiki; edit away. :)
Tools -> Options -> Keyboard -> Apply the following additional keyboard mapping scheme -> Emacs
For editing and rearranging I've found the following 3 very useful, even though they're not on the home row:
Keypad + for Edit.Copy
Keypad - for Edit.Cut
Keypad * for Edit.Paste
These are easy to hit (even with the right thumb, at a pinch, if your right hand is holding the mouse) and require no meta keys. I often work by writing snippets then turning it into compilable code using search and replace, and then copying in words from elsewhere. The second step is usually most efficiently done by using the cursor with the mouse, so I've not found it a problem that these keys are so far away from the typing set -- being able to hit them without meta keys is more important.
(For commenting out large swathes of code, the above makes it impossible to use the numeric keypad to quickly add in /* or */. I've taken to using Edit.CommentSelection and Edit.UncommentSelection instead, or Visual Assist's comment selection facility. These have the additional slight advantage of not producing unnestable comments.)
Only other particularly useful shortcuts I find myself stuck without are these two:
Ctrl+Alt+1 for View.FindResults1
Ctrl+Alt+2 for View.FindResults2
The other lesser windows have keyboard shortcuts for them by default; I'm not sure why the Find Results windows don't.
I don't generally remap much (probably due to having to wander around and help others who have default mappings often), but there are two additions / changes I like to make:
Alt+N becomes VAssistX -> Refactor -> Rename... for Visual Assist X (VAssistX.RefactorRename). More recent VAX copies make this Shift+Alt+R automatically, but we were on a version without a keybinding for this, and I became accustomed to Alt+N.
F7 changes to do a Build -> Project Only -> Build Only Project (Build.BuildOnlyProject); Ctrl+Shift+B still builds the solution. Not sure if I'm married to this or not, but I do wish there was a default keyboard shortcut for BuildOnlyProject. Since we're using an external make, Ctrl+F7 (Build.Compile) for a single file doesn't work for us, and I forget it exists half the time when working with other projects.
If you'll allow me to continue to gush over a commercial product, my favorite shortcuts are still VAX's Alt+Shift+S find symbol, Alt+Shift+O open file in solution, and Alt+O open corresponding file. But those are not remappings, they're defaults...
Ctrl+1 - Resharper.UnitTest_ContextRun (Run unit test at cursor position)
Ctrl+2 - Resharper.UnitTest_ContextDebug (Debug unit test at cursor position)
http://www.viemu.com/
It tries very hard to accurately emulate vim. Intellisense and all other features of VS still work perfectly (unlike with all the free vi[m] plugins).
The developer is very friendly and has a very fast turnaround time for feature requests.
I can't use VS without this plugin as a long long time vim user.
ALT+W+U : Hide all tool windows like Watch, Immediate, Output etc. Useful when you wanna focus on the code you're writing

Visual Studio 2010 Formatting

I have plenty of experience with Eclipse, and now I'm trying out Visual Studio 2010. I find its formatting somewhat counter-intuitive. Here are some things I'm trying to figure out:
Is there a way to select all text and format/indent it properly, like SHIFT+A SHIFT+I in Eclipse?
Why is it that when I type a line like if (n == 0) {, as soon as I type the opening brace, the text cursor is moved to the beginning of the line? Is this some productivity speedup I'm failing to see?
When I hit ENTER after the aforementioned line, I'd like the closing brace to be put in place automatically for me. How can I do this?
I've looked for hotkey documentation, and it's helped a bit, but this still feels clunky to me.
The Format Document shortcut key combination is Ctrl K, Ctrl D. Since this command is not supported in C++ ( Visual Studio 2010: Why aren't key combinations available?), the workaround for C++ files is to Select All then Format Selection: Ctrl A, Ctrl K, Ctrl F.
On your second and third question, see Creating and Using IntelliSense Code Snippets. Short version: for if, type "if {TAB} {TAB}". Again, this not supported for C++. So if you're in C++, what you're seeing is when you typed typed the { on the line after the if, what the editor did was move the { to the same indention level as the if (not necessarily the beginning of the line), because the coding style it's helping you achieve is
if (n == 0)
{
n = 1;
}
The formatting commands are by default bound to Ctrl+K Ctrl+??. Ctrl+K as the first keystoke, followed by another key stroke that determines the specific formatting option.
Look at the Advanced submenu of the Edit menu. It will show you that
"format selection" is Ctrl+k Ctrl+f
"comment selection" is Ctrl+k Ctrl+c
To format a document in visual studio the key combination is: ctrl-k ctrl-d
just FYI in eclipse it's: ctrl-a -> ctrl-i
not shift-a -> shift-i
I'm sure I'm the only one that actually tried that in eclipse.

Hidden Features of Visual Studio (2005-2010)?

Locked. This question and its answers are locked because the question is off-topic but has historical significance. It is not currently accepting new answers or interactions.
Visual Studio is such a massively big product that even after years of working with it I sometimes stumble upon a new/better way to do things or things I didn't even know were possible.
For instance-
Crtl + R, Ctrl + W to show white spaces. Essential for editing Python build scripts.
Under "HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\8.0\Text Editor"
Create a String called Guides with the value "RGB(255,0,0), 80" to have a red line at column 80 in the text editor.
What other hidden features have you stumbled upon?
Make a selection with ALT pressed - selects a square of text instead of whole lines.
Tracepoints!
Put a breakpoint on a line of code. Bring up the Breakpoints Window and right click on the new breakpoint. Select 'When Hit...'. By ticking the 'Print a message' check box Visual Studio will print out a message to the Debug Output every time the line of code is executed, rather than (or as well as) breaking on it. You can also get it to execute a macro as it passes the line.
You can drag code to the ToolBox. Try it!
Click an identifier (class name, variable, etc) then hit F12 for "Go To Definition". I'm always amazed how many people I watch code use the slower right-click -> "Go To Definition" method.
EDIT: Then you can use Ctrl+- to jump back to where you were.
CTRL+SHIFT+V will cycle through your clipboard, Visual Studio keeps a history of copies.
Sara Ford covers lots of lovely tips: http://blogs.msdn.com/saraford/archive/tags/Visual+Studio+2008+Tip+of+the+Day/default.aspx
But some of my favourites are Code Snippets, Ctrl + . to add a using <Namespace> or generate a method stub.
I can't live without that.
Check out a great list in the Visual Studio 2008 C# Keybinding poster: http://www.microsoft.com/downloadS/details.aspx?familyid=E5F902A8-5BB5-4CC6-907E-472809749973&displaylang=en
CTRL-K, CTRL-D
Reformat Document!
This is under the VB keybindings, not sure about C#
How many times do you debug an array in a quickwatch or a watch window and only have visual studio show you the first element? Add ",N" to the end of the definition to make studio show you the next N items as well. IE "this->m_myArray" becomes "this->m_array,5".
Incremental search: While having a source document open hit (CTRL + I) and type the word you are searching for you can hit (CTRL + I) again to see words matching your input.
You can use the following codes in the watch window.
#err - display last error
#err,hr - display last error as an HRESULT
#exception - display current exception
Ctrl-K, Ctrl-C to comment a block of text with // at the start
Ctrl-K, Ctrl-U to uncomment a block of text with // at the start
Can't live without it! :)
Stopping the debugger from stepping into trivial functions.
When you’re stepping through code in the debugger, you can spend a lot of time stepping in and out of functions you’re not particularly interested in, with names such as GetID(), or std::vector<>(), to pick a C++ example. You can use the registry to make the debugger ignore these.
For Visual Studio 2005, you have to go to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio \8.0\NativeDE\StepOver and add string values containing regular expressions for each function or set of functions you wish to exclude; e.g.
std::vector.*::.*
TextBox::GetID
You can also override these for individual exceptions. For instance, suppose you did want to step into the vector class’s destructor:
std::vector.*::\~.*=StepInto
You can find details for other versions of Visual Studio at http://blogs.msdn.com/andypennell/archive/2004/02/06/69004.aspx
Ctrl-F10: run to cursor during debugging. Took me ages to find this, and I use it all the time;
Ctrl-E, Ctrl-D: apply standard formatting (which you can define).
TAB key feature.
If you know snippet key name, write and click double Tab. for example:
Write
foreach
and then click tab key twice to
foreach (object var in collection_to_loop)
{
}
2. If you write any event, write here
Button btn = new Button();
btn.Click +=
and then click tab key twice to
private void Form1_Load(object sender, EventArgs e)
{
Button btn = new Button();
btn.Click += new EventHandler(btn_Click);
}
void btn_Click(object sender, EventArgs e)
{
throw new Exception("The method or operation is not implemented.");
}
btn_Click function write automatically
in XAML Editor, Write any event. for example:
MouseLeftButtonDown then click tab
MouseLeftButtonDown="" then click tab again
MouseLeftButtonDown="Button_MouseLeftButtonDown" in the code section Button_MouseLeftButtonDown method created.
Sara Ford has this market cornered.
http://blogs.msdn.com/saraford/default.aspx
More Visual Studio tips and tricks than you can shake a stick at.
Some others:
The Visual Studio 2005 and 2008 3-month trial editions are fully-functional, and can be used indefinitely (forever) by setting the system clock back prior to opening VS. Then, when VS is opened, set the system clock forward again so your datetimes aren't screwed up.
But that's really piracy and I can't recommend it, especially when anybody with a .edu address can get a fully-functional Pro version of VS2008 through Microsoft Dreamspark.
You can use Visual Studio to open 3rd-party executables, and browse embedded resources (dialogs, string tables, images, etc) stored within.
Debugging visualizers are not exactly a "hidden" feature but they are somewhat neglected, and super-useful, since in addition to using the provided visualizers you can roll your own for specific data sets.
Debugger's "Set Instruction Pointer" or "Set Next Statement" command.
Conditional breakpoints (as KiwiBastard noted).
You can use Quickwatch etc. to evaluate not only the value of a variable, but runtime expressions around that variable.
T4 (Text Template Transformation Toolkit). T4 is a code generator built right into Visual Studio
Custom IntelliSense dropdown height, for example displaying 50 items instead of the default which is IMO ridiculously small (8).
(To do that, just resize the dropdown next time you see it, and Visual Studio will remember the size you selected next time it opens a dropdown.)
Discovered today:
Ctrl + .
Brings up the context menu for refactoring (then one that's accessible via the underlined last letter of a class/method/property you've just renamed - mouse over for menu or "Ctrl" + ".")
A lot of people don't know or use the debugger to it's fullest - I.E. just use it to stop code, but right click on the red circle and there are a lot more options such as break on condition, run code on break.
Also you can change variable values at runtime using the debugger which is a great feature - saves rerunning code to fix a silly logic error etc.
Line transpose, Shift-Alt-T
Swaps two line (current and next) and moves cursor to the next line. I'm lovin it. I've even written a macro which changed again position by one line, executed line transpose and changed line position again so it all looking like I swapping current line with previous (Reverse line transpose).
Word transpose, Shift-Ctrl-T
When developing C++, Ctrl-F7 compiles the current file only.
Document Outline in the FormsDesigner (CTRL + ALT + T)
Fast control renaming, ordering and more!
To auto-sync current file with Solution Explorer. So don't have to look where the file lives in the project structure
Tools -> Options -> Projects and Solutions -> "Track Active Item in Solution Explorer"
Edit: If this gets too annoying for you then you can use Dan Vanderboom's macro to invoke this feature on demand through a keystroke.
(Note: Taken from the comment below by Jerry).
I'm not sure if it's "hidden", but not many people know about it -- pseudoregisters. Comes very handy when debugging, I've #ERR, hr in my watch window all the time.
Ctrl-Minus, Ctrl-Plus, navigates back and forward where you've been recently (only open files, though).
I don't use it often, but I do love:
ctrl-alt + mouse select
To select in a rectangular block, to 'block' boundaries.
As noted in comments,
alt + mouse select
Does just a plain rectangular block.
Here's something I learned (for C#):
You can move the cursor to the opening curly brace from the closing curly brace by pressing Control + ].
I learned this on an SO topic that's a dupe of this one:
“Hidden Secrets” of the Visual Studio .NET debugger?
CTRL + Shift + U -> Uppercase highlighted section.
CTRL + U -> Lowercase the highlighted section
Great for getting my SQL Statements looking just right when putting them into string queries.
Also useful for code you've found online where EVERYTHING IS IN CAPS.
Middle Mouse Button Click on the editor tab closes the tab.
To display any chunk of data as an n-byte "array", use the following syntax in Visual Studio's QuickWatch window:
variable, n
For example, to view a variable named foo as a 256-byte array, enter the following expression in the QuickWatch window:
foo, 256
This is particularly useful when viewing strings that aren't null-terminated or data that's only accessible via a pointer. You can use Visual Studio's Memory window to achieve a similar result, but using the QuickWatch window is often more convenient for a quick check.

Changing Ctrl + Tab behavior for moving between documents in Visual Studio

Is it possible to change how Ctrl + Tab and Shift + Ctrl + Tab work in Visual Studio? I have disabled the popup navigator window, because I only want to switch between items in the tab control. My problem is the inconsistency of what switching to the next and previous document do.
Every other program that uses a tab control for open document I have seen uses Ctrl + Tab to move from left to right and Shift + Ctrl + Tab to go right to left. Visual Studio breaks this with its jump to the last tab selected. You can never know what document you will end up on, and it is never the same way twice.
It is very counterintuitive. Is this a subtle way to encourage everyone to only ever have two document open at once?
Let's say I have a few files open. I am working in one, and I need to see what is in the next tab to the right. In every other single application on the face of the Earth, Ctrl + Tab will get me there. But in Visual Studio, I have no idea which of the other tabs it will take me to. If I only ever have two documents open, this works great. As soon as you go to three or more, all bets are off as to what tab Visual Studio has decided to send you to.
The problem with this is that I shouldn't have to think about the tool, it should fade into the background, and I should be thinking about the task. The current tab behavior keeps pulling me out of the task and makes me have to pay attention to the tool.
In Visual Studio 2015 (as well as previous versions of VS, but you must install Productivity Power Tools if you're using VS2013 or below), there are two new commands in Visual Studio:
Window.NextTab and
Window.PreviousTab
Just go remap them from Ctrl+Alt+PageUp/Ctrl+Alt+PageDown to Ctrl+Tab/Ctrl+Shift+Tab in:
Menu Tools -> Options -> Environment -> Keyboard
Note: In earlier versions such as Visual Studio 2010, Window.NextTab and Window.PreviousTab were named Window.NextDocumentWellTab and
Window.PreviousDocumentWellTab.
Visual Studio 2010 has, built in, a way to solve this.
By default, Ctrl+Tab and Ctrl+Shift+Tab are assigned to Window.[Previous/Next]..Document, but you can, through
Tools -> Options -> Environment -> Keyboard,
remove those key assignments and reassign them to Window.[Next/Previous]Tab to add the desired behavior.
it can be changed, at least in VS 2012 (I think it should work for 2010 too).
1) TOOLS > Options > Environment > Keyboard
(Yes TOOLS, its VS2012 !) Now three shortcuts to check.
2) Window.NextDocumentWindow - you can reach there quickly by typing on the search pane on top. Now this is your enemy. Remove it if you dont like it. Change it to something else (and dont forget the Assign button) if want to have your own, but do remember that shortcut whatever it is in the end. It will come handy later.
(I mean this is the shortcut that remembers your last tab)
3) Now look for Window.NextDocumentWindowNav - this is the same as above but shows a preview of opened tabs (you can navigate to other windows too quickly with this pop-up). I never found this helpful though. Do all that mentioned in step 2 (don't forget to remember).
4) Window.NextTab - your magic potion. This would let you cycle through tabs in the forward order. May be you want CTRL+TAB? Again step 2 and remember.
5) Now place cursor in the Press shortcut keys: textbox (doesn't matter what is selected currently, you're not going to Assign this time), and type first of the three (or two or one) shortcuts.
You'll see Shortcut currently used by: listed. Ensure that you have no duplicate entry for the shortcut. In the pic, there are no duplicate entries. In case you have (a rarity), say X, then go to X, and remove the shortcut. Repeat this step for other shortcuts as well.
6) Now repeat 1-5 for Previous shortcuts as well (preferably adding Shift).
7) Bonus: Select VS2005 mapping scheme (at the top of the same box), so now you get F2 for Rename members and not CTRL+R+R, and F7 for View Code and not CTRL+ALT+0.
I'm of the opinion VS has got it right by default. I find it extremely useful that VS remembers what I used last, and makes switching easier, much like what the OS itself does (on ALT+TAB). My browser does the same too by default (Opera), though I know Firefox behaves differently.
In Visual Studio 2012 or later (2013, 2015, 2017...):
Browse the menu Tools / Options / Environment / Keyboard.
Search for the command 'Window.NextTab', set the shortcut to Ctrl+Tab
Search for the command 'Window.PreviousTab', set the shortcut to Ctrl+Shift+Tab
Navigate to the blog post Visual Studio Tab Un-stupidifier Macro and make use of the macro. After you apply the macro to your installation of Visual Studio you can bind your favorite keyboard shortcuts to them. Also notice the registry fix in the comments for not displaying the macro balloon since they might get annoying after a while.
Ctl + Alt + PgUp or PgDn shortcuts worked to toggle next/prev tab out of the box for me...
After a couple of hours of searching I found a solution how to switch between open documents using CTRL+TAB which move from left to right and SHIFT+ CTRL+ TAB to go right to left.
In short you need to copy and paste this macro:
Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports System.Diagnostics
Public Module TabCtrl
Public Sub TabForward()
Dim i As Integer
Dim activateNext As Boolean = False
For i = 1 To DTE.Windows.Count
If DTE.Windows().Item(i).Kind = "Document" Then
If activateNext Then
DTE.Windows().Item(i).Activate()
GoTo done
End If
If DTE.Windows().Item(i) Is DTE.ActiveWindow Then
activateNext = True
End If
End If
Next
' Was the last window... go back to the first
If activateNext Then
For i = 1 To DTE.Windows.Count
If DTE.Windows().Item(i).Kind = "Document" Then
DTE.Windows().Item(i).Activate()
GoTo done
End If
Next
End If
done:
End Sub
Public Sub TabBackward()
Dim i As Integer
Dim activateNext As Boolean = False
For i = DTE.Windows.Count To 1 Step -1
If DTE.Windows().Item(i).Kind = "Document" Then
If activateNext Then
DTE.Windows().Item(i).Activate()
GoTo done
End If
If DTE.Windows().Item(i) Is DTE.ActiveWindow Then
activateNext = True
End If
End If
Next
' Was the first window... go back to the last
If activateNext Then
For i = DTE.Windows.Count To 1 Step -1
If DTE.Windows().Item(i).Kind = "Document" Then
DTE.Windows().Item(i).Activate()
GoTo done
End If
Next
End If
done:
End Sub
End Module
The macro comes from: www.mrspeaker.net/2006/10/12/tab-un-stupidifier/
If you never add a macro to Visual Studio there is a very useful link how to do it.
The philosophy of the Visual Studio tab order is very counterintuitive since the order of the displayed tabs differs from the tab-switching logic, rendering the ordering of the tabs completely useless.
So until a better solution arises, change the window layout (in Environment->General) from tabbed-documents to multiple-documents; it will not change the behaviour, but it reduces the confusion caused by the tabs.
That way you will also find the DocumentWindowNav more useful!
I'm 100% in agreement with Jeff.
I had worked on Borland C++ Builder for several years and one of the features I miss most is the 'correct' document tabbing order with Ctrl-Tab. As Jeff said, "The current tab behavior keeps pulling me out of the task and makes me have to pay attention to the tool " is exactly how I feels about this, and I'm very much surprised by the fact that there aren't many people complaining about this.
I think Ctrl-F6 - NextDocumentWindowNav - navigates documents based on the document's last-activated time. This behavior is a lot like how MDI applications used to behave in old days.
With this taken this into account, I usually use Ctrl+F6 to switch between 2 documents (which is pretty handy in switching between .cpp and .h files when working on c++ project) even when there are more than 2 currently opened documents. For example, if you have 10 documents open (Tab1, Tab2, Tab3, ...., Tab10), I click on Tab1 and then Tab2. When I do Ctrl+F6 and release keys, I'll jump to Tab1. Pressing Ctrl+F6 again will take me back to Tab2.
I guess you want what VSS calls Next(Previous)DocumentWindow. By default, it's on Ctrl(-Shift)-F6 on my VSS 8. On Ctrl(-Shift)-Tab they have Next(Previous)DocumentWindowNav. You can change key assignments via Tools/Options/Keyboard.
In registry branch:
HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\9.0
add DWORD named "UseMRUDocOrdering" with value of 1.
It will order documents so most recently used are placed on the left. It's not perfect but better than the default misbehaviour.
Updated to VS 2017+, where, according to #J-Bob's comment under #thepaulpage's answer, (emphasis added):
Looks like the commands have changed again. It's now 2017 and the keyboard shortcuts are called Open Next Editor and Open Previous Editor. You don't need any extensions for this.
You can find the options under Settings, which can be accessed via the gear symbol in the lower left, or by the [Ctrl]+, command.
I feel the top answer at the moment is outdated. In Visual Studio 2021 (v1.56), you do not need to install any extensions or mess around with any configuration files. You simply need to do the following steps:
Click the gear icon in the bottom-left.
Select 'Keyboard Shortcuts'.
Search for 'workbench.action.previousEditor' and 'workbench.action.nextEditor' and edit their keybindings by clicking the pencil icon on the left side of the row.
If you do change to 'Ctrl+tab' or any other shortcut that is already in use by another command, it will let you know and give you the option to change those. I personally changed them to 'Ctrl+PgUp' and 'Ctrl+PgDn' so it was just a straight swap.
I don't use Visual Studio (yes, really, I don't use it), but AutoHotkey can remap any hotkey globally or in a particular application:
#IfWinActive Microsoft Excel (application specific remapping)
; Printing area in Excel (# Ctrl+Alt+A)
^!a::
Send !ade
return
#IfWinActive
$f4::
; Closes the active window (make double tapping F4 works like ALT+F4)
if f4_cnt > 0
{
f4_cnt += 1
return
}
f4_cnt = 1
SetTimer, f4_Handler, 250
return
f4_Handler:
SetTimer, f4_Handler, off
if (f4_cnt >= 2) ; Pressed more than two times
{
SendInput !{f4}
} else {
; Resend f4 to the application
Send {f4}
}
f4_cnt = 0
return
These are two remappings of my main AutoHotKey script. I think it's an excellent tool for this type of tasks.

Resources