Use Perltidy to beautify Perl code in vim

Source: Internet
Author: User
Tags coding standards

Source:

Http://www.cnblogs.com/itech/archive/2013/02/18/2915279.html

The beautifully formatted Perl code is not only pleasing to the eye, but also easy to read.

Perltidy is a small project of SourceForge, after we have written a messy code, he can be like magic to tidy up the code, come and experience it!!!

Perltidy Home: http://perltidy.sourceforge.net/perltidy.html

Installation method:

Go to the extracted directory and execute the command
Perl makefile.pl
Make
Make Test
Make install

How to use:
Configure VIM so that we can beautify our code when we write the code without leaving vim.
In the last line of/ETC/VIMRC: (meaning shortcut key pt to call Perltidy)
Map, PT:%! Perltidy

After writing the Perl code, in the VIM command mode, enter the command ", PT" to directly organize the code format.

Attention:

1) If you need to install into your own home directory, as follows:
Perl makefile.pl Prefix=~/perl
Setenv Perl5lib ~/perl/lib/site_perl/5.8.3

2) Called with Config, which defaults to. PERLTIDYRC:
In the home directory by default, Perltidy Yourscript will generate YOURSCRIPT.TDY files and need to manually overwrite the original files with TDY files.
If you only use the specified profile Perltidy-pro=tidyconfigfile yourscript > Yourscript.tdy, then overwrite the original file with the Tdy file.

The default profile instance. perltidyrc File:
# A simple of a. PERLTIDYRC configuration file
# This implements a highly spaced style
-BL # braces on new lines
-pt=0 # parens not tight @ all
-bt=0 # braces not tight
-sbt=0 # square brackets not tight

My configuration file:
-GNU # GNU Coding standards
-PBP #--perl-best-practices
-i=2 # use 2 columns per indentation level
-ci=2 # Continuation indentation is extra indentation spaces applied when a long line is broken.
-ce # Else and elsif is follow immediately after the curly brace closing the previous block
-NBL # places an opening brace on the same line as the keyword introducing it.
-bt=2 # braces not tight
-sbt=2 # square brackets not tight
-pt=2 # Tightness of curly braces, parentheses, and square brackets.
-NSFS #--space-for-semicolon
-nsak=s #--nospace-after-keyword=s removes keywords.
-DWS #--delete-old-whitespace

Use Perltidy to beautify Perl code in vim

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.