# Strange cursor location when using begin{}-end{} snippet for list environment in LaTeX

**URL:** <https://forum.sublimetext.com/t/strange-cursor-location-when-using-begin-end-snippet-for-list-environment-in-latex/34567>\
**Category:** Technical Support\
**Created:** [January 15, 2018, 7:39am UTC](https://forum.sublimetext.com/t/strange-cursor-location-when-using-begin-end-snippet-for-list-environment-in-latex/34567 "2018-01-15T07:39:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![h2li](https://forum.sublimetext.com/user_avatar/forum.sublimetext.com/h2li/32/73627_2.png) [@h2li](https://forum.sublimetext.com/u/h2li)\
**Post date:** [January 15, 2018, 7:39am UTC](https://forum.sublimetext.com/t/strange-cursor-location-when-using-begin-end-snippet-for-list-environment-in-latex/34567/1 "2018-01-15T07:39:12Z")

</div>

When I use the begin{}-end{} snippet to type a list environment (i.e. `itemize`, `enumerate`, `list`, `description`) in LaTeX, after I enter the environment name in brace brackets, the snippet will automatically fill one `\item` inside the environment. But when I press `Tab`, the cursor jumps to the position _before_ the `\item` command rather than after it, where I suppose to continue typing (see the enclosed screencast).

![](https://d.pr/i/LaC2LC+)

I’ve checked the snippet code:

```auto
<snippet>
	<content><![CDATA[\\begin{${1:env}}
	${1/(enumerate|itemize|list)|(description)|.*/(?1:\\item )(?2:\\item)/}$0
\\end{${1:env}}]]></content>
	<tabTrigger>begin</tabTrigger>
	<scope>text.tex.latex</scope>
	<description>\begin{}…\end{}</description>
</snippet>

```

The `$0` mark is indeed after the substituted `\item` command.

The ST3 version I used is build 3143. This issue occurs on Windows 7 (6.1.7601), macOS (High Sierra 10.13.2), and Ubuntu 17.10, even when there is no third-party package enabled. Does anyone know how to fix this?

---

<div class="post-metadata">

**Author:** ![h2li](https://forum.sublimetext.com/user_avatar/forum.sublimetext.com/h2li/32/73627_2.png) [@h2li](https://forum.sublimetext.com/u/h2li)\
**Post date:** [March 27, 2018, 8:47am UTC](https://forum.sublimetext.com/t/strange-cursor-location-when-using-begin-end-snippet-for-list-environment-in-latex/34567/2 "2018-03-27T08:47:49Z")

</div>

Is this a bug of Sublime Text, or am I doing something wrong?

I’ve filed a [bug report](https://github.com/sublimehq/Packages/issues/1388) at Sublime Text’s package repository, too. No one responds after two months.

---

<div class="post-metadata">

**Author:** ![kingkeith](https://forum.sublimetext.com/user_avatar/forum.sublimetext.com/kingkeith/32/50274_2.png) [@kingkeith](https://forum.sublimetext.com/u/kingkeith)\
**Post date:** [March 27, 2018, 9:01am UTC](https://forum.sublimetext.com/t/strange-cursor-location-when-using-begin-end-snippet-for-list-environment-in-latex/34567/3 "2018-03-27T09:01:22Z")

</div>

I’m guessing that ST calculates the region where `$0` refers to before any substitutions take place, i.e. it’s a static position. So not necessarily a bug per se, but an implementation detail that prevents it from working the way you want it to.

possibly slightly related:

> <https://github.com/SublimeTextIssues/Core/issues/1>

---

<div class="post-metadata">

**Author:** ![h2li](https://forum.sublimetext.com/user_avatar/forum.sublimetext.com/h2li/32/73627_2.png) [@h2li](https://forum.sublimetext.com/u/h2li)\
**Post date:** [March 28, 2018, 3:02pm UTC](https://forum.sublimetext.com/t/strange-cursor-location-when-using-begin-end-snippet-for-list-environment-in-latex/34567/4 "2018-03-28T15:02:45Z")

</div>

Thanks for your explanation. [That issue](https://github.com/SublimeTextIssues/Core/issues/1) doesn’t seem very helpful.

After a few tries, I find that if there are any characters between the substitution and the `$0` mark, then the tab navigation will work as what I expect, i.e., the cursor will jump to the location where `$0` is no matter whether the substitution takes place or not.

For example, if I replace the original line

```
${1/(enumerate|itemize|list)|(description)|.*/(?1:\\item )(?2:\\item)/}$0

```

by

```
${1/(enumerate|itemize|list)|(description)|.*/(?1:\\item )(?2:\\item)/} $0

```

then

![A workaround](https://ws2.sinaimg.cn/large/006tKfTcgy1fq0qf5er4ag30eu0clte1.gif)

However, this is an ugly workaround, because the _additional_ character inserted before `$0` mark will still be there.

Maybe such a problem is an intentional design, but I still think it is more like a bug because when the substitution part is put before the `$0` mark in the snippet, it is supposed the substitution and the region where `$0` refers to will follow the order
