Preserve spacing on indent or outdent with tab in VSCode












7















In VSCode, when I have:



    /*
* Comment
*/


If I select it and hit tab, I get:



        /*
* Comment
*/


If instead I had hit shift-tab, I get:



/*
* Comment
*/


Same happens with Ctrl-] and Ctrl-[ (if those are supposed to make a difference)



I hoped turning off autoIndent would stop this, but no dice. I also turned off C++ formatting in the JSON config:



{
"editor.autoIndent": false,
"editor.detectIndentation": false,
"C_Cpp.formatting": "Disabled"
}


There's an extension which shifts text by one character at a time which is a sort of proof-of-concept you could override your tab key with something like that. But it doesn't seem you should need an extension to disable this formatting.



Is editor.autoIndent: false supposed to do what I want, and just broken?



UPDATE: I have also raised this as an issue on the VSCode GitHub










share|improve this question

























  • Does stackoverflow.com/a/29972553/1023911 help?

    – Werner Henze
    Nov 17 '18 at 20:16













  • @WernerHenze Setting "editor.detectIndentation": false still leads the tab key to wreck the spacing in the material being indented or outdented...but fills the left with tab characters instead of spaces (I want spaces, but a data point to check to see if I were using tabs it would not mangle the comment)

    – HostileFork
    Nov 17 '18 at 20:25











  • Despite the fact that this was picked up and considered a bug by VSCode, am I really the only person who's noticed this? I really am not a fan of automatic formatting behaviors when cutting, pasting, tabbing. It seems to me one should be able to trust that grabbing things from one place and putting them elsewhere preserves them, and if you want otherwise a specific "reformat this" command should be run.

    – HostileFork
    Nov 21 '18 at 21:14








  • 1





    Who says that you are the only one who sees the problem? If noone answers it just means that noone knows a solution. BTW, using .clang-format with ReflowComments: true auto formats the comment, but it does not help for indenting either. Just for your information: Visual Studio (not VS code) does indenting correctly but also fails for un-indenting.

    – Werner Henze
    Nov 21 '18 at 22:47






  • 1





    If you set the Tab size to 1, it will do the same job as the extension you referenced. It does on my side.

    – TeeKea
    Nov 24 '18 at 21:00
















7















In VSCode, when I have:



    /*
* Comment
*/


If I select it and hit tab, I get:



        /*
* Comment
*/


If instead I had hit shift-tab, I get:



/*
* Comment
*/


Same happens with Ctrl-] and Ctrl-[ (if those are supposed to make a difference)



I hoped turning off autoIndent would stop this, but no dice. I also turned off C++ formatting in the JSON config:



{
"editor.autoIndent": false,
"editor.detectIndentation": false,
"C_Cpp.formatting": "Disabled"
}


There's an extension which shifts text by one character at a time which is a sort of proof-of-concept you could override your tab key with something like that. But it doesn't seem you should need an extension to disable this formatting.



Is editor.autoIndent: false supposed to do what I want, and just broken?



UPDATE: I have also raised this as an issue on the VSCode GitHub










share|improve this question

























  • Does stackoverflow.com/a/29972553/1023911 help?

    – Werner Henze
    Nov 17 '18 at 20:16













  • @WernerHenze Setting "editor.detectIndentation": false still leads the tab key to wreck the spacing in the material being indented or outdented...but fills the left with tab characters instead of spaces (I want spaces, but a data point to check to see if I were using tabs it would not mangle the comment)

    – HostileFork
    Nov 17 '18 at 20:25











  • Despite the fact that this was picked up and considered a bug by VSCode, am I really the only person who's noticed this? I really am not a fan of automatic formatting behaviors when cutting, pasting, tabbing. It seems to me one should be able to trust that grabbing things from one place and putting them elsewhere preserves them, and if you want otherwise a specific "reformat this" command should be run.

    – HostileFork
    Nov 21 '18 at 21:14








  • 1





    Who says that you are the only one who sees the problem? If noone answers it just means that noone knows a solution. BTW, using .clang-format with ReflowComments: true auto formats the comment, but it does not help for indenting either. Just for your information: Visual Studio (not VS code) does indenting correctly but also fails for un-indenting.

    – Werner Henze
    Nov 21 '18 at 22:47






  • 1





    If you set the Tab size to 1, it will do the same job as the extension you referenced. It does on my side.

    – TeeKea
    Nov 24 '18 at 21:00














7












7








7








In VSCode, when I have:



    /*
* Comment
*/


If I select it and hit tab, I get:



        /*
* Comment
*/


If instead I had hit shift-tab, I get:



/*
* Comment
*/


Same happens with Ctrl-] and Ctrl-[ (if those are supposed to make a difference)



I hoped turning off autoIndent would stop this, but no dice. I also turned off C++ formatting in the JSON config:



{
"editor.autoIndent": false,
"editor.detectIndentation": false,
"C_Cpp.formatting": "Disabled"
}


There's an extension which shifts text by one character at a time which is a sort of proof-of-concept you could override your tab key with something like that. But it doesn't seem you should need an extension to disable this formatting.



Is editor.autoIndent: false supposed to do what I want, and just broken?



UPDATE: I have also raised this as an issue on the VSCode GitHub










share|improve this question
















In VSCode, when I have:



    /*
* Comment
*/


If I select it and hit tab, I get:



        /*
* Comment
*/


If instead I had hit shift-tab, I get:



/*
* Comment
*/


Same happens with Ctrl-] and Ctrl-[ (if those are supposed to make a difference)



I hoped turning off autoIndent would stop this, but no dice. I also turned off C++ formatting in the JSON config:



{
"editor.autoIndent": false,
"editor.detectIndentation": false,
"C_Cpp.formatting": "Disabled"
}


There's an extension which shifts text by one character at a time which is a sort of proof-of-concept you could override your tab key with something like that. But it doesn't seem you should need an extension to disable this formatting.



Is editor.autoIndent: false supposed to do what I want, and just broken?



UPDATE: I have also raised this as an issue on the VSCode GitHub







visual-studio-code auto-indent






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 18 '18 at 19:39







HostileFork

















asked Nov 15 '18 at 18:51









HostileForkHostileFork

25.7k779133




25.7k779133













  • Does stackoverflow.com/a/29972553/1023911 help?

    – Werner Henze
    Nov 17 '18 at 20:16













  • @WernerHenze Setting "editor.detectIndentation": false still leads the tab key to wreck the spacing in the material being indented or outdented...but fills the left with tab characters instead of spaces (I want spaces, but a data point to check to see if I were using tabs it would not mangle the comment)

    – HostileFork
    Nov 17 '18 at 20:25











  • Despite the fact that this was picked up and considered a bug by VSCode, am I really the only person who's noticed this? I really am not a fan of automatic formatting behaviors when cutting, pasting, tabbing. It seems to me one should be able to trust that grabbing things from one place and putting them elsewhere preserves them, and if you want otherwise a specific "reformat this" command should be run.

    – HostileFork
    Nov 21 '18 at 21:14








  • 1





    Who says that you are the only one who sees the problem? If noone answers it just means that noone knows a solution. BTW, using .clang-format with ReflowComments: true auto formats the comment, but it does not help for indenting either. Just for your information: Visual Studio (not VS code) does indenting correctly but also fails for un-indenting.

    – Werner Henze
    Nov 21 '18 at 22:47






  • 1





    If you set the Tab size to 1, it will do the same job as the extension you referenced. It does on my side.

    – TeeKea
    Nov 24 '18 at 21:00



















  • Does stackoverflow.com/a/29972553/1023911 help?

    – Werner Henze
    Nov 17 '18 at 20:16













  • @WernerHenze Setting "editor.detectIndentation": false still leads the tab key to wreck the spacing in the material being indented or outdented...but fills the left with tab characters instead of spaces (I want spaces, but a data point to check to see if I were using tabs it would not mangle the comment)

    – HostileFork
    Nov 17 '18 at 20:25











  • Despite the fact that this was picked up and considered a bug by VSCode, am I really the only person who's noticed this? I really am not a fan of automatic formatting behaviors when cutting, pasting, tabbing. It seems to me one should be able to trust that grabbing things from one place and putting them elsewhere preserves them, and if you want otherwise a specific "reformat this" command should be run.

    – HostileFork
    Nov 21 '18 at 21:14








  • 1





    Who says that you are the only one who sees the problem? If noone answers it just means that noone knows a solution. BTW, using .clang-format with ReflowComments: true auto formats the comment, but it does not help for indenting either. Just for your information: Visual Studio (not VS code) does indenting correctly but also fails for un-indenting.

    – Werner Henze
    Nov 21 '18 at 22:47






  • 1





    If you set the Tab size to 1, it will do the same job as the extension you referenced. It does on my side.

    – TeeKea
    Nov 24 '18 at 21:00

















Does stackoverflow.com/a/29972553/1023911 help?

– Werner Henze
Nov 17 '18 at 20:16







Does stackoverflow.com/a/29972553/1023911 help?

– Werner Henze
Nov 17 '18 at 20:16















@WernerHenze Setting "editor.detectIndentation": false still leads the tab key to wreck the spacing in the material being indented or outdented...but fills the left with tab characters instead of spaces (I want spaces, but a data point to check to see if I were using tabs it would not mangle the comment)

– HostileFork
Nov 17 '18 at 20:25





@WernerHenze Setting "editor.detectIndentation": false still leads the tab key to wreck the spacing in the material being indented or outdented...but fills the left with tab characters instead of spaces (I want spaces, but a data point to check to see if I were using tabs it would not mangle the comment)

– HostileFork
Nov 17 '18 at 20:25













Despite the fact that this was picked up and considered a bug by VSCode, am I really the only person who's noticed this? I really am not a fan of automatic formatting behaviors when cutting, pasting, tabbing. It seems to me one should be able to trust that grabbing things from one place and putting them elsewhere preserves them, and if you want otherwise a specific "reformat this" command should be run.

– HostileFork
Nov 21 '18 at 21:14







Despite the fact that this was picked up and considered a bug by VSCode, am I really the only person who's noticed this? I really am not a fan of automatic formatting behaviors when cutting, pasting, tabbing. It seems to me one should be able to trust that grabbing things from one place and putting them elsewhere preserves them, and if you want otherwise a specific "reformat this" command should be run.

– HostileFork
Nov 21 '18 at 21:14






1




1





Who says that you are the only one who sees the problem? If noone answers it just means that noone knows a solution. BTW, using .clang-format with ReflowComments: true auto formats the comment, but it does not help for indenting either. Just for your information: Visual Studio (not VS code) does indenting correctly but also fails for un-indenting.

– Werner Henze
Nov 21 '18 at 22:47





Who says that you are the only one who sees the problem? If noone answers it just means that noone knows a solution. BTW, using .clang-format with ReflowComments: true auto formats the comment, but it does not help for indenting either. Just for your information: Visual Studio (not VS code) does indenting correctly but also fails for un-indenting.

– Werner Henze
Nov 21 '18 at 22:47




1




1





If you set the Tab size to 1, it will do the same job as the extension you referenced. It does on my side.

– TeeKea
Nov 24 '18 at 21:00





If you set the Tab size to 1, it will do the same job as the extension you referenced. It does on my side.

– TeeKea
Nov 24 '18 at 21:00












1 Answer
1






active

oldest

votes


















1





+100









If you set the Tab size to 1, it will do the same job as the extension you referenced.



You can set the Tab or Space size by clicking on the bottom-right corner:



Change Tab/Space size



Click on Spaces:4. Then, select Indent Using Spaces or Indent Using Tabs and choose the size 1.



UPDATE:



I found an approach that fully satisfies your requirement (though it's through an extension). After choosing a Tab/Space size of 1, install and load the multi-command extension to perform the 1-space indentation 'four' times. Then, go to your settings.json (File > Preferences > Settings) and add these two commands:



{
"macros": {
"tab4times": [
"tab",
"tab",
"tab",
"tab"
],
"shifttab4times": [
"outdent",
"outdent",
"outdent",
"outdent"
]
}
}


Then, in the keybindings.json file (CTRL+P and then type keybindings.json), modify the CTRL+] and CTRL+[ keys to execute the newly created commands:



[
{
"key": "ctrl+]",
"command": "macros.tab4times",
"when": "editorTextFocus && !editorReadonly"
},
{
"key": "ctrl+[",
"command": "macros.shifttab4times",
"when": "editorTextFocus && !editorReadonly"
}
]


After saving these configurations, go to your text. Now press the CTRL+] and CTRL+[ to see you desired behavior of indentation and outdentation, respectiovely.



Hope it helps.






share|improve this answer





















  • 1





    Thanks for doing this! I'm busy with some other things right now and can't try it out, but I'll assume it works as described... giving you the bounty before the clock runs out. :-)

    – HostileFork
    Nov 25 '18 at 3:24













  • Thank you, @HostileFork. I really appreciate that you trusted my answer. It worked well for me, but please let me know if any of the steps is not clear while you implement it. Have a wonderful weekend!

    – TeeKea
    Nov 25 '18 at 3:58











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53326134%2fpreserve-spacing-on-indent-or-outdent-with-tab-in-vscode%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1





+100









If you set the Tab size to 1, it will do the same job as the extension you referenced.



You can set the Tab or Space size by clicking on the bottom-right corner:



Change Tab/Space size



Click on Spaces:4. Then, select Indent Using Spaces or Indent Using Tabs and choose the size 1.



UPDATE:



I found an approach that fully satisfies your requirement (though it's through an extension). After choosing a Tab/Space size of 1, install and load the multi-command extension to perform the 1-space indentation 'four' times. Then, go to your settings.json (File > Preferences > Settings) and add these two commands:



{
"macros": {
"tab4times": [
"tab",
"tab",
"tab",
"tab"
],
"shifttab4times": [
"outdent",
"outdent",
"outdent",
"outdent"
]
}
}


Then, in the keybindings.json file (CTRL+P and then type keybindings.json), modify the CTRL+] and CTRL+[ keys to execute the newly created commands:



[
{
"key": "ctrl+]",
"command": "macros.tab4times",
"when": "editorTextFocus && !editorReadonly"
},
{
"key": "ctrl+[",
"command": "macros.shifttab4times",
"when": "editorTextFocus && !editorReadonly"
}
]


After saving these configurations, go to your text. Now press the CTRL+] and CTRL+[ to see you desired behavior of indentation and outdentation, respectiovely.



Hope it helps.






share|improve this answer





















  • 1





    Thanks for doing this! I'm busy with some other things right now and can't try it out, but I'll assume it works as described... giving you the bounty before the clock runs out. :-)

    – HostileFork
    Nov 25 '18 at 3:24













  • Thank you, @HostileFork. I really appreciate that you trusted my answer. It worked well for me, but please let me know if any of the steps is not clear while you implement it. Have a wonderful weekend!

    – TeeKea
    Nov 25 '18 at 3:58
















1





+100









If you set the Tab size to 1, it will do the same job as the extension you referenced.



You can set the Tab or Space size by clicking on the bottom-right corner:



Change Tab/Space size



Click on Spaces:4. Then, select Indent Using Spaces or Indent Using Tabs and choose the size 1.



UPDATE:



I found an approach that fully satisfies your requirement (though it's through an extension). After choosing a Tab/Space size of 1, install and load the multi-command extension to perform the 1-space indentation 'four' times. Then, go to your settings.json (File > Preferences > Settings) and add these two commands:



{
"macros": {
"tab4times": [
"tab",
"tab",
"tab",
"tab"
],
"shifttab4times": [
"outdent",
"outdent",
"outdent",
"outdent"
]
}
}


Then, in the keybindings.json file (CTRL+P and then type keybindings.json), modify the CTRL+] and CTRL+[ keys to execute the newly created commands:



[
{
"key": "ctrl+]",
"command": "macros.tab4times",
"when": "editorTextFocus && !editorReadonly"
},
{
"key": "ctrl+[",
"command": "macros.shifttab4times",
"when": "editorTextFocus && !editorReadonly"
}
]


After saving these configurations, go to your text. Now press the CTRL+] and CTRL+[ to see you desired behavior of indentation and outdentation, respectiovely.



Hope it helps.






share|improve this answer





















  • 1





    Thanks for doing this! I'm busy with some other things right now and can't try it out, but I'll assume it works as described... giving you the bounty before the clock runs out. :-)

    – HostileFork
    Nov 25 '18 at 3:24













  • Thank you, @HostileFork. I really appreciate that you trusted my answer. It worked well for me, but please let me know if any of the steps is not clear while you implement it. Have a wonderful weekend!

    – TeeKea
    Nov 25 '18 at 3:58














1





+100







1





+100



1




+100





If you set the Tab size to 1, it will do the same job as the extension you referenced.



You can set the Tab or Space size by clicking on the bottom-right corner:



Change Tab/Space size



Click on Spaces:4. Then, select Indent Using Spaces or Indent Using Tabs and choose the size 1.



UPDATE:



I found an approach that fully satisfies your requirement (though it's through an extension). After choosing a Tab/Space size of 1, install and load the multi-command extension to perform the 1-space indentation 'four' times. Then, go to your settings.json (File > Preferences > Settings) and add these two commands:



{
"macros": {
"tab4times": [
"tab",
"tab",
"tab",
"tab"
],
"shifttab4times": [
"outdent",
"outdent",
"outdent",
"outdent"
]
}
}


Then, in the keybindings.json file (CTRL+P and then type keybindings.json), modify the CTRL+] and CTRL+[ keys to execute the newly created commands:



[
{
"key": "ctrl+]",
"command": "macros.tab4times",
"when": "editorTextFocus && !editorReadonly"
},
{
"key": "ctrl+[",
"command": "macros.shifttab4times",
"when": "editorTextFocus && !editorReadonly"
}
]


After saving these configurations, go to your text. Now press the CTRL+] and CTRL+[ to see you desired behavior of indentation and outdentation, respectiovely.



Hope it helps.






share|improve this answer















If you set the Tab size to 1, it will do the same job as the extension you referenced.



You can set the Tab or Space size by clicking on the bottom-right corner:



Change Tab/Space size



Click on Spaces:4. Then, select Indent Using Spaces or Indent Using Tabs and choose the size 1.



UPDATE:



I found an approach that fully satisfies your requirement (though it's through an extension). After choosing a Tab/Space size of 1, install and load the multi-command extension to perform the 1-space indentation 'four' times. Then, go to your settings.json (File > Preferences > Settings) and add these two commands:



{
"macros": {
"tab4times": [
"tab",
"tab",
"tab",
"tab"
],
"shifttab4times": [
"outdent",
"outdent",
"outdent",
"outdent"
]
}
}


Then, in the keybindings.json file (CTRL+P and then type keybindings.json), modify the CTRL+] and CTRL+[ keys to execute the newly created commands:



[
{
"key": "ctrl+]",
"command": "macros.tab4times",
"when": "editorTextFocus && !editorReadonly"
},
{
"key": "ctrl+[",
"command": "macros.shifttab4times",
"when": "editorTextFocus && !editorReadonly"
}
]


After saving these configurations, go to your text. Now press the CTRL+] and CTRL+[ to see you desired behavior of indentation and outdentation, respectiovely.



Hope it helps.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 25 '18 at 1:45

























answered Nov 24 '18 at 21:22









TeeKeaTeeKea

3,22851731




3,22851731








  • 1





    Thanks for doing this! I'm busy with some other things right now and can't try it out, but I'll assume it works as described... giving you the bounty before the clock runs out. :-)

    – HostileFork
    Nov 25 '18 at 3:24













  • Thank you, @HostileFork. I really appreciate that you trusted my answer. It worked well for me, but please let me know if any of the steps is not clear while you implement it. Have a wonderful weekend!

    – TeeKea
    Nov 25 '18 at 3:58














  • 1





    Thanks for doing this! I'm busy with some other things right now and can't try it out, but I'll assume it works as described... giving you the bounty before the clock runs out. :-)

    – HostileFork
    Nov 25 '18 at 3:24













  • Thank you, @HostileFork. I really appreciate that you trusted my answer. It worked well for me, but please let me know if any of the steps is not clear while you implement it. Have a wonderful weekend!

    – TeeKea
    Nov 25 '18 at 3:58








1




1





Thanks for doing this! I'm busy with some other things right now and can't try it out, but I'll assume it works as described... giving you the bounty before the clock runs out. :-)

– HostileFork
Nov 25 '18 at 3:24







Thanks for doing this! I'm busy with some other things right now and can't try it out, but I'll assume it works as described... giving you the bounty before the clock runs out. :-)

– HostileFork
Nov 25 '18 at 3:24















Thank you, @HostileFork. I really appreciate that you trusted my answer. It worked well for me, but please let me know if any of the steps is not clear while you implement it. Have a wonderful weekend!

– TeeKea
Nov 25 '18 at 3:58





Thank you, @HostileFork. I really appreciate that you trusted my answer. It worked well for me, but please let me know if any of the steps is not clear while you implement it. Have a wonderful weekend!

– TeeKea
Nov 25 '18 at 3:58




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53326134%2fpreserve-spacing-on-indent-or-outdent-with-tab-in-vscode%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

404 Error Contact Form 7 ajax form submitting

How to know if a Active Directory user can login interactively

Refactoring coordinates for Minecraft Pi buildings written in Python