Indent several lines with VIM? The 2019 Stack Overflow Developer Survey Results Are InHow to yank a particular line without moving the cursor in vim?Auto indent / format code for Vim?VIM - how to minimize tabindent on hilighted textIndent the middle of multiple linesVim gg=G (reindent whole file) without losing current positionvim how to keep cursor position while copying textWrap all lines with character sequence in vimVim cursor highlights wrong positionvim: Match WORD in current block with balanced bracketsIn vim, how to detach/open an exist window to a new tab?

Is "plugging out" electronic devices an American expression?

When should I buy a clipper card after flying to OAK?

If a Druid sees an animal’s corpse, can they Wild Shape into that animal?

Did Scotland spend $250,000 for the slogan "Welcome to Scotland"?

Protecting Dualbooting Windows from dangerous code (like rm -rf)

A poker game description that does not feel gimmicky

Delete all lines which don't have n characters before delimiter

How technical should a Scrum Master be to effectively remove impediments?

How to manage monthly salary

How are circuits which use complex ICs normally simulated?

What do hard-Brexiteers want with respect to the Irish border?

Do these rules for Critical Successes and Critical Failures seem fair?

Are spiders unable to hurt humans, especially very small spiders?

For what reasons would an animal species NOT cross a *horizontal* land bridge?

Button changing it's text & action. Good or terrible?

What are the motivations for publishing new editions of an existing textbook, beyond new discoveries in a field?

What does Linus Torvalds mean when he says that Git "never ever" tracks a file?

Right tool to dig six foot holes?

What could be the right powersource for 15 seconds lifespan disposable giant chainsaw?

Why hard-Brexiteers don't insist on a hard border to prevent illegal immigration after Brexit?

How come people say “Would of”?

Shouldn't "much" here be used instead of "more"?

FPGA - DIY Programming

Did Section 31 appear in Star Trek: The Next Generation?



Indent several lines with VIM?



The 2019 Stack Overflow Developer Survey Results Are InHow to yank a particular line without moving the cursor in vim?Auto indent / format code for Vim?VIM - how to minimize tabindent on hilighted textIndent the middle of multiple linesVim gg=G (reindent whole file) without losing current positionvim how to keep cursor position while copying textWrap all lines with character sequence in vimVim cursor highlights wrong positionvim: Match WORD in current block with balanced bracketsIn vim, how to detach/open an exist window to a new tab?



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








40















For example, I'm editing this code:



<html>
<body>
<script>
var a = 10;
a += 100;
</script>
</body>
</html>


now I need to indent the script line:



<html>
<body>
<script>
var a = 10;
a += 100;
</script>
</body>
</html>


How could I do this without moving cursor to the begin of each line and press Tab?










share|improve this question
























  • In command mode: gg=G

    – Prince John Wesley
    Jul 19 '11 at 8:22


















40















For example, I'm editing this code:



<html>
<body>
<script>
var a = 10;
a += 100;
</script>
</body>
</html>


now I need to indent the script line:



<html>
<body>
<script>
var a = 10;
a += 100;
</script>
</body>
</html>


How could I do this without moving cursor to the begin of each line and press Tab?










share|improve this question
























  • In command mode: gg=G

    – Prince John Wesley
    Jul 19 '11 at 8:22














40












40








40


14






For example, I'm editing this code:



<html>
<body>
<script>
var a = 10;
a += 100;
</script>
</body>
</html>


now I need to indent the script line:



<html>
<body>
<script>
var a = 10;
a += 100;
</script>
</body>
</html>


How could I do this without moving cursor to the begin of each line and press Tab?










share|improve this question
















For example, I'm editing this code:



<html>
<body>
<script>
var a = 10;
a += 100;
</script>
</body>
</html>


now I need to indent the script line:



<html>
<body>
<script>
var a = 10;
a += 100;
</script>
</body>
</html>


How could I do this without moving cursor to the begin of each line and press Tab?







vim vi






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Apr 7 at 15:32









Saca

1034




1034










asked Jul 19 '11 at 8:13









wong2wong2

848398




848398












  • In command mode: gg=G

    – Prince John Wesley
    Jul 19 '11 at 8:22


















  • In command mode: gg=G

    – Prince John Wesley
    Jul 19 '11 at 8:22

















In command mode: gg=G

– Prince John Wesley
Jul 19 '11 at 8:22






In command mode: gg=G

– Prince John Wesley
Jul 19 '11 at 8:22











5 Answers
5






active

oldest

votes


















64














Press V to switch to VISUAL LINE mode and highlight the lines you want to indent by pressing j. Then press > to indent them. So the complete command would be Vjjj>.



Alternatively, put your cursor on the <script> tag and use 4>> to indent four lines.






share|improve this answer


















  • 1





    Also, when changing multiple indent levels, . is extremely useful (it will move the same 'block' wether with visual, marks or a [count] like the above 4>>).

    – Pif
    Jan 17 '12 at 11:18











  • Also, if your syntax file can do tag matching, you can have your cursor on the word "script", and press v for visual mode, % to go to matching tag, and > to indent or = to auto indent based on syntax, so the total command would be v%> or v%=

    – ben
    Feb 1 '13 at 20:42











  • This works with character-wise visual mode too (lowercase v), which is a bit easier to type. So vjjj>

    – James Scriven
    Jan 3 '16 at 0:59


















14














To supplement the above answer, take a look here.
https://stackoverflow.com/questions/235839/how-do-i-indent-multiple-lines-quickly-in-vi



There are more than one way to do this, and I can't hope to compete with documentation already provided there.



My personal favorite is == to auto-indent. 5== to auto-indent 5 lines.






share|improve this answer
































    10














    To indent the all the lines below the current line



    =G


    So, to indent entire file, go to the beginning of the file (gg) and then indent all the lines below the current line (=G)



    gg=G


    To indent the current line



    ==


    So, to indent n lines below the current line



    n==


    For example, to indent 4 lines below the current line



    4==


    These are the simplest commands to indent multiple lines.






    share|improve this answer
































      7














      If it was me, I would notice that there are 4 lines to indent, position onto the top line and then type >4>. If there were too many lines to count, I would position onto the top line and type mk to make a mark named k, then position onto the bottom line (which might be several screenfuls away), and type >'k






      share|improve this answer






























        3














        Here is a nice approach, if you are trying to indent over a great number of lines:



        :/<script>/,/</script>/ >>





        share|improve this answer























          Your Answer








          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "106"
          ;
          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: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          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%2funix.stackexchange.com%2fquestions%2f16939%2findent-several-lines-with-vim%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          5 Answers
          5






          active

          oldest

          votes








          5 Answers
          5






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          64














          Press V to switch to VISUAL LINE mode and highlight the lines you want to indent by pressing j. Then press > to indent them. So the complete command would be Vjjj>.



          Alternatively, put your cursor on the <script> tag and use 4>> to indent four lines.






          share|improve this answer


















          • 1





            Also, when changing multiple indent levels, . is extremely useful (it will move the same 'block' wether with visual, marks or a [count] like the above 4>>).

            – Pif
            Jan 17 '12 at 11:18











          • Also, if your syntax file can do tag matching, you can have your cursor on the word "script", and press v for visual mode, % to go to matching tag, and > to indent or = to auto indent based on syntax, so the total command would be v%> or v%=

            – ben
            Feb 1 '13 at 20:42











          • This works with character-wise visual mode too (lowercase v), which is a bit easier to type. So vjjj>

            – James Scriven
            Jan 3 '16 at 0:59















          64














          Press V to switch to VISUAL LINE mode and highlight the lines you want to indent by pressing j. Then press > to indent them. So the complete command would be Vjjj>.



          Alternatively, put your cursor on the <script> tag and use 4>> to indent four lines.






          share|improve this answer


















          • 1





            Also, when changing multiple indent levels, . is extremely useful (it will move the same 'block' wether with visual, marks or a [count] like the above 4>>).

            – Pif
            Jan 17 '12 at 11:18











          • Also, if your syntax file can do tag matching, you can have your cursor on the word "script", and press v for visual mode, % to go to matching tag, and > to indent or = to auto indent based on syntax, so the total command would be v%> or v%=

            – ben
            Feb 1 '13 at 20:42











          • This works with character-wise visual mode too (lowercase v), which is a bit easier to type. So vjjj>

            – James Scriven
            Jan 3 '16 at 0:59













          64












          64








          64







          Press V to switch to VISUAL LINE mode and highlight the lines you want to indent by pressing j. Then press > to indent them. So the complete command would be Vjjj>.



          Alternatively, put your cursor on the <script> tag and use 4>> to indent four lines.






          share|improve this answer













          Press V to switch to VISUAL LINE mode and highlight the lines you want to indent by pressing j. Then press > to indent them. So the complete command would be Vjjj>.



          Alternatively, put your cursor on the <script> tag and use 4>> to indent four lines.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jul 19 '11 at 8:30









          dogbanedogbane

          14.8k106458




          14.8k106458







          • 1





            Also, when changing multiple indent levels, . is extremely useful (it will move the same 'block' wether with visual, marks or a [count] like the above 4>>).

            – Pif
            Jan 17 '12 at 11:18











          • Also, if your syntax file can do tag matching, you can have your cursor on the word "script", and press v for visual mode, % to go to matching tag, and > to indent or = to auto indent based on syntax, so the total command would be v%> or v%=

            – ben
            Feb 1 '13 at 20:42











          • This works with character-wise visual mode too (lowercase v), which is a bit easier to type. So vjjj>

            – James Scriven
            Jan 3 '16 at 0:59












          • 1





            Also, when changing multiple indent levels, . is extremely useful (it will move the same 'block' wether with visual, marks or a [count] like the above 4>>).

            – Pif
            Jan 17 '12 at 11:18











          • Also, if your syntax file can do tag matching, you can have your cursor on the word "script", and press v for visual mode, % to go to matching tag, and > to indent or = to auto indent based on syntax, so the total command would be v%> or v%=

            – ben
            Feb 1 '13 at 20:42











          • This works with character-wise visual mode too (lowercase v), which is a bit easier to type. So vjjj>

            – James Scriven
            Jan 3 '16 at 0:59







          1




          1





          Also, when changing multiple indent levels, . is extremely useful (it will move the same 'block' wether with visual, marks or a [count] like the above 4>>).

          – Pif
          Jan 17 '12 at 11:18





          Also, when changing multiple indent levels, . is extremely useful (it will move the same 'block' wether with visual, marks or a [count] like the above 4>>).

          – Pif
          Jan 17 '12 at 11:18













          Also, if your syntax file can do tag matching, you can have your cursor on the word "script", and press v for visual mode, % to go to matching tag, and > to indent or = to auto indent based on syntax, so the total command would be v%> or v%=

          – ben
          Feb 1 '13 at 20:42





          Also, if your syntax file can do tag matching, you can have your cursor on the word "script", and press v for visual mode, % to go to matching tag, and > to indent or = to auto indent based on syntax, so the total command would be v%> or v%=

          – ben
          Feb 1 '13 at 20:42













          This works with character-wise visual mode too (lowercase v), which is a bit easier to type. So vjjj>

          – James Scriven
          Jan 3 '16 at 0:59





          This works with character-wise visual mode too (lowercase v), which is a bit easier to type. So vjjj>

          – James Scriven
          Jan 3 '16 at 0:59













          14














          To supplement the above answer, take a look here.
          https://stackoverflow.com/questions/235839/how-do-i-indent-multiple-lines-quickly-in-vi



          There are more than one way to do this, and I can't hope to compete with documentation already provided there.



          My personal favorite is == to auto-indent. 5== to auto-indent 5 lines.






          share|improve this answer





























            14














            To supplement the above answer, take a look here.
            https://stackoverflow.com/questions/235839/how-do-i-indent-multiple-lines-quickly-in-vi



            There are more than one way to do this, and I can't hope to compete with documentation already provided there.



            My personal favorite is == to auto-indent. 5== to auto-indent 5 lines.






            share|improve this answer



























              14












              14








              14







              To supplement the above answer, take a look here.
              https://stackoverflow.com/questions/235839/how-do-i-indent-multiple-lines-quickly-in-vi



              There are more than one way to do this, and I can't hope to compete with documentation already provided there.



              My personal favorite is == to auto-indent. 5== to auto-indent 5 lines.






              share|improve this answer















              To supplement the above answer, take a look here.
              https://stackoverflow.com/questions/235839/how-do-i-indent-multiple-lines-quickly-in-vi



              There are more than one way to do this, and I can't hope to compete with documentation already provided there.



              My personal favorite is == to auto-indent. 5== to auto-indent 5 lines.







              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited May 23 '17 at 12:39









              Community

              1




              1










              answered Jul 20 '11 at 15:16









              user606723user606723

              6811413




              6811413





















                  10














                  To indent the all the lines below the current line



                  =G


                  So, to indent entire file, go to the beginning of the file (gg) and then indent all the lines below the current line (=G)



                  gg=G


                  To indent the current line



                  ==


                  So, to indent n lines below the current line



                  n==


                  For example, to indent 4 lines below the current line



                  4==


                  These are the simplest commands to indent multiple lines.






                  share|improve this answer





























                    10














                    To indent the all the lines below the current line



                    =G


                    So, to indent entire file, go to the beginning of the file (gg) and then indent all the lines below the current line (=G)



                    gg=G


                    To indent the current line



                    ==


                    So, to indent n lines below the current line



                    n==


                    For example, to indent 4 lines below the current line



                    4==


                    These are the simplest commands to indent multiple lines.






                    share|improve this answer



























                      10












                      10








                      10







                      To indent the all the lines below the current line



                      =G


                      So, to indent entire file, go to the beginning of the file (gg) and then indent all the lines below the current line (=G)



                      gg=G


                      To indent the current line



                      ==


                      So, to indent n lines below the current line



                      n==


                      For example, to indent 4 lines below the current line



                      4==


                      These are the simplest commands to indent multiple lines.






                      share|improve this answer















                      To indent the all the lines below the current line



                      =G


                      So, to indent entire file, go to the beginning of the file (gg) and then indent all the lines below the current line (=G)



                      gg=G


                      To indent the current line



                      ==


                      So, to indent n lines below the current line



                      n==


                      For example, to indent 4 lines below the current line



                      4==


                      These are the simplest commands to indent multiple lines.







                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited Aug 9 '14 at 7:38

























                      answered Jul 31 '14 at 4:33









                      Sagar JainSagar Jain

                      20124




                      20124





















                          7














                          If it was me, I would notice that there are 4 lines to indent, position onto the top line and then type >4>. If there were too many lines to count, I would position onto the top line and type mk to make a mark named k, then position onto the bottom line (which might be several screenfuls away), and type >'k






                          share|improve this answer



























                            7














                            If it was me, I would notice that there are 4 lines to indent, position onto the top line and then type >4>. If there were too many lines to count, I would position onto the top line and type mk to make a mark named k, then position onto the bottom line (which might be several screenfuls away), and type >'k






                            share|improve this answer

























                              7












                              7








                              7







                              If it was me, I would notice that there are 4 lines to indent, position onto the top line and then type >4>. If there were too many lines to count, I would position onto the top line and type mk to make a mark named k, then position onto the bottom line (which might be several screenfuls away), and type >'k






                              share|improve this answer













                              If it was me, I would notice that there are 4 lines to indent, position onto the top line and then type >4>. If there were too many lines to count, I would position onto the top line and type mk to make a mark named k, then position onto the bottom line (which might be several screenfuls away), and type >'k







                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered Aug 11 '11 at 5:21









                              Michael DillonMichael Dillon

                              79737




                              79737





















                                  3














                                  Here is a nice approach, if you are trying to indent over a great number of lines:



                                  :/<script>/,/</script>/ >>





                                  share|improve this answer



























                                    3














                                    Here is a nice approach, if you are trying to indent over a great number of lines:



                                    :/<script>/,/</script>/ >>





                                    share|improve this answer

























                                      3












                                      3








                                      3







                                      Here is a nice approach, if you are trying to indent over a great number of lines:



                                      :/<script>/,/</script>/ >>





                                      share|improve this answer













                                      Here is a nice approach, if you are trying to indent over a great number of lines:



                                      :/<script>/,/</script>/ >>






                                      share|improve this answer












                                      share|improve this answer



                                      share|improve this answer










                                      answered Aug 8 '11 at 5:46









                                      bhinesleybhinesley

                                      55847




                                      55847



























                                          draft saved

                                          draft discarded
















































                                          Thanks for contributing an answer to Unix & Linux Stack Exchange!


                                          • 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%2funix.stackexchange.com%2fquestions%2f16939%2findent-several-lines-with-vim%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

                                          getting Checkpoint VPN SSL Network Extender working in the command lineHow to connect to CheckPoint VPN on Ubuntu 18.04LTS?Will the Linux ( red-hat ) Open VPNC Client connect to checkpoint or nortel VPN gateways?VPN client for linux machine + support checkpoint gatewayVPN SSL Network Extender in FirefoxLinux Checkpoint SNX tool configuration issuesCheck Point - Connect under Linux - snx + OTPSNX VPN Ububuntu 18.XXUsing Checkpoint VPN SSL Network Extender CLI with certificateVPN with network manager (nm-applet) is not workingWill the Linux ( red-hat ) Open VPNC Client connect to checkpoint or nortel VPN gateways?VPN client for linux machine + support checkpoint gatewayImport VPN config files to NetworkManager from command lineTrouble connecting to VPN using network-manager, while command line worksStart a VPN connection with PPTP protocol on command linestarting a docker service daemon breaks the vpn networkCan't connect to vpn with Network-managerVPN SSL Network Extender in FirefoxUsing Checkpoint VPN SSL Network Extender CLI with certificate

                                          Cannot Extend partition with GParted The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) 2019 Community Moderator Election ResultsCan't increase partition size with GParted?GParted doesn't recognize the unallocated space after my current partitionWhat is the best way to add unallocated space located before to Ubuntu 12.04 partition with GParted live?I can't figure out how to extend my Arch home partition into free spaceGparted Linux Mint 18.1 issueTrying to extend but swap partition is showing as Unknown in Gparted, shows proper from fdiskRearrange partitions in gparted to extend a partitionUnable to extend partition even though unallocated space is next to it using GPartedAllocate free space to root partitiongparted: how to merge unallocated space with a partition

                                          Marilyn Monroe Ny fiainany manokana | Jereo koa | Meny fitetezanafanitarana azy.