Visual Studio Shortcut: Definition (F12) and Peek Definition (Alt+F12)

less than 1 minute read

I’m sure I press F12 many times a day because it goes to the definition and it’s awesome, especially when you have a code base you don’t fully understand or maybe you forget what a particular method does. Simply place the cursor on the method name and press F12 and it will open the file and/or go directly to the code.

Peek Definition , Alt+F12, added in 2013 is even better as you don’t have to leave your current window, you can even switch to the other floating window by pressing Shift+Esc, make some changes and then press Esc to go back to what you were doing. In this case it's actually in the same file, press Alt+F12 puts the focus on the 'Peek Window' In this case it’s actually in the same file, press Alt+F12 puts the focus on the ‘Peek Window’ I didn’t realise you can can keep going through the definitions by pressing Alt+F12 on another and navigate them using Ctrl+Alt+= and Ctr+Alt+-.

With these sort of features there’s really no excuse to split up your code into logical chunks and refactor your methods. It also has the bonus of making your code self documenting, easier to read and probably easier to test.

Leave a Comment