How to indent/format a selection of code in VSCode with ctrl+shift+f












24














I want to indent a specific section of code in VSCode



I read How do you format code in Visual Studio Code (VSCode) post that gives shortcuts to indent the whole code but it doesn't work when selecting a specific section of code.



I tried ctrl+shift+F after selecting some line in my code but the whole file is indented. I'm on Windows with VSCode Insider 1.8.0. Any help is appreciated.










share|improve this question





























    24














    I want to indent a specific section of code in VSCode



    I read How do you format code in Visual Studio Code (VSCode) post that gives shortcuts to indent the whole code but it doesn't work when selecting a specific section of code.



    I tried ctrl+shift+F after selecting some line in my code but the whole file is indented. I'm on Windows with VSCode Insider 1.8.0. Any help is appreciated.










    share|improve this question



























      24












      24








      24


      11





      I want to indent a specific section of code in VSCode



      I read How do you format code in Visual Studio Code (VSCode) post that gives shortcuts to indent the whole code but it doesn't work when selecting a specific section of code.



      I tried ctrl+shift+F after selecting some line in my code but the whole file is indented. I'm on Windows with VSCode Insider 1.8.0. Any help is appreciated.










      share|improve this question















      I want to indent a specific section of code in VSCode



      I read How do you format code in Visual Studio Code (VSCode) post that gives shortcuts to indent the whole code but it doesn't work when selecting a specific section of code.



      I tried ctrl+shift+F after selecting some line in my code but the whole file is indented. I'm on Windows with VSCode Insider 1.8.0. Any help is appreciated.







      visual-studio-code indentation






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Aug 13 at 7:58









      darshan a n

      326114




      326114










      asked Nov 8 '16 at 17:25









      Damien Leroux

      5,43932244




      5,43932244
























          3 Answers
          3






          active

          oldest

          votes


















          51















          I want to indent a specific section of code in VSCode:





          • Select the lines you want to indent,

          • use Ctrl + ] to indent them.


          If you want to format a section (instead of indent it):




          • Select the lines you want to format,

          • use Ctrl + K, Ctrl + F to format them.






          share|improve this answer























          • On my keyboard, ] and ) are on the same key. So when using it, it unindent the seleciton. Ctrl + K, Ctrl + F works well. Thank you!
            – Damien Leroux
            Nov 9 '16 at 9:24








          • 2




            Shift + Alt + F can also be used for formatting ( Windows Platform )
            – SridharKritha
            May 2 '17 at 16:29






          • 1




            What about OSX?
            – GreenAsJade
            Jul 8 at 1:22










          • @GreenAsJade On MacOS, Cmd + ] (indent) and Cmd + [ (unindent) works for me.
            – Alex Johnson
            Jul 12 at 13:33












          • @AlexJohnson sorry, I was asking about what about OSX format selected lines.
            – GreenAsJade
            Jul 14 at 0:29





















          38















          • you can also indent a whole section by selecting it and clicking
            TAB

          • and also indent backward using Shift+TAB


          and of course for auto indentation and formatting, following the language your using you can see which good extension do the good job, and which formatters to install or which parameters settings to enable or set. Each language and it's available tools. Just make sure to read well the documentation of the extension, to install and set all what it need. Up to now indentation problem bother me with python when copy pasting a block of code, if that's the case here how you solve that https://stackoverflow.com/a/46899704/7668448 .






          share|improve this answer

















          • 1




            this doesn't work in VS Code for me, pressing tab while selecting text simply adds a tab where my cursor is
            – Abe Fehr
            Aug 6 at 13:38










          • I think you selected only a portion of one line text. For that to work, you have too cases: you have selected multi-lines and in such a case it doesn't matter how much you selected, it will work. The other case is to select the whole line where it will work too. If you select just a portion from one line, then the behavior is that a tab will be inserted in place of the selected text. I tested that in both windows and linux systems. Confirm if it's the same with you, or there is something wrong with your config.
            – Mohamed Allal
            Aug 14 at 21:59



















          1














          In OSx "Document Format" , Select all lines that you need format



          Option + Shift + F





          share|improve this answer





















          • Thankyou thankyou!
            – GreenAsJade
            Dec 7 at 8:13











          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%2f40492960%2fhow-to-indent-format-a-selection-of-code-in-vscode-with-ctrlshiftf%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          3 Answers
          3






          active

          oldest

          votes








          3 Answers
          3






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          51















          I want to indent a specific section of code in VSCode:





          • Select the lines you want to indent,

          • use Ctrl + ] to indent them.


          If you want to format a section (instead of indent it):




          • Select the lines you want to format,

          • use Ctrl + K, Ctrl + F to format them.






          share|improve this answer























          • On my keyboard, ] and ) are on the same key. So when using it, it unindent the seleciton. Ctrl + K, Ctrl + F works well. Thank you!
            – Damien Leroux
            Nov 9 '16 at 9:24








          • 2




            Shift + Alt + F can also be used for formatting ( Windows Platform )
            – SridharKritha
            May 2 '17 at 16:29






          • 1




            What about OSX?
            – GreenAsJade
            Jul 8 at 1:22










          • @GreenAsJade On MacOS, Cmd + ] (indent) and Cmd + [ (unindent) works for me.
            – Alex Johnson
            Jul 12 at 13:33












          • @AlexJohnson sorry, I was asking about what about OSX format selected lines.
            – GreenAsJade
            Jul 14 at 0:29


















          51















          I want to indent a specific section of code in VSCode:





          • Select the lines you want to indent,

          • use Ctrl + ] to indent them.


          If you want to format a section (instead of indent it):




          • Select the lines you want to format,

          • use Ctrl + K, Ctrl + F to format them.






          share|improve this answer























          • On my keyboard, ] and ) are on the same key. So when using it, it unindent the seleciton. Ctrl + K, Ctrl + F works well. Thank you!
            – Damien Leroux
            Nov 9 '16 at 9:24








          • 2




            Shift + Alt + F can also be used for formatting ( Windows Platform )
            – SridharKritha
            May 2 '17 at 16:29






          • 1




            What about OSX?
            – GreenAsJade
            Jul 8 at 1:22










          • @GreenAsJade On MacOS, Cmd + ] (indent) and Cmd + [ (unindent) works for me.
            – Alex Johnson
            Jul 12 at 13:33












          • @AlexJohnson sorry, I was asking about what about OSX format selected lines.
            – GreenAsJade
            Jul 14 at 0:29
















          51












          51








          51







          I want to indent a specific section of code in VSCode:





          • Select the lines you want to indent,

          • use Ctrl + ] to indent them.


          If you want to format a section (instead of indent it):




          • Select the lines you want to format,

          • use Ctrl + K, Ctrl + F to format them.






          share|improve this answer















          I want to indent a specific section of code in VSCode:





          • Select the lines you want to indent,

          • use Ctrl + ] to indent them.


          If you want to format a section (instead of indent it):




          • Select the lines you want to format,

          • use Ctrl + K, Ctrl + F to format them.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 8 '16 at 22:46

























          answered Nov 8 '16 at 22:40









          Shaun Luttin

          57.3k32220281




          57.3k32220281












          • On my keyboard, ] and ) are on the same key. So when using it, it unindent the seleciton. Ctrl + K, Ctrl + F works well. Thank you!
            – Damien Leroux
            Nov 9 '16 at 9:24








          • 2




            Shift + Alt + F can also be used for formatting ( Windows Platform )
            – SridharKritha
            May 2 '17 at 16:29






          • 1




            What about OSX?
            – GreenAsJade
            Jul 8 at 1:22










          • @GreenAsJade On MacOS, Cmd + ] (indent) and Cmd + [ (unindent) works for me.
            – Alex Johnson
            Jul 12 at 13:33












          • @AlexJohnson sorry, I was asking about what about OSX format selected lines.
            – GreenAsJade
            Jul 14 at 0:29




















          • On my keyboard, ] and ) are on the same key. So when using it, it unindent the seleciton. Ctrl + K, Ctrl + F works well. Thank you!
            – Damien Leroux
            Nov 9 '16 at 9:24








          • 2




            Shift + Alt + F can also be used for formatting ( Windows Platform )
            – SridharKritha
            May 2 '17 at 16:29






          • 1




            What about OSX?
            – GreenAsJade
            Jul 8 at 1:22










          • @GreenAsJade On MacOS, Cmd + ] (indent) and Cmd + [ (unindent) works for me.
            – Alex Johnson
            Jul 12 at 13:33












          • @AlexJohnson sorry, I was asking about what about OSX format selected lines.
            – GreenAsJade
            Jul 14 at 0:29


















          On my keyboard, ] and ) are on the same key. So when using it, it unindent the seleciton. Ctrl + K, Ctrl + F works well. Thank you!
          – Damien Leroux
          Nov 9 '16 at 9:24






          On my keyboard, ] and ) are on the same key. So when using it, it unindent the seleciton. Ctrl + K, Ctrl + F works well. Thank you!
          – Damien Leroux
          Nov 9 '16 at 9:24






          2




          2




          Shift + Alt + F can also be used for formatting ( Windows Platform )
          – SridharKritha
          May 2 '17 at 16:29




          Shift + Alt + F can also be used for formatting ( Windows Platform )
          – SridharKritha
          May 2 '17 at 16:29




          1




          1




          What about OSX?
          – GreenAsJade
          Jul 8 at 1:22




          What about OSX?
          – GreenAsJade
          Jul 8 at 1:22












          @GreenAsJade On MacOS, Cmd + ] (indent) and Cmd + [ (unindent) works for me.
          – Alex Johnson
          Jul 12 at 13:33






          @GreenAsJade On MacOS, Cmd + ] (indent) and Cmd + [ (unindent) works for me.
          – Alex Johnson
          Jul 12 at 13:33














          @AlexJohnson sorry, I was asking about what about OSX format selected lines.
          – GreenAsJade
          Jul 14 at 0:29






          @AlexJohnson sorry, I was asking about what about OSX format selected lines.
          – GreenAsJade
          Jul 14 at 0:29















          38















          • you can also indent a whole section by selecting it and clicking
            TAB

          • and also indent backward using Shift+TAB


          and of course for auto indentation and formatting, following the language your using you can see which good extension do the good job, and which formatters to install or which parameters settings to enable or set. Each language and it's available tools. Just make sure to read well the documentation of the extension, to install and set all what it need. Up to now indentation problem bother me with python when copy pasting a block of code, if that's the case here how you solve that https://stackoverflow.com/a/46899704/7668448 .






          share|improve this answer

















          • 1




            this doesn't work in VS Code for me, pressing tab while selecting text simply adds a tab where my cursor is
            – Abe Fehr
            Aug 6 at 13:38










          • I think you selected only a portion of one line text. For that to work, you have too cases: you have selected multi-lines and in such a case it doesn't matter how much you selected, it will work. The other case is to select the whole line where it will work too. If you select just a portion from one line, then the behavior is that a tab will be inserted in place of the selected text. I tested that in both windows and linux systems. Confirm if it's the same with you, or there is something wrong with your config.
            – Mohamed Allal
            Aug 14 at 21:59
















          38















          • you can also indent a whole section by selecting it and clicking
            TAB

          • and also indent backward using Shift+TAB


          and of course for auto indentation and formatting, following the language your using you can see which good extension do the good job, and which formatters to install or which parameters settings to enable or set. Each language and it's available tools. Just make sure to read well the documentation of the extension, to install and set all what it need. Up to now indentation problem bother me with python when copy pasting a block of code, if that's the case here how you solve that https://stackoverflow.com/a/46899704/7668448 .






          share|improve this answer

















          • 1




            this doesn't work in VS Code for me, pressing tab while selecting text simply adds a tab where my cursor is
            – Abe Fehr
            Aug 6 at 13:38










          • I think you selected only a portion of one line text. For that to work, you have too cases: you have selected multi-lines and in such a case it doesn't matter how much you selected, it will work. The other case is to select the whole line where it will work too. If you select just a portion from one line, then the behavior is that a tab will be inserted in place of the selected text. I tested that in both windows and linux systems. Confirm if it's the same with you, or there is something wrong with your config.
            – Mohamed Allal
            Aug 14 at 21:59














          38












          38








          38







          • you can also indent a whole section by selecting it and clicking
            TAB

          • and also indent backward using Shift+TAB


          and of course for auto indentation and formatting, following the language your using you can see which good extension do the good job, and which formatters to install or which parameters settings to enable or set. Each language and it's available tools. Just make sure to read well the documentation of the extension, to install and set all what it need. Up to now indentation problem bother me with python when copy pasting a block of code, if that's the case here how you solve that https://stackoverflow.com/a/46899704/7668448 .






          share|improve this answer













          • you can also indent a whole section by selecting it and clicking
            TAB

          • and also indent backward using Shift+TAB


          and of course for auto indentation and formatting, following the language your using you can see which good extension do the good job, and which formatters to install or which parameters settings to enable or set. Each language and it's available tools. Just make sure to read well the documentation of the extension, to install and set all what it need. Up to now indentation problem bother me with python when copy pasting a block of code, if that's the case here how you solve that https://stackoverflow.com/a/46899704/7668448 .







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Oct 23 '17 at 23:13









          Mohamed Allal

          1,9111318




          1,9111318








          • 1




            this doesn't work in VS Code for me, pressing tab while selecting text simply adds a tab where my cursor is
            – Abe Fehr
            Aug 6 at 13:38










          • I think you selected only a portion of one line text. For that to work, you have too cases: you have selected multi-lines and in such a case it doesn't matter how much you selected, it will work. The other case is to select the whole line where it will work too. If you select just a portion from one line, then the behavior is that a tab will be inserted in place of the selected text. I tested that in both windows and linux systems. Confirm if it's the same with you, or there is something wrong with your config.
            – Mohamed Allal
            Aug 14 at 21:59














          • 1




            this doesn't work in VS Code for me, pressing tab while selecting text simply adds a tab where my cursor is
            – Abe Fehr
            Aug 6 at 13:38










          • I think you selected only a portion of one line text. For that to work, you have too cases: you have selected multi-lines and in such a case it doesn't matter how much you selected, it will work. The other case is to select the whole line where it will work too. If you select just a portion from one line, then the behavior is that a tab will be inserted in place of the selected text. I tested that in both windows and linux systems. Confirm if it's the same with you, or there is something wrong with your config.
            – Mohamed Allal
            Aug 14 at 21:59








          1




          1




          this doesn't work in VS Code for me, pressing tab while selecting text simply adds a tab where my cursor is
          – Abe Fehr
          Aug 6 at 13:38




          this doesn't work in VS Code for me, pressing tab while selecting text simply adds a tab where my cursor is
          – Abe Fehr
          Aug 6 at 13:38












          I think you selected only a portion of one line text. For that to work, you have too cases: you have selected multi-lines and in such a case it doesn't matter how much you selected, it will work. The other case is to select the whole line where it will work too. If you select just a portion from one line, then the behavior is that a tab will be inserted in place of the selected text. I tested that in both windows and linux systems. Confirm if it's the same with you, or there is something wrong with your config.
          – Mohamed Allal
          Aug 14 at 21:59




          I think you selected only a portion of one line text. For that to work, you have too cases: you have selected multi-lines and in such a case it doesn't matter how much you selected, it will work. The other case is to select the whole line where it will work too. If you select just a portion from one line, then the behavior is that a tab will be inserted in place of the selected text. I tested that in both windows and linux systems. Confirm if it's the same with you, or there is something wrong with your config.
          – Mohamed Allal
          Aug 14 at 21:59











          1














          In OSx "Document Format" , Select all lines that you need format



          Option + Shift + F





          share|improve this answer





















          • Thankyou thankyou!
            – GreenAsJade
            Dec 7 at 8:13
















          1














          In OSx "Document Format" , Select all lines that you need format



          Option + Shift + F





          share|improve this answer





















          • Thankyou thankyou!
            – GreenAsJade
            Dec 7 at 8:13














          1












          1








          1






          In OSx "Document Format" , Select all lines that you need format



          Option + Shift + F





          share|improve this answer












          In OSx "Document Format" , Select all lines that you need format



          Option + Shift + F






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 22 at 23:47









          Adrian Romero

          405




          405












          • Thankyou thankyou!
            – GreenAsJade
            Dec 7 at 8:13


















          • Thankyou thankyou!
            – GreenAsJade
            Dec 7 at 8:13
















          Thankyou thankyou!
          – GreenAsJade
          Dec 7 at 8:13




          Thankyou thankyou!
          – GreenAsJade
          Dec 7 at 8:13


















          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.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • 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%2f40492960%2fhow-to-indent-format-a-selection-of-code-in-vscode-with-ctrlshiftf%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

          Contact image not getting when fetch all contact list from iPhone by CNContact

          count number of partitions of a set with n elements into k subsets

          A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks