keyboard shortcuts

How to switch desktops when Hyper V steals your focus

I currently run Windows 10 as my main OS, yet I often run Windows 8.1 in a virtual machine under Hyper V to work on a project no longer supported in Windows 10. This is quite practical now that multiple desktops are supported out of the box: I typically run Windows 8.1 in full screen on a separate desktop, so it does not interfere with my other desktop(s).

Tip: In Windows 10, press the Windows key + Ctrl + D to create and switch to a new desktop. Hold down Ctrl and the Windows button while pressing the right or left arrow to switch between desktops. You can also use win + Tab, and click the desktop-icons at the bottom of the screen to switch between them.

One thing I found annoying was the difficulty of switching away from Hyper V and Windows 8.1, since the virtual machine will typically steal the focus. I’ve found a relatively simple solution now though: When the focus is in Hyper V, Ctrl + Alt + Left arrow will move it out and into the outer context – in my case away from my virtual Windows 8.1 machine, and back out to Windows 10. This shortcut is probably not new, but I was unaware of it until recently.

In short:

  • To move from a regular Windows 10 desktop and right into a full screen windows 8.1 desktop, I’ll use: Ctrl + Windows + arrow key.
  • To move back out from Windows 8.1, I’ll first press Ctrl + Alt + left arrow, followed by Ctrl + Windows + arrow key.

This may sound a little awkward, but I’ve found it surprisingly easy to get used to, and as far as I can tell, this appears to be the easiest way to escape from a VM.

Replace a string with newline in emacs

I sometimes find myself wanting to replace certain strings in a text file with a new-line character. Not with “\n” or “\r\n” mind you, but an actual break to make the text more readable in the editor. Take for example a random stack trace from Visual Studio. I sometimes copy these out to another simpler text editor to examine them closer. The problem is that when pasted, they will appear as a single line with “\r\n” instead of actual line breaks:

at System.Windows.Forms.UnsafeNativeMethods.CoCreateInstance(Guid& clsid, Object punkOuter, Int32 context, Guid& iid)\r\n at System.Windows.Forms.AxHost.CreateWithLicense(String license, Guid clsid)\r\n at System.Windows.Forms.AxHost.CreateInstanceCore(Guid clsid)\r\n at System.Windows.Forms.AxHost.CreateInstance at System.Windows.Forms.AxHost.GetOcxCreate()\r\n at System.Windows.Forms.AxHost.TransitionUpTo(Int32 state)\r\n at System.Windows.Forms.AxHost.CreateHandle()\r\n at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)\r\n at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)\r\n at System.Windows.Forms.AxHost.EndInit()\r\n at MyApplication.frmPrint.InitializeComponent() in (...)

If your text editor breaks lines at the edge of the window, it might look more like this:

at System.Windows.Forms.UnsafeNativeMethods.CoCreateInstance(Guid& 
clsid, Object punkOuter, Int32 context, Guid& iid)\r\n at 
System.Windows.Forms.AxHost.CreateWithLicense(String license, Guid 
clsid)\r\n at System.Windows.Forms.AxHost.CreateInstanceCore(Guid 
clsid)\r\n atSystem.Windows.Forms.AxHost.CreateInstance at 
System.Windows.Forms.AxHost.GetOcxCreate()\r\n at 
System.Windows.Forms.AxHost.TransitionUpTo(Int32 state)\r\n at 
System.Windows.Forms.AxHost.CreateHandle()\r\n at 
System.Windows.Forms.Control.CreateControl(Boolean 
fIgnoreVisible)\r\n at System.Windows.Forms.Control.CreateControl(Boolean 
fIgnoreVisible)\r\n at System.Windows.Forms.AxHost.EndInit()\r\n at 
MyApplication.frmPrint.InitializeComponent() in (...)

..which may be better, but still not very readable.

Most text-editors have some form of replace-all utility built in, but it’s not always easy to replace “\r\n” with an actual line shift (try it!). In Emacs, there is a nice way to handle this:

Use M-x Replace-String to prompt for the string to replace. Enter “\r\n” in the mini-buffer. Press enter, and it will prompt for the string to replace it with. At this point, use C-q C-j to input a new-line (C-j) as quoted text (C-q), and press enter again.

The result will be a much more readable stack trace:

at System.Windows.Forms.UnsafeNativeMethods.CoCreateInstance(Guid& clsid, Object punkOuter, Int32 context, Guid& iid)
at System.Windows.Forms.AxHost.CreateWithLicense(String license, Guid clsid)
at System.Windows.Forms.AxHost.CreateInstanceCore(Guid clsid)
at System.Windows.Forms.AxHost.CreateInstance at System.Windows.Forms.AxHost.GetOcxCreate()
at System.Windows.Forms.AxHost.TransitionUpTo(Int32 state)
at System.Windows.Forms.AxHost.CreateHandle()
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.AxHost.EndInit()
at MyApplication.frmPrint.InitializeComponent() in (...)

Visual Studio Peek Definitions

I just recently discovered the new Peek Definitions feature in Visual Studio 2013, and thought I’d share a short post about it. There is a pretty comprehensive description of it here, so this is just a short summary and example of the basics. You’ll find a list of the most important keyboard shortcuts at the end of this article.

Peeking at the implementation of a method.

 

Continue reading