Questions tagged [code-snippets]

For issues relating to the creation, use, and maintenance of code snippets.

A snippet is a small region of re-usable source code, machine code or text. Ordinarily, these are formally-defined operative units to incorporate into larger programming modules. Snippets are often used to clarify the meaning of an otherwise "cluttered" function, or to minimize the use of repeated code that is common to other functions.

Snippets can be created and used in many newer IDEs to insert a nearly functional code. With placeholders it is then possible to tab through the missing parts and fill in the variable names of other missing code parts.

For a fast practical use of a theoretical concept it is often preferred to show it on a snippet as an excerpt of the used code with the variable names foo and bar.

1929 questions
37
votes
3 answers

Formatting Literal parameters of a C# code snippet

Is there any way that I can change how a Literal of a code snippet renders when it is used in the code that the snippet generates? Specifically I'd like to know if I can have a literal called say, $PropertyName$ and then get the snippet engine to…
Michael Lang
  • 2,157
  • 3
  • 22
  • 29
36
votes
4 answers

Intellisense not working in code snippets - VS Code

I have installed the C# extension in VS Code. The problem I am having is, after using a code snippet prop, Intellisense no longer suggests variable types. This happens with other things like ctor as well, it will not autocomplete the class name, for…
34
votes
4 answers

WebStorm functional snippet React

Does anybody knows what the shortcut is for React functional components snippet in WebStorm? So far I only found shortcut for class components.
34
votes
8 answers

Sphinx, reStructuredText show/hide code snippets

I've been documenting a software package using Sphinx and reStructuredText. Within my documents, there are some long code snippets. I want to be able to have them hidden as default, with a little "Show/Hide" button that would expand them…
Adam Matan
  • 128,757
  • 147
  • 397
  • 562
34
votes
2 answers

How do you put HTML or XML into a YAML?

I would like to store HTML snippets inside a YAML file. What is the best way to do that? Something like: myhtml: |
Piotr Zolnierek
  • 1,030
  • 1
  • 10
  • 19
31
votes
2 answers

Edit Sublime Text 2's default snippets

I've been using Sublime text 2 for the past few days, and I have to say it's been amazing! I have added many snippets already, but can't figure out how to edit Sublime's default snippets like the script element (script+tab). In my opinion the script…
Web_Designer
  • 72,308
  • 93
  • 206
  • 262
31
votes
8 answers

Short Python Code to say "Pick the lower value"?

What I mean is, I'm looking for really short code that returns the lower value. for example: a=[1,2,3,4,5,6,7,8,9,10] b=[1,2,3,4,5,6,7,8] len(a) = 10 len(b) = 8 if (fill-this-in): print(lesser-value) And I forgot to add that if b is lower than…
Devoted
  • 177,705
  • 43
  • 90
  • 110
30
votes
6 answers

What is the best code template facility for Emacs?

Particularly, what is the best snippets package out there? Features: easy to define new snippets (plain text, custom input with defaults) simple navigation between predefined positions in the snippet multiple insertion of the same custom…
jfs
  • 399,953
  • 195
  • 994
  • 1,670
28
votes
3 answers

Change default XML comment snippet in Visual Studio

When I hit /// in Visual Studio, is it possible to change the resulting snippet from this: /// /// /// to this?: ///
Daniel Schaffer
  • 56,753
  • 31
  • 116
  • 165
27
votes
3 answers

Adding code snippet in Code Snippet Library (Xcode 10)

Recently when I was using Xcode 10 beta 3, I tried to make a code snippet and add it to the code snippet library. But the drag drop cannot be done as the code snippet library is detached in Xcode 10, and hides when I click on a code. How to add code…
Subhajit Halder
  • 1,427
  • 13
  • 21
26
votes
2 answers

"Extract Variable" in Visual Studio without ReSharper

I don't have ReSharper at my current gig, and I miss the "Extract Variable" refactoring. I understand that it's possible to write your own refactoring "snippet" in VS. Does anybody have one that does this?
Justin R.
  • 23,435
  • 23
  • 108
  • 157
25
votes
9 answers

Short and useful Objective-C snippets?

Since XCode 4, there is now a Code Snippets section which offers the snippets via auto-complete when typing. I'd be very interested in snippets you all have stored in there. What snippets save you the most time (and why)? Please only post actual…
Epaga
  • 38,231
  • 58
  • 157
  • 245
25
votes
4 answers

Assign code snippet to keyboard shortcut in Visual Studio

Anyone knows how to assign key shortcut to specific code snippet? I would like to assign for instance CTRL+K,CTRL+J to a #region snippet. Therefore by able to: select text, press CTRL+K,CTRL+J => selected text would be surrounded with #region ..…
aerkain
  • 592
  • 1
  • 4
  • 16
25
votes
6 answers

How to use the "sysout" snippet in Eclipse with selected text?

I am aware of the Eclipse snippet "sysout" which is neatly replaced with System.out.println(); when tab-completed. This is very useful but sometimes, I need to wrap some existing code in a System.out.println(); In Eclipse internals, the template is…
Vincent Robert
  • 35,564
  • 14
  • 82
  • 119
24
votes
3 answers

How to get the base directory in visual studio code snippet?

I am trying to get the file current directory in a snippet for visual studio code. VSCode has a variable: TM_DIRECTORY, which is the fullpath. eg: {folder: "$TM_DIRECTORY"} would be replaced by {folder:…
Kev
  • 5,049
  • 5
  • 32
  • 53