How to navigate back to the last cursor position in Visual Studio? - visual-studio

What is the keyboard shortcut navigate back to the last cursor position in Visual Studio?

It Will not work for red color (-) key. For me it only works for blue color combination.

According to Visual C# 2008 Keybinding Reference Poster it is Ctrl + -. The name of the specific keybinding is View.NavigateBackward.
PS: While researching I also found that Ctrl + . is the same as Shift + Alt + F10. Nice!

ctrl + - (dash) navigates backward.
ctrl + shift + - (dash) navigates forward.
These settings can be found under Environment -> Keyboard:

For Changing the setting in Visual Studio 2019:
Search for view.navigate
CHOOSE "Text Editor" from the "Use new shortcut in:" drop down menu
Select your shortcut
Global doesn't catch for this.

For new VS Code(1.28.2)
Back: Ctrl+Alt+- (dash)
Forward: Ctrl+Shift+- (dash)

The most generic answers is: there is no working default and you need to define your own keyboard shortcuts for View.NavigateBackward and View.NavigateForward.
Why? For most keyboards, the default shortcut is a broken, unusuable combination because VS badly handles the shift and altGr modifiers. MS did not pay attention to portability and internationalisation so much when they redeveloped VS after version 6, and this is still true today. This bug has been there for way more than a decade, nearly two decades. At this rate, it will never be fixed. And yes, I have filled a bug report, and I'm certainly not the only one.
However, their "VSCode" product line does have better keyboard handling as it doesn't depend on the shift or altGr modifiers to identify the key. For example, when you are in text writing mode and press the key that has the dash symbol, without using shift nor altGr, let's say it writes something else, like number 6. To VSCode when it comes to shortcut handling, that's still the dash key for its purpose. As long as a key has the symbol written on it, whether this is painted as the 1st, 2nd or 3rd level doesn't matter, it just that key.
Of course, it's never a good thing to make the default shortcuts use non-alphanumeric symbols, that's always confusing, whether it works or not. The good mature text editors have known that for a long time and should be taken as examples of things done right. In some ways, VS learned a few good things from emacs with shortcuts that are a sequence of two letters, but ultimately screwed up on other parts with the choice of non-alphanumeric bindings, combined with a broken low-level keyboard handling.

This works for me in Visual Code
Navigate backward Alt+←
Navigate forward Alt+→

Related

Does Visual Studio have a begin selection/set mark command like Emacs?

In Emacs, one can begin a selection (more accurately "set the mark") by pressing Ctrl-Space. Then, one can navigate around the file, e.g. by pressing End to go to the end of the current line, and the selection will follow the caret.
There is more to the Emacs mark than that, but my question is:
Does Visual Studio 2013 have a way to begin a selection at the caret and have the selection follow the caret until ESC is pressed, or something similar? Visual Studio has a command called "Edit.EmacsSetMark", but it does not seem to work for me.
I only know of SHIFT + cursor keys (including PgUp/PgDn, Home/End, and most of them also with Ctrl). Could take a bit of practice in your case, but very convenient IMO. The selection is cleared as soon as you use a cursor key with SHIFT released.
Even rectangular selections are supported if you also press ALT.
Then there is also the mouse of course. With variations by using SHIFT (extend selection) and ALT (rectangular).
Not that I know of for 2013, but you could do it in 2010 with this...a link

Keyboard Shortcuts in Visual Studio for faster coding

Visual Studio autocompletes brackets and tags and then shifts the cursor inside a bracket/tag upon creation.
I usually have to hit END then ENTER to continue past the tag, it would be really useful to 'jump' over the closing tag/bracket and possibly to the next line.
Is there a fundamental keyboard shortcut I'm missing here in order to accomplish this?
Can't find this in the MSDN VS Keyboard Shortcut manual either.
The keyboard shortcut you are looking for is Ctrl + Shift + Enter.
Pressing this will take you to the next line instead of inserting an enter, allowing you to move the cursor outside of the tag.

Windows 7 Map CTRL + j to the Down Arrow Key

I have been searching for months for a way to map a key combination (CTRL + something) to a directional key (like down or up).
I desperately want in Visual Studio to be able to press CTRL + j and have the cursor move down a line. I hate having to move my hands off of the home row to move up and down for things like intellisense or even just navigating up and down lines.
Does anyone have a solution for this? I would be ok with a Visual Studio-only solution, but something that works at the OS level would be ideal since this kind of navigation would be nice in any editor window and for instance SQL Server Management Studio also has intellisense.
I haven't considered any macro hotkey type solutions since they could conflict with in-app hotkeys (for instance if CTRL+j were assigned to something in Visual Studio already)
I think the answer is nothing out there exists that would do this. I have done a lot of research.
I am now using Autohotkey instead of what would have been ideal. I have been familiar with this application for years and it does a pretty good job, but doesn't work across remote desktop for instance and so doesn't quite fill the need.
I mapped ctrl + i to do up, ctrl + k to be down, ctrl + j as left and ctrl + l for right.
VS-only solution is simple.
At least in Visual Studio 2017 you can assign Ctrl+XXX key combinations to corresponding commands for Text Editor.
CharLeft
CharLeftExtend
CharRight
CharRightExtend
LineUp
LineUpExtend
LineDown
LineDownExtend
PageUp
PageUpExtend
PageDown
PageDownExtend
LineStart
LineStartExtend
Delete
DeleteBackwards
WordPrevious
WordPreviousExtend
WordNext
WordNextExtend
and so on.
All using standard Tools / Options / Environment / Keyboard settings dialog.

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.

Strange visual studio 2008 behavior when pressing keys

Every once in a while I'll do something that causes strang behavior when pressing certain keys.
1)The single quote key (') will not type a character unless I press it twice, in which case it will print two backwards single quote characters (``).
2)The ` (backwards single quote?) key types a # character.
3)The angle bracket keys (< and >) type a single quote (') and a period (.).
4)Shift + any A-Z character types the character and brings the code completion window up.
I'm sure there's other symptomps, and they only want I've found to stop it is to restart Visual studio. This behavior does not appear in any other apps. Anybody experience this?
I started getting this on my computer (not in Visual Studio, but everywhere else). I had default input language set to "English(New Zealand) - United States-International", whatever that is supposed to mean. Changed it to English-US. Disabled the "Language Bar"
"Control Panel >> Regional Settings >> Languages, click on Advanced, look at Installed Services. See if you have multiple choices - if you have an "International" option, remove it and I believe the problem will go away. It did for me.
AFAIK, this happened when I installed XP-SP3.
You probably have an alternate input language set up (try typing ` a when this happens and you'll get à). I think the default hotkey to switch between input languages is Ctrl+Shift, so you're probably hitting it by accident occasionally. Use the language settings control panel to turn off the hotkey or remove the unwanted keyboard configuration.
I have a laptop/keyboard which can be used for French-Canadian. Alternative key-meanings are printed on some keys (in green) ... and they match the keys you mentioned, i.e.:
alt of ' is ``
alt of ` is #
alt of < and > are ' and .
I have an edition of Vista installed that knows about French-Canadian. On the right-hand end of the O/S Taskbar, near the clock, there's a keyboard icon. It's usually set to "US but if I set it to "Canadian French" then I get the key mappings you describe.
Something similar (i.e. changing the language-specific interpretation of the keyboard) must be happening on your machine too. You say it's in Visual Studio, but for me I find it in my O/S.
If you have multiple languages on your machine, then you probably triggered this behavior by pressing ctrl+shift, which causes windows to switch the system language for the active window.
You can either press it again, or better yet, disable the language bar and all other secondary languages.
Like others have said, you can press ctrl-shift to "loop" through the settings.

Resources