在vim中使用perltidy美化perl代码

 

格式优美的perl代码不但让人赏心悦目,而且可以方便阅读.

perltidy的是sourceforge的一个小项目,在我们写完乱七八糟的代码后,他能像变魔术一样把代码整理得漂漂亮亮,快来体验一下吧!!!

perltidy 主页: http://perltidy.sourceforge.net/perltidy.html

安装方法:

进入解压后的目录,然后执行一下命令
perl Makefile.PL
make
make test
make install

使用方法:
配置一下vim,使得我们在写代码的时候,不离开vim就可以美化我们代码。
在/etc/vimrc最后一行加入:(意思是快捷键pt来调用perltidy)
map ,pt :%! perltidy

写完perl代码后,在vim命令模式下,输入命令“,pt”就可以直接整理代码格式了。

注意:

1)如果需要安装到自己的home目录下,如下:
perl Makefile.PL PREFIX=~/perl
setenv PERL5LIB ~/perl/lib/site_perl/5.8.3

2)调用时使用config,默认为home目录下的.perltidyrc:
默认地,perltidy yourscript 将生成yourscript.tdy文件, 需要手动用tdy文件覆盖原来的文件。
如果只用指定的配置文件 perltidy -pro=tidyconfigfile yourscript > yourscript.tdy,然后在用tdy文件覆盖原来的文件。

默认的配置文件实例 .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

我的配置文件:
-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
-nsak=s # --nospace-after-keyword=s removes keywords.
-dws # --delete-old-whitespace

完!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值