Using Mac Keyboard Shortcuts for Home/End in Visual Studio
Overview
Using Visual Studio (in Parallels) on my Mac works pretty well, except when I try to use Command+Arrow to move to the beginning or end of a line. When you press Command+Arrow in Visual Studio on a Mac, the window moves around the screen, which is quite surprising and not at all helpful.
I did some research and found some useful information about mapping Mac Keyboard Shortcuts to Visual Studio (and Windows) in the following areas:
- http://hiltmon.com/blog/2013/10/10/using-mac-navigation-keys-in-visual-studio/
- Comments from the post in #1 above
- https://autohotkey.com/board/topic/60675-osx-style-command-keys-in-windows/
The information above basically involves using AutoHotKey to remap the keys and then modifying the keyboard shortcuts in Visual Studio to get the desired result.
Below is a summary of the steps required to use Mac keyboard shortcuts such as Command+Left Arrow from within a Parallels or similar Windows VM and Visual Studio.
Note this tutorial is for Windows 10 and Visual Studio 2015.
Steps
- Install AutoHotKey
- Download the MacKeyboard.ahk file (note this modifies more than just Visual Studio keys and incorporates changes from the links above.The file is a fork from here).
- Setup the .ahk file to run at startup
- Type Command+R to open the run window, then type shell:startup
- Copy the MacKeyboard.ahk file into the startup folder.
- Type Command+R to open the run window, then type shell:startup
- Open Visual Studio
- Press Ctrl+Q and type Keyboard to open keyboard settings.
- Type “Edit.LineStart” in “Show commands containing” to select the LineStart command
- Select “Text Editor” in the “Use new shortcut in:” box
- Type Shift+Control+Option+Left Arrow into “Press shortcut keys:” and click Assign
- Click OK to close the Options window.
- Double click on the MacKeyboard.ahk script to run it.
- Open a project in Visual Studio and Command+Left Arrow should bring your cursor to the home position. Alt+Left Arrow should move a word at a time.