Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to position the cursor caret in Xcode code snippets

Is it possible to specify where the cursor should be after inserting a code snippet in xcode 4? Is there a <# #> style marker for this? I'm having trouble finding good documentation on code snippets.

like image 609
Roger Gilbrat Avatar asked Sep 17 '11 19:09

Roger Gilbrat


People also ask

What is snippet in Swift?

Code snippets in the library go even further: They are snippets of ","noIndex":0,"noFollow":0},"content":"<p>Code completion and Fix‐It can both help you speed up your typing and writing of Swift code. Code snippets in the library go even further: They are snippets of code you can just drag into your own code.

Where are Xcode snippets stored?

User's code snippets are saved in '~/Library/Developer/Xcode/UserData/CodeSnippets' in the form of xml documents with 'codesnippet' extension.

How do I use code snippets in Xcode?

Just select the code that you want to make a snippet and drag it to the code snippet section towards the bottom right of the xcode. A window will appear and there you can rename it and add a description. Check the gif below. Now the code snippet is created.


2 Answers

You can just use <##>. It will show a "bubble" you can select, which isn't ideal, but it does move the cursor caret to that location.

like image 68
rdougan Avatar answered Oct 06 '22 14:10

rdougan


Here are a couple examples supplementing @rdougan's helpful answer. This is not exactly what the OP was asking in the question, but it is what I was looking for when I came here based on the title.

Custom Example

print("<#text#>")

gives you

enter image description here

Standard Example

You can also observe any of the standard code snippets to see how they are made. Just click one of them in the code snippet area.

enter image description here

which gives

enter image description here

Reminder on how to add custom code snippets:

Write your code as normal in the code editor. Then highlight it and drag it into the code snippet window. A dialog box will pop up where you can give it a simple shortcut.

enter image description here

like image 35
Suragch Avatar answered Oct 06 '22 15:10

Suragch