46

I know that Visual Studio has some tools for fast surrounding by code snippets, for example how to do more faster try/catch code blocks. but I can't find a hotkey combination to do this. Who knows the hotkey combination for try/catch?

apereira
  • 426
  • 12
  • 20
asolovyov
  • 903
  • 1
  • 10
  • 21

3 Answers3

106

Press "Ctrl + K, S" and then in drop down menu double click "try" - it's a "try-catch" template.

Sasha
  • 1,676
  • 1
  • 16
  • 18
  • 7
    +1 for the answer. Select the code first and then press `Ctrl+K,S` – Habib Nov 28 '12 at 09:54
  • 8
    Here's a rather inappropriate tip to help remember this shortcut: KS (kamasutra) is a rather popular condom brand in India. Whenever, you need to "surround" something...ahem..you just use ctrl + K,S – arviman Sep 09 '15 at 10:04
  • 3
    Although in spirit correct its `ctrl + K, ctrl+S` if you do that combination VS would not recognize it. This is more to the point: [link](https://stackoverflow.com/a/13602070/1242782) – apereira Jan 25 '18 at 14:42
  • 2
    A more appropriate way to remember this shortcut is that it takes you to the *K*eyboard *S*hortcuts – cstrutton May 01 '19 at 15:03
  • @Habib, what if i want to add try-catch directly without selecting any line, like before typing some code, is there any short cut in this case?? – Vivek Thummar Oct 29 '21 at 10:18
  • Vivek Thummar, the same shortcut works – Pradeep Mar 22 '22 at 21:02
  • This does not seem to work in python files – sam Jun 12 '23 at 08:10
28

Try Ctrl + K, Ctrl + S.
Source

Daniel Hilgarth
  • 171,043
  • 40
  • 335
  • 443
1

Press Ctrl + K, followed by CTRL + S Type T Press Enter or Tab

pmh
  • 192
  • 10