zoukankan      html  css  js  c++  java
  • 在vim中使用perltidy美化perl代码

    来源:

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

    格式优美的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

  • 相关阅读:
    linux系统中不同颜色的文件夹及根目录介绍
    linux命令学习 随笔
    Happiness
    Sequence Number
    base64加密解密c++代码
    Wooden Sticks
    出租车费
    关系推断
    如何在Ubuntu中安装中文输入法
    c语言中printf("%x",-1);为什么会输出-1的十六进制补码??
  • 原文地址:https://www.cnblogs.com/spriteflk/p/5741261.html
Copyright © 2011-2022 走看看