在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
完!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· winform 绘制太阳,地球,月球 运作规律
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
2012-02-18 Wget将网站下载到本地
2011-02-18 多用途互联网邮件扩展MIME