Skip to content

Instantly share code, notes, and snippets.

@AlchemistCamp
Created June 1, 2020 12:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlchemistCamp/7b9ca48a39846556adfa290be7d9f445 to your computer and use it in GitHub Desktop.
Save AlchemistCamp/7b9ca48a39846556adfa290be7d9f445 to your computer and use it in GitHub Desktop.
My elixir.json file for Elixir snippets in VS Code
{
// In VS Code you can create this file via ctrl/cmd +p, and then "> Preferences: Configure User Snippets"
// Each snippet is defined under a snippet name and has a prefix, body and description.
// The prefix is what is used to trigger the snippet and the body will be expanded and inserted.
//
// Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders.
// Placeholders with the same ids are connected.
//
// The general rule I follow is this:
// If I type the same block five times in a coding session, it's probably worth making a snippet.
// I've made quite a few but it's probably better to create your own than copy mine!
"__MODULE__": {
"prefix": "uumod",
"body": [
"__MODULE__"
]
},
"__something__": {
"prefix": "uu",
"body": [
"__${1:MODULE}__$0"
]
},
"Define function": {
"prefix": "dfun",
"body": [
"def ${1:function_name}(${2:args}) $3do",
" $0",
"end"
]
},
"Define 1-line function": {
"prefix": "d1f",
"body": [
"def ${1:function_name}(${2:args}), $3do: $0",
]
},
"Define private function": {
"prefix": "pfun",
"body": [
"defp ${1:function_name}(${2:args}) $3do",
" $0",
"end"
]
},
"Define 1-line private function": {
"prefix": "p1f",
"body": [
"defp ${1:function_name}(${2:args}), $3do: $0",
]
},
"Define module": {
"prefix": "dmod",
"body": [
"defmodule ${1:ModuleName} do",
" $0",
"end"
]
},
"Define struct": {
"prefix": "dstruct",
"body": [
"defstruct [${1:contents}]",
]
},
"Define test": {
"prefix": "test",
"body": [
"test \"${1:test description}\" do",
" $0",
"end"
]
},
"Ecto alter table": {
"prefix": "altt",
"body": [
"alter table(:${1:name}) do",
" $0",
"end"
]
}
}
@AlchemistCamp
Copy link
Author

This file is named elixir.json5 instead of elixir.json because otherwise there's no way to get Github not to fill it with ugly red highlights on the comments. In VS Code, the file has comments and is a .json extension.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment