You need to put the snippet into a folder with the name of the mode to use it in as follows:
Check out the documentation:
Organizing snippets > Basic structure:
| `-- printf
| `-- println
Expanding snippets > ... > Eligible snippets :
Probably just change $1 to $0. That will just put the cursor there to start typing.
From the documentation:
Tab stops are fields that you can navigate back and forth by TAB and S-TAB. They are written by $ followed with a number. $0 has the special meaning of the exit point of a snippet. That is the last place to go when you've traveled all the fields.
(setq ac-auto-start nil)
Specify how completion will be started. t means always starting completion automatically. nil means never started automatically. An integer means completion will not be started until the value is more than a length of the completion target string.
It's described in the Auto-Complete User Manual.
You can set header arguments in Org mode properties (see (org) Using Header Arguments) to avoid repeating, for example, all code blocks in this org file will have :dir /tmp
#+PROPERTY: header-args :dir /tmp
I also have the following command in my init file, it duplicates the last src block's header, ...
You can delete chars from the buffer during expansion, but modifying the buffer during expansion is dicouraged.
Deleting chars is pretty easy, because yasnippet allows to eval elisp code during expansion. You have to put this code into back-quotes Read more about it here.
Your snippet would then look like this example (you need to refine this crude example,...
You can do this with an extra step (see "Nested placeholder fields" in the manual):
With the optional field: TAB, TAB, insert field 1, TAB, insert field 2, TAB to exit. Without the optional field: TAB, C-d, insert field 2, TAB to exit.
Another option is to use a function that deletes the empty field in case it finds one:
In your buffer, M-x yas-visit-snippet-file, then type the name of the snippet you want to edit, or choose from a prompted list. Then it will open a buffer for you to edit. From the buffer you can M-: buffer-file-name to see the path of the file containing the snippet.