Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I fix the indentation of an entire file in Vi?

In Vim, what is the command to correct the indentation of all the lines?

Often times I'll copy and paste code into a remote terminal and have the whole thing messed up. I want to fix this in one fell swoop.

like image 633
mmcdole Avatar asked Feb 03 '09 05:02

mmcdole


People also ask

How do I indent a whole file in Vim?

Start in the top of a file (to get there, press gg anywhere in the file.). Then press =G , and Vim will fix the indentation in the whole file. If you don't start in the beginning of the file, it will fix indentation from current line to the bottom of file.

Why does Vim auto indent?

autoindent essentially tells vim to apply the indentation of the current line to the next (created by pressing enter in insert mode or with O or o in normal mode. smartindent reacts to the syntax/style of the code you are editing (especially for C). When having it on you also should have autoindent on.

How do I turn off auto indent in Vim?

vim Inserting text Disable auto-indent to paste code Just press F3 in insert mode, and paste. Press F3 again to exit from the paste mode.

What is Vim smart indent?

Vim has four methods of indentation, namely: Autoindent – this method uses indent from the previous line for the file type you are editing. smartindent – smartindent works similarly to autoindent but recognizes the syntax for some languages such as C language.


1 Answers

=, the indent command can take motions. So, gg to get the start of the file, = to indent, G to the end of the file, gg=G.

like image 70
Logan Capaldo Avatar answered Sep 25 '22 13:09

Logan Capaldo