Adding Visual Studio Shortcut to Close currently opened File


You might know that Ctrl + W is a shortcut key for many browsers like Internet Explorer, Firefox, Chrome etc. to close the tab bar items. If you have tabs in the open tab bar and want to close the currently open tab, you can use Ctrl + W shortcut key instead of clicking the close button.

 

In Visual Studio, you might want to do the same. Suppose you have a no. of documents open in your tab and you want to close some of them with a shortcut instead of clicking one by one. How can you do that? Read the post to configure your Visual Studio IDE to assign a shortcut for it.

 

 

Let us again describe here what we want to achieve by this post. Suppose we have a no. of open documents inside Visual Studio, you will see all of them in the tab bar as shown below:

 

image

 

Now sometime it is very difficult to close them one by one by clicking the close button. Ever imagined of a way to use a shortcut to handle it just like we do for the internet browsers? Let me tell you that, there are no shortcut assigned for this. So, let's create our own shortcut key for that.

 

To do this open the Options page from the Tools menu as shown below:

 

image

 

In the options dialog expand the "Environment" tree node from the left panel. There you will find a link called "Keyboard". Click that to open up the Keyboard settings page at the right side. There you will see a input box called "Show commands containing". This textbox searches for the input command in the list just below it.

 

Have a look into the following screenshot:

 

image

 

In the input box type "File.Close" and you will see the command filtered in the list. This command executes instruction to the Visual Studio IDE to close the currently open document. Select the command from the list.

 

Now, the 2nd step is to select the proper location to store a shortcut key for it. Select "Global" as the "Use new shortcut in" dropdown. This will make sure that your shortcut for the command will store in the global settings and will be applicable to any instance of the Visual Studio IDE all over the time.

 

image

 

As the 3rd step, click on the textbox "Press shortcut keys" and enter your desired shortcut key by pressing the respective keyboard keys. In our case, we will use "Ctrl + W". Press "Ctrl" and "W" to enter the key combination in the box.

 

image

 

As shown above once you entered the shortcut key, click "Assign". This will store the key combination for the selected command and you will see the following changes in the dialog:

 

image

 

 

Click "OK" in the dialog box to continue. Now you will be able to close the open document file just by pressing "Ctrl + W" key combination.

 

Hope you enjoyed reading this post. This small tip will help you to quickly close the open documents. Hence, happy coding and enjoy your daily experiences with Visual Studio IDE.

 


5 comments

  1. Nice post. Good to know about customizing and assigning new shortcut keys. There is an existing shortcut for all the tabbed interfaces in Windows which can be used with softwares like Internet Explorer, Visual Studio, Word, Excel etc which support tabbed documents. We can close the current active tab with the combination of Ctrl + F4.

    ReplyDelete
  2.  Woo! Good to know that. Thanks for sharing it.

    ReplyDelete
  3. Nice Tip. Thank you for sharing it. Good Job.

    ReplyDelete
  4. Though it is simple but very helpful. Yes some time it is difficult to click and click to close the document. This CTRL+W shortcut will help to easily close the open document which is not require at the time of pressing CTRL+TAB. As those keys are side by side, will take very few steps to switch and close the document.

    Thanks Kunal for sharing such a nice Tip.

    ReplyDelete
  5. Thanks for sharing! I appreciate it!

    ReplyDelete


 
© 2008-2014 Kunal-Chowdhury.com | Designed by Kunal Chowdhury
Back to top