vscode-yaml icon indicating copy to clipboard operation
vscode-yaml copied to clipboard

Auto indent when press ENTER after colon

Open eailfly opened this issue 4 years ago • 12 comments

I'm trying figure out how to make vscode indent after I press ENTER after colon, like this

name:
  echo: "It should place cursor under letter 'm' automatically"

It should have indented and placed the cursor under the letter 'm' (2 spaces) when I pressed the enter key after "name:"

But I can't seem to get it to work. It just puts the cursor underneath the letter 'n'.

eailfly avatar Feb 26 '20 04:02 eailfly

I'm not entirely sure if we have the ability to customize what happens when you just press enter in a yaml file. If you have a JSON schema attached to the file and autocomplete name then it should automatically indent underneath the "m"

JPinkney avatar Feb 26 '20 13:02 JPinkney

I'm curious, what's different between I press enter after name: in a yaml and press enter after def some(): in a python file, indent works well in a python file.

eailfly avatar Feb 27 '20 11:02 eailfly

From reading the docs it looks like this could be implemented using indent rules

JPinkney avatar Feb 27 '20 13:02 JPinkney

I'm having a similar issue while writing kubernetes manifests. Using these settings... image ...when I try to define a rule for an Ingress object, the http suggestion appears, as it should, but when I hit enter, the additional items are inserted with the first non-whitespace character at the given columns. image As you can see, it's quite...off...

After playing around and trying all permutations of the relevant editor settings, both language-specific and global, I found these lines in extension.ts:

// Options to control the language client
  const clientOptions: LanguageClientOptions = {
    // Register the server for on disk and newly created YAML documents
    documentSelector: [{ language: 'yaml' }],
    synchronize: {
      // Synchronize these setting sections with the server
      configurationSection: ['yaml', 'http.proxy', 'http.proxyStrictSSL', 'editor.tabSize'],
      // Notify the server about file changes to YAML and JSON files contained in the workspace
      fileEvents: [workspace.createFileSystemWatcher('**/*.?(e)y?(a)ml'), workspace.createFileSystemWatcher('**/*.json')],
    },
  };

This led me to believe that the "editor.tabSize" was being used instead of the same field found inside the "[yaml]" block. Sure enough, I changed the global "editor.tabSize" from 4 to 2, and...voilà! The problem went away.

I'm not 100 percent confident, but it seems like the extension isn't picking up the editor settings for the language defined in the settings with "[yaml]", but only the language server settings which are prefixed w/ yaml (no brackets).

zlmiller avatar Oct 02 '20 03:10 zlmiller

After re-reading the initial issue, these aren't actually all that similar. haha 😅

Nonetheless, I think I've found the commit that introduced the problem I'm experiencing: #362

I had been using 0.11.1, and installed 0.11.0. The problem still occurred. I went back to 0.10.0, and it worked as expected.

The change referenced appears to have been made as part of the 0.11.0 release.

zlmiller avatar Oct 02 '20 04:10 zlmiller

@zlmiller I cannot reproduce your problem: ezgif com-gif-maker

Make sure that you select proper indentation(Spaces) on VSCode status bar: Screenshot 2020-10-02 at 11 28 20

If you still has problem, please create new issue, we can discuss there.

evidolob avatar Oct 02 '20 08:10 evidolob

Hmm. Interesting. I presume the settings.json in the gif were the only ones in effect? i.e. no other level (User, Workspace, etc.)

I might just have to take those as a starting point.

zlmiller avatar Oct 02 '20 14:10 zlmiller

settings.json in gif is Workspace settings, I assume that they has bigger priority then User settings

evidolob avatar Oct 05 '20 06:10 evidolob

Same request: microsoft/vscode#148528. This could added with a onEnter rule. If you come up with something, I'm happy to adopt it in the built-in yaml extension.

aeschli avatar May 04 '22 07:05 aeschli

for everyone still struggling here..

install the yaml extension. and then set editor.formatOnType to true.

jaro-io avatar Apr 16 '23 15:04 jaro-io

I'm pretty frustrated to not have an autoindent after colon enter in YAML; my Vim plugins do this; given that some people in this thread have reported they can't reproduce it, how do we dump and identify the settings that might be causing some of us to have this issue?

life5ign avatar Dec 04 '23 19:12 life5ign

Recently Í also had this problem, but most of other extentions like .lua can work, so it is probably the setting.json error.

Then hinted by this, I use the following config:

    "[yaml]": {
        // "editor.defaultFormatter": "redhat.vscode-yaml", // this will format with one weird result for some yamls sometimes, so Í format manually with only the indentation format when typing.
        "editor.tabSize": 2,
        "editor.autoIndent": "full" // the default setting is "keep"
    }

It works well with the predefined tabSize and will have the following typing behavior:

foo:
  bar: // this line the tab count will be added to 1 based on the past line
    - bar_1 // this line the tab count will be also added
    - bar_2 // this line the tab count will not be also added

sci-42ver avatar Mar 16 '24 05:03 sci-42ver