Use perltidy in VIM to beautify Perl code

Source: Internet
Author: User
Tags coding standards

 

Beautiful perl formatCodeIt is not only pleasing to the eye, but also easy to read.

Perltidy is a small project of SourceForge. After we finish writing the messy code, he can organize the code like magic. Come and try it !!!

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

Installation Method:

Enter the decompressed directory and run the following command:
Perl makefile. pl
Make
Make Test
Make install

Usage:
Configure Vim so that when writing code, we can beautify our code without leaving vim.
Add the following in the last line of/etc/vimrc: (the shortcut key PT is used to call perltidy)
Map, PT: %! Perltidy

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

Note:

1) if you need to install it in your home directory, as shown below:
Perl makefile. pl prefix = ~ /Perl
Setenv perl5lib ~ /Perl/lib/site_perl/5.8.3

2) use config during the call. The default value is. perltidyrc in the home directory:
By default, perltidy yourscript will generate the yourscript. TDY file. You need to manually overwrite the original file with the TDY file.
If you only use the specified configuration file perltidy-Pro = tidyconfigfile yourscript> yourscript. TDY, then overwrite the original file with the TDY file.

Default configuration file instance. perltidyrc file:
# This is a simple of A. perltidyrc configuration file
# This implements a highly spaced Style
-BL # braces on New Lines
-Pt = 0 # Parens not tight at 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 are 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
-Native K = s # -- nospace-after-keyword = s removes keywords.
-DWS # -- delete-old-whitespace

Complete!

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.