vscode snippets
satya - 2/11/2024, 3:28:50 PM
Stupid thing!!!
- There are instructions in the snippet file
- If you leave them as they are..and add your snippet under it won't work
- Delete the comments
- Just use the snippet block
satya - 2/11/2024, 3:29:59 PM
The file will be saved under
your folder/.vscode/file.code-snippets
satya - 2/11/2024, 3:30:12 PM
An example
{
"Block Comments": {
"scope": "python",
"prefix": "block_comments",
"body": [
"\"\"\"",
"*************************************************",
"* Prep the template",
"*************************************************",
"\"\"\""
],
"description": "Inserts a block comment for template preparation."
}
}
satya - 2/11/2024, 3:31:24 PM
Note the global files are stored under
/users/user/appdata/roaming/code/user/snippets/filenam.code-snippets
satya - 2/11/2024, 3:41:48 PM
Here is how you put 2 snippets
{
"Block Comments": {
"scope": "python",
"prefix": "block_comments",
"body": [
"\"\"\"",
"*************************************************",
"* Prep the template",
"*************************************************",
"\"\"\""
],
"description": "Inserts a block comment for template preparation."
},
"lib_main_snippet": {
"prefix": "lib_main_snippet",
"body": [
"def test():",
" pass",
"",
"def localTest():",
" log.ph1(\"Starting local test\")",
" test()",
" log.ph1(\"End local test\")",
"",
"if __name__ == '__main__':",
" localTest()"
],
"description": "Template for local testing with a main block"
}
}
satya - 2/11/2024, 3:43:46 PM
The json format of this file is important
- A single root note
- Each snippet is a dictionary entry
- Not sure if comments are allowed
- Even a small mistake, vscode reports no snippets available...
- The whole error messaging could be quite a case in-convalescence.
satya - 2/11/2024, 3:46:39 PM
How to create this snippet file
- ctrl-shift-p and "snippets"
- use "configure user snippets"
- Instead of choosing global you may want to chose your local snippet
- this file is saved in .vscode/file.code-snippet
- I assume you can have multiple snippet files
- Doing locally gives you more access and control to that file where as the global files are tucked away deep inside python global jungle.
satya - 2/11/2024, 3:47:41 PM
How do I invoke or insert the snippet
- Just type the beginning words
- intellisense should prompt you right away
- No tab is needed
- No ctrl-space is needed
satya - 2/11/2024, 3:49:10 PM
You have the option in settings to
- Go to settings (ctrl-shift-p: search for settings)
- Editor: snippet suggestion
- options: top, bottom, inline (default), none
- I chose "top"
- works good so far