vscode-yaml
vscode-yaml copied to clipboard
Auto indent when press ENTER after colon
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'.
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"
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.
From reading the docs it looks like this could be implemented using indent rules
I'm having a similar issue while writing kubernetes manifests. Using these settings...
...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.
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).
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 I cannot reproduce your problem:
Make sure that you select proper indentation(Spaces
) on VSCode status bar:
If you still has problem, please create new issue, we can discuss there.
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.
settings.json
in gif is Workspace settings, I assume that they has bigger priority then User settings
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.
for everyone still struggling here..
install the yaml extension. and then set editor.formatOnType
to true
.
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?
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