i have managed to make a code snippet and its all good, the question is i dont want to use ctrl+k ctrl +S then click on the snippet , instead i want to use a combination of keys to just use the snippet right away , or at least pressing ctrl+k ctrl + S then another combination ?
is that possible ?
thanks in advance...
If you say you're pressing Ctrl+K, Ctrl+S is because the snippet you added was a Surround With snippet, isn't it?
I suggest you installing ReSharper for this purpose. You can easily add all kind of snippets (called templates in ReSharper), and of course, Surround-With snippets.
After adding a template, you can give it the number you want.
Then all you have to do is press: Ctrl+Alt+J and you will see the following:
And all you have to do is press the number of the snippet you want.
For example, if you want to surround some code with an if, you press: Ctrl+Alt+J, 1.
Note:
In this moment, I don't really remember if Ctrl+Alt+J is the keyboard shortcut by default, because I have changed many of them, but you can check it in ReSharper > Edit > Surround With Template...
Easier than typing a key-combination is just typing the name+[Tab]+[Tab]. Visual Studio is pretty good at remembering the last ones used to make it even easier.
"f+[tab]+[tab]" creates a for loop snippet.
In your code snippet file, you can set up a shortcut element. Your code snippets are located under(depending on language):
"\Documents\Visual Studio 2010\Code
Snippets\Visual C#\My Code Snippets"
Under the CodeSnippet\Header\Shortcut section in the code snippet file, type a unique short relevant series of characters.
<CodeSnippet>
<Header>
<Shortcut>spi</Shortcut>
</Header>
Typing these characters followed by tab in the code window will insert your code snippet.
Related
So, I have some code for a Rect variable mageSection:
And I'd like to copy the same code for a different variable warriorSection. To achieve this:
So I'd like to know if there is a visual studio shortcut for allow you to change variable name in multiple line in visual studio without refactoring the whole variable name.i.e. I don't have to manually change those names from mageSection to warriorSectionfor these 4 lines.
It is a question about shortcut in visual studio rather than writing functions, as I'd like to know the shortcut for this. Many thanks!
Copy and paste the section of code.
Now select the pasted code and hit Ctrl-H to bring up the Quick Replace dialog.
In the top box, type "mageSection".
In the bottom box, type "warriorSection".
Hit Enter and it will find the first occurrence and replace it.
Hit Enter three more times...done.
If I'm understanding your question correctly you should be able to hold down alt while clicking into multiple lines and change them all at once. Then hit ESC to exit multiline editing.
I review a lot of code and I want to put brackets around certain text elements that lacks them. So far I've been been doing the following:
1) Highlighting the text element I want to put brackets around (only one highlight at a time)
2) Hit ctrl-k + ctrl-s to invoke the "Surrond With..." shortcut (see Edit->IntelliSense->Surround With...
3) Find my "insert bracket" code snippet and then hitting enter
I want to keybind a specific snippet to do this in one go (just like when you are commenting out a block using the keybind ctrl-k + ctrl-c. Is this possible?
This question is smiliar to Assign code snippet to keyboard shortcut in Visual Studio but its not marked as answered. Can anyone help confirm that its not possible or whether another work-around is possible.
Whenever I hit the key after a keyword that comes from the list of code snippets, Visual Studio always inserts the code snippet.
However, this is very disturbing when I want to add one-line comments to existing code. I can't, for example, add a TAB character after the else keyword.
What keyboard combination do I have to press in order to get a TAB character inserted here?
Your help is appreciated.
A simple workaround for your else scenario is to insert a space and then the tab character, then remove the space.
If you want to make changes to snippets, you can do this by going to Tools -> Code Snippets Manager (Ctrl-K, Ctrl-B) and select the snippet you wish to modify. The path to the .snippet file will be shown. You can just open the file in a text editor and modify it to do the action you want.
In visual Studio aspx editor, i want to stop portion of the code to be formatted on format using ctrl - K ctrl - D .
Problem faced.
I am using two validator with text '*', both should be in same place i adjusted using css. But when format the code , this formatting introduce extra space.
If anybody knows the solution for this, please answer for it.
Expectation:
I am expecting a marker tag, to stop alignment.
For example,
<DontChange><asp:....>......</asp:....>
</DontChange>
When i give like this content between DontChange tag should not be aligned in Editor on every align.
This is an excellent question. Does highlighting the code block and selecting Edit->Advanced->Format Selection (or press Ctrl+K, Ctrl+F) work?
I don't think it's possible. Somehow VS would have to remove the extra tags when you build/deploy. I belive a simple <%-- --%> comment somehow should disable the formatting, but I haven't found anything yet :(
Perhaps an extension/plugin could do the trick?
I'm using Notepad++ as an editor to write programs in Python. It might sound daft but I looked around in the editor and could not find any means (not the manual way but something like in Emacs) to do a block comment in my code.
Since so many language settings are supported in Notepad++, I'm curious to find a way to block comment code.
CTRL+Q Block comment/uncomment.
See Keyboard And Mouse Shortcuts - Notepad++ Wiki.
Try the following shortcut:
Ctrl+K.
This link was exactly what I was searching for .
Let me summarize the answers for others' benefit (for python and notepad++)
1) Ctrl+K on multiple lines (i.e. selected region) allows you to block comment.
Also note that pressing the combination multiple times allows you to add multiple "#"s (sometimes I use that while testing to differentiate from other comments)
2) Ctrl+Shift+K (on the commented region) allows you to perform block uncomment
3) Ctrl+Shift+K on an uncommented selected region does not comment it
4) Ctrl+Q allows you to block comment/uncomment in a toggled mode (meaning, you cannot add multiple '#'s like in 1) )
Hope this helps another wandering soul.
Question - how would you develop a hack of keyboard combinations to comment/uncomment if there were no shortcuts? Just curious. I've no clue hence asking.
Yes in Notepad++ you can do that!
Some hotkeys regarding comments:
Ctrl+Q Toggle block comment
Ctrl+K Block comment
Ctrl+Shift+K Block uncomment
Ctrl+Shift+Q Stream comment
Source: shortcutworld.com from the Comment / uncomment section.
On the link you will find many other useful shortcuts too.
for .sql files Ctrl+K or Ctrl+Q does not work.
to insert comments in .sql files in Notepad++ try Ctrl+Shift+Q
(there is no shortcut to uncomment the code block though. I have tried that on v5.8.2 )
Use shortcut: Ctrl+Q.
You can customize in Settings
In your n++ editor, you can go to
Setting > Shortcut mapper
and find all shortcut information as well as you can edit them :)
Two ways for block commenting:
Ctrl+Shift+Q
or
Select the block
Alt + Right click
Choose block comment.
Without having selected a language type for your file there are no styles defined. Comment and block comment are language specific style preferences. If that's a PITA...
To select for multi-line editing you can use
shift + alt + down arrow
To add a comment under any code on NOTEPAD++ first we have to save and define the programming or scripting file type. Like, save the file as xml, html etc. Once the file is saved in proper format you will be able to add a comment directly using the shortcut ctrl+Q
Just select the desired line and click on Ctrl + Q
Ps: I am using Notepad++