search

Home  >  Q&A  >  body text

How to batch indent code in vim

If multiple lines of code are selected, how to indent the selected code segments at the same time?

大家讲道理大家讲道理2762 days ago1030

reply all(5)I'll reply

  • 某草草

    某草草2017-05-27 17:46:19

    Select the code,
    Press < or add a number 3< to indent forward
    Press > or add a number 3> to indent backward

    reply
    0
  • phpcn_u1582

    phpcn_u15822017-05-27 17:46:19

    Press the > key to indent the current line
    Press the 3 >> key to indent the two lines starting from the current one and after

    reply
    0
  • 淡淡烟草味

    淡淡烟草味2017-05-27 17:46:19

    I usually use =,

    • Indent the current line: just ==

    • Indent a function: Move the cursor to the opening brace or closing brace of a function, press = + shift 5, first press =, then press shift and 5

      at the same time
    • Indent a few lines of code: just number + ==, such as 3==, if there are more lines, press more numbers, such as 100==

    • Indent an entire file of code: Press gg to get to the top of the file, then press =, then simultaneously press shift g

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-05-27 17:46:19

    Select multiple lines, then press >(shift + .), it will shrink the length of one tab, and then press . to repeat the indentation operation just now.

    reply
    0
  • ringa_lee

    ringa_lee2017-05-27 17:46:19

    Select all, shift+tab

    reply
    0
  • Cancelreply