# Visual studio Code + Robot Framework Indentation wrong

**URL:** <https://forum.robotframework.org/t/visual-studio-code-robot-framework-indentation-wrong/4924>\
**Category:** Visual Studio Code(ium)\
**Created:** [9 November 2022 14:31 UTC](https://forum.robotframework.org/t/visual-studio-code-robot-framework-indentation-wrong/4924 "2022-11-09T14:31:09Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![LaurensRobot](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/laurensrobot/32/2037_2.png) [@LaurensRobot](https://forum.robotframework.org/u/LaurensRobot)\
**Post date:** [9 November 2022 14:31 UTC](https://forum.robotframework.org/t/visual-studio-code-robot-framework-indentation-wrong/4924/1 "2022-11-09T14:31:09Z")

</div>

Hi,  
I have been using Visual Studio Code(Mac-version) for my RF tests. Only two issues I encounter are:

1. My indentation is all wrong. I cant seem to line anything up with my tabs. It only seems to happen with .robot -files and not with .py etc.  
I tried making changes to my **settings.json** file for indentation but nothing seems to work.  
Please help me with this because its very frustrating.  
A copy of my settings.json is added as an appendix  

2. When I run my tests from the **testrunner button** (_Run Tests/Suite, upper right button_)  
 ![Screenshot 2022-11-09 at 15.32.14](https://europe1.discourse-cdn.com/flex005/uploads/robotframework1/original/2X/5/5bfc17498fe51c304cac611ad0532e97baf9487a.png)

it seems to store the output.xml and report.html file in the project folder. I have a **“Results”** directory which I can use to store the output.xml and report.html-files if I run the tests with _“robot -d results tests/crm.robot”_.

Using a button seems easier and faster. Is there a way I can change the directory in which the results are stored to **/Users/laurens/projects/robotframework/Results** automatically?

Many thanks in advance!

---

<div class="post-metadata">

**Author:** ![daniel](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/daniel/32/1492_2.png) [@daniel](https://forum.robotframework.org/u/daniel)\
**Post date:** [9 November 2022 15:42 UTC](https://forum.robotframework.org/t/visual-studio-code-robot-framework-indentation-wrong/4924/2 "2022-11-09T15:42:59Z")

</div>

which extension you are using for robotframework?

---

<div class="post-metadata">

**Author:** ![LaurensRobot](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/laurensrobot/32/2037_2.png) [@LaurensRobot](https://forum.robotframework.org/u/LaurensRobot)\
**Post date:** [9 November 2022 17:06 UTC](https://forum.robotframework.org/t/visual-studio-code-robot-framework-indentation-wrong/4924/3 "2022-11-09T17:06:07Z")

</div>

Hi,

- Robocorp Code
- Robot Framework Formatter
- Robot Framework Language Server

Aside from that also:

- Prettier

---

<div class="post-metadata">

**Author:** ![fabioz](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/fabioz/32/983_2.png) [@fabioz](https://forum.robotframework.org/u/fabioz)\
**Post date:** [9 November 2022 17:07 UTC](https://forum.robotframework.org/t/visual-studio-code-robot-framework-indentation-wrong/4924/4 "2022-11-09T17:07:41Z")

</div>

@LaurensRobot can you show some code showing a sample code with an example so that I can help you diagnose what’s actually happening?

i.e.: Something as: given code: xxx when I press tab at: xxx I’d like to have the code: xxx as a result.

---

<div class="post-metadata">

**Author:** ![fabioz](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/fabioz/32/983_2.png) [@fabioz](https://forum.robotframework.org/u/fabioz)\
**Post date:** [9 November 2022 17:09 UTC](https://forum.robotframework.org/t/visual-studio-code-robot-framework-indentation-wrong/4924/5 "2022-11-09T17:09:00Z")

</div>

As a note, the setting related to:

`robot.editor.4spacesTab` is the one that makes a tab enter 4 spaces (instead of using the default indent which would add spaces up to a multiple of 4). Perhaps setting it to false is what you want?

---

<div class="post-metadata">

**Author:** ![fabioz](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/fabioz/32/983_2.png) [@fabioz](https://forum.robotframework.org/u/fabioz)\
**Post date:** [9 November 2022 17:13 UTC](https://forum.robotframework.org/t/visual-studio-code-robot-framework-indentation-wrong/4924/6 "2022-11-09T17:13:49Z")

</div>

For number 2 (customizing the output), you need to configure your launch configuration for those shortcuts (i.e.: you need to add arguments to the launch configuration used in this case).

See: [robotframework-lsp/faq.md at master · robocorp/robotframework-lsp · GitHub](https://github.com/robocorp/robotframework-lsp/blob/master/robotframework-ls/docs/faq.md#how-to-configure-the-launch-from-a-code-lensshortcut) for details on how to do that.

---

<div class="post-metadata">

**Author:** ![LaurensRobot](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/laurensrobot/32/2037_2.png) [@LaurensRobot](https://forum.robotframework.org/u/LaurensRobot)\
**Post date:** [9 November 2022 17:17 UTC](https://forum.robotframework.org/t/visual-studio-code-robot-framework-indentation-wrong/4924/7 "2022-11-09T17:17:42Z")

</div>

Here’s an example.  
 ![Screenshot 2022-11-09 at 18.13.27](https://europe1.discourse-cdn.com/flex005/uploads/robotframework1/original/2X/5/573d3bdc7424297cafdc783ef12b1a32698e7a52.png)

The first four lines line up perfectly, but when I use a different keyword it doesn’t.  
It seems that when I first use the tab after the keyword it only moves 2 spaces, but when I press TAB a second time it moves 4…

---

<div class="post-metadata">

**Author:** ![fabioz](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/fabioz/32/983_2.png) [@fabioz](https://forum.robotframework.org/u/fabioz)\
**Post date:** [10 November 2022 10:56 UTC](https://forum.robotframework.org/t/visual-studio-code-robot-framework-indentation-wrong/4924/8 "2022-11-10T10:56:38Z")

</div>

@LaurensRobot I believe that what you want is really setting **robot.editor.4spacesTab** to **false**.

In that case it’ll always indent the cursor to a multiple of your indent size (so, yes, when you press tab the first time it’ll indent up to the next multiple and then it’ll add 4) – if you use it consistently you’ll note that the indent will end up matching because it’ll always be a multiple of 4 (but you have to adjust existing text…).

But still, I’d actually recommend against using that (because it’ll always indent to a multiple of 4 sometimes it’ll add just 1 space and you’ll have to use tab again to actually add a separator… note that this is the default VSCode indent behavior and it’s the reason for the **robot.editor.4spacesTab** setting) and just using the formatter that comes with the **Robot Framework Language Server** – the bundled formatter is actually **robotframework-tidy** (you can see [Robotidy 3.3.2](https://robotidy.readthedocs.io/en/stable/) for its docs).

Personally what I do is enabling format on save and let the formatter deal with it (you can configure the formatter creating a **pyproject.toml** which is then picked up by robotframework-tidy – its page has more info).

To enable format on save just for robot files you could use something as:

```python
  "[robot]": {
    "editor.formatOnSave": true,
  }

```
