# TexStudio: Multiple Cursors in Macro

however looking up my questions using the usual suspects (Google, search function etc.) I could not find an answer/solution to the following task (potentially I don't know the proper name of the task I am looking for XD ):

In Texstudio I want to create my own macro/snippet for a figure environment, where the cursor is placed at a certain position to enter the filename. However I would like to have the same text filled in another position while I type (such as in the cmd+E environment snippet).

\begin{figure}[t]
\centering
\includegraphics{pics/%<%>}
\caption{}
\label{fig:%<%>}
\end{figure}


The /%<%> places my cursor at the desired position, but I am not able to figure out how to autofill this text in the label command while typing.

The second /%<%> just provides another cursor position which I can access manually.

I appreciate any help. So thanks in advance!

• As a start you may have a look at the TeXstudio Usermanual - Section 4.5.3. It describes how to use JavaScript in order to script macros. – Markus Mar 29 '15 at 16:13
• %<foo%> just creates a placeholder. The cursor is placed at the first placeholder. Setting multiple cursors in a macro is not supported. – Tim Hoffmann Mar 29 '15 at 19:12
• Thanks so far, maybe I can figure out how to write a script. The manual is not very informative for a non IT person... – Stefan Apr 1 '15 at 17:39
• @TimHoffmann can you support this function, I think it is very useful. – noname1014 Feb 13 '16 at 19:45

For clarification

Multiple cursors are not supported. This would be something like

% NOT SUPPORTED
\includegraphics{pics/%|}
\caption{}
\label{fig:%|}


Mirrored placeholders are supported. This is an undocumented function and may change in the future without further notice.

% THIS DOES WORK
\includegraphics{pics/%<%:id:1%>}
\caption{}
\label{fig:%<%:mirror,id:1%>}

• I believe they are supported now, as well as multiple mirrors working fine. I guess it is worth to update the answer. – MetalMathician Jan 23 '17 at 14:52
• No. The above example still does not work. – Tim Hoffmann Jan 24 '17 at 21:16

I can see the problem. You are using a "/" which is only to indicate the image is in a subfolder. The code to positioning the cursor it's just conformed by %<%>. Creating a macro for inline math code, it look like

$%<%>$

Inclusive, you can include text inside it, like a tag for reference:

$%< tag %>$

If your macro has more than one cursor positions, with "ctrl+rightarrow" you will move the cursor to the next one position when you work with your macro. With "ctrl+leftarrow" you can reverse the position.

• You are right, but this is not an answer. As Tim said on the comments, it is not possible to fill all placeholders typing only once. – Sigur Jan 28 '16 at 20:59