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
58
votes
2 answers

Replace parameter multiple times in Xcode code snippets

Can I create a custom snippet that takes a parameter that is replaced multiple times inside the code? I tried something like: <#class#> instanceOf<#class#>; but it doesn't replace both class placeholders when I insert the snippet and write over the…
lkraider
  • 4,111
  • 3
  • 28
  • 31
56
votes
3 answers

Using VS Code Snippets with Resharper

I am trying to use Code Contract's Code Snippets but since I turned Resharper back on it doesn't recognize them. On the other hand, it is recognizing some snippets I've implemented myself in the past. Any ideia of what might be the problem? I'm…
devoured elysium
  • 101,373
  • 131
  • 340
  • 557
54
votes
7 answers

What's The Best Way To Write Multi-Line Code Snippets In VS-Code?

In Sublime Text, multi-line code snippets can be defined with white-spaces in a snippet file. But as far as I know, VS-Code needs a JSON entry. These require either: Hard-breaks into a list of double-quoted strings, or Soft-break a long string…
kakyo
  • 10,460
  • 14
  • 76
  • 140
54
votes
4 answers

VS Code Intellisense don't suggest snippet at first

I want to use code snippets in VSCode. But when I type, for example, for in javascript file, the Intellisense doesn't suggest snippet "for-loop" - I need to manually scroll the dropdown and select it. Is there any way to make VSCode to suggest…
Agnarh
  • 543
  • 1
  • 4
  • 7
51
votes
1 answer

Snippet inserts extra newline in VS2015

I've made a custom snippet for use in Visual Studio. In VS2013, it worked as expected, but since using it in VS2015 (Community Edition) it's been inserting an extra newline before the code (right when I press tab/enter the second time). This seems…
thomas88wp
  • 2,381
  • 19
  • 31
49
votes
7 answers

How to edit existing VS Code Snippets

Is there a way to remove or edit some of the default code snippets in Visual Studio CODE ? For example when i type req+TAB i need require not requestAnimationFrame
Nikola Hristov
  • 686
  • 1
  • 6
  • 11
48
votes
22 answers

Short (and useful) python snippets

In spirit of the existing "what's your most useful C/C++ snippet" - thread: Do you guys have short, monofunctional Python snippets that you use (often) and would like to share with the StackOverlow Community? Please keep the entries small (under 25…
ChristopheD
  • 112,638
  • 29
  • 165
  • 179
47
votes
7 answers

How to determine whether a string is valid JSON?

Does anyone know of a robust (and bullet proof) is_JSON function snippet for PHP? I (obviously) have a situation where I need to know if a string is JSON or not. Hmm, perhaps run it through a JSONLint request/response, but that seems a bit overkill.
Spot
  • 7,962
  • 9
  • 46
  • 55
46
votes
8 answers

Delete a User Code Snippet in Xcode

How ??? I can not delete a custom code snippet in Xcode.
user704010
46
votes
9 answers

Any way to surround code block with Curly Braces {} in VS2008?

I always find myself needing to enclose a block of code in curly braces { }, but unfortunately that isn't included in the C# surround code snippets, which seems to be an oversight. I couldn't find anything on building your own surround snippets…
Jim McKeeth
  • 38,225
  • 23
  • 120
  • 194
45
votes
4 answers

How to create a 'surround with' type of snippet in Visual Studio 2010?

Is there a way to create a 'surround with' snippet in visual studio 2010? I know how to create a replacement type of snippet. A simple surround with snippet could surround a block of text with an asp:hyperlink. Similar to the way the default…
FiveTools
  • 5,970
  • 15
  • 62
  • 84
43
votes
3 answers

Manage code snippets in Notepad++

Is there any way to manage code snippets with backup for the database and code highlighting in Notepad++?
MohamedKadri
  • 627
  • 1
  • 5
  • 10
43
votes
2 answers

How to hide code in RMarkdown, with option to see it

I'm writing an RMarkdown document in which I'd like to re-run some chunks (5 to 9). There's no need to display these chunks again, so I considered using ```{r echo=FALSE} to make the rerun chunks invisible, as described in another stackoverflow…
RobinLovelace
  • 4,799
  • 6
  • 29
  • 40
42
votes
3 answers

Visual Studio Code : Sort functions by name?

Is it possible to sort functions by name in Visual Studio Code ? I mean, using a keyboard shortcut or even an extension. Precision: I'm spaeking about sorting the functions in the panel code editor.
37
votes
3 answers

Why does this C# code return what it does

Can someone please help me understand why this code snippet returns "Bar-Bar-Quux"? I'm having a hard time understanding this even after reading up on interfaces. interface IFoo { string GetName(); } class Bar : IFoo { public string…
B-Lock-a
  • 403
  • 6
  • 8