Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vim question: tabbing a block of code

Tags:

vim

How do you tab a block of code, to the right to the left, on Vim?

like image 915
vehomzzz Avatar asked Sep 10 '09 21:09

vehomzzz


People also ask

How do I tab chunk of code in Vim?

My favorite way is to select your block of code (with [V]isual line mode normally), then press > or If you want to tab more than once, 2> or 3> to repeat it. If you didn't tab enough (or tabbed too much) then type "gv" to reselect your selection and try again.

How do I indent a block of code in Vim?

To indent the current line, or a visual block: ctrl-t, ctrl-d - indent current line forward, backwards (insert mode) visual > or < - indent block by sw (repeat with . ) then try hitting the F5 key while in insert mode (or just :set paste ).


3 Answers

Short Answer:

  • V select lines by and then >

    and for 3 tabs:

  • V, 3 and then >


My favorite way is to select your block of code (with [V]isual line mode normally), then press > or If you want to tab more than once, 2> or 3> to repeat it.

If you didn't tab enough (or tabbed too much) then type "gv" to reselect your selection and try again.

To move a block of code, select it with [V]isual line mode and then press "d". This is the "Cut" operation.

Then move your cursor to the place you want it to go, and press "p". This is the "Paste" operation.

You can also try auto-tabbing a block of code by selecting it with [V]isual line mode, and pressing "=".

like image 87
Fragsworth Avatar answered Sep 22 '22 01:09

Fragsworth


The page "Indenting source code" should give you all the information you need.

like image 44
dcruz Avatar answered Sep 19 '22 01:09

dcruz


To indent the internal block containing the cursor, do: >iB To indent the internal block including the enclosing braces, do: >aB

You can replace '>' with '<' to indent left.

To auto-indent press == (or = if you have highlighted text).

like image 4
Jordan Parmer Avatar answered Sep 20 '22 01:09

Jordan Parmer