I have a LaTeX source file with its indentation messed up.
I am looking for a way to force vim (may be through one of vim-latex-suite
commands) to re-run the automatic indentation commands over the whole file once again.
I can easily get rid of the messed up indentation by eating up all the white spaces in the beginning of each line with a simple regex :%s/^\s\+//
. My problem is how to re-run the automatic indentation commands over the whole file.
( I am basically looking for something like the smart indent
in MATLAB Editor or some other text editor, which can re-indent already existing text).
Best Answer
Method #1: vim
I believe you can do what you want with the following keyboard commands in
vim
, as follows.NOTE:
=
, the indent command can take motions.So:
gg
to get the start of the file=
to indentG
to the end of the filePutting it all together:
gg=G
.Method #2: without vim
This isn't a
vim
solution but I came across this Perl script titledLaTeXTidy.pl
which might be more useful if you have multiple files you have to do this with.The original script and a copy on pastebin:
Example
To run it you'll need to make it executable after downloading it and then just run it passing it the name of a latex file.
download
permissions and running