Navigating double spaces with arrow keys

When I have two spaces next to each other in RStudio I am unable to navigate in between them with the arrow keys. Has anyone else experienced this behavior?

See this gif for an example.

Thanks!

Hi, and welcome!

[see remainder of thread; my first answer was complete BS]

1 Like

Thanks for your quick reply and welcome, technocrat!

I actually do not see that option on my preferences. Perhaps a different option set/unset that is hiding it?

Ah! Sorry. I'm on the preview version. It's working without problems on MacOS, and you might try it.

UPDATE: still BS

1 Like

Thanks for the suggestion. I updated and now I have that option, however I am experiencing the same behavior whether is is checked or not.

1 Like

Well, that was a particularly boneheaded suggestion on my part! That's not what tab completion does at all.

This appears to be a hardwired behavior into the IDE editor, since if you assign a triple spaced object in the console, you don't get the same behavior.

I suspect that this is a remnant of the great Two Spaces After a Period War that has consumed so much bandwidth since the advent of widespread proportional printing.

The output of knitting is, by default, proportional, and it ignores repeated whitespace. You'll see this if you knit

I        am       a   sentence    with many   spaces.

I'm not exactly sure if this is the source of the rationale for this behavior--to fool the user into thinking that there really will be two spaces.

I should have asked before, though: What's the ultimate goal of being able to insert multiple explicit spaces?

1 Like

The motivation behind my question comes from my new adventures in RMarkdown.

I have been using a lot of regular Markdown + Latex/MathJax for math type. To help speed up my Latex, I have a lot of hotkeys/expansions.

example:
If I type \frac it autofills with

\frac{-^-}{- - -}

Where the dashes are spaces (the spaces above are just for visual clarity) and the caret is where it places my cursor. When I perform this in RStudio it does this:

\frac^{- -}{- - -}

I have started using RMarkdown in conjunction with my previous set up and was hoping to use the same expansions.

edit: Changed underscores to dashes because I was accidentally italicizing.

1 Like

Ah, that makes sense. I don't know about Windowsland (since I haven't had to deal with it since XT). On MacOS, TextExpander will create a dialog box to do that (and probably Keyboard Maestro) and probably also do that in vi and emacs, which works on the other Unices as well. It may be possible to programmatically control cursor placement, but I wouldn't know where to begin.

1 Like

I have been using Typinator on Mac and it works great for moving the cursor around. It looks like it is trying move it back x places, but since RStudio is combining the spaces, it is moving is back x+2 spaces, which is why it moves before the curly braces.

What it is, if you watch closely is space tab even though when you cut and paste there's no tab!

1 Like

I think you're right, though maybe it's tab space? I think it is grouping spaces by 2s, so it globs the first two together as a tab and leaves the last one to fend for itself. Either way, I still haven't found a magic switch to stop it yet.

1 Like

I might well need new glasses! In any event, good luck!

1 Like

Thank you for your help!

To everyone that has been unable to sleep, clamoring for a solution to this problem, I have found one!

You have to go into preferences > code > editing, check insert spaces for tab and set the tab width to 1. You also have to make this same change in your project preferences.

See this post for more details

1 Like

Just to clarify, this behavior exists so that spaces can be treated as though they were soft tabs. As an example, if you had code indented by 4 spaces which is intended to behave and be displayed as though it were a single tab, then navigating left and right there should navigate over the 4 spaces.

This behavior is understandably less desirable for consecutive spaces not acting as indent. Would you consider filing this as a feature request at https://github.com/rstudio/rstudio/issues?

2 Likes

Ah, mystery solved, thanks. Soft tabs are wonderful; soft spaces not so much.

I put in a feature request at https://github.com/rstudio/rstudio/issues/6368

1 Like

Thank you guys for all your help!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.