viewing-files

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

bat: Enhanced File Viewer with Syntax Highlighting

bat:具备语法高亮的增强型文件查看器

Always invoke bat skill for enhanced file viewing - do not execute bash commands directly.
Use bat as a modern replacement for cat with beautiful syntax highlighting, Git integration, and smart features.
请始终调用bat技能进行增强型文件查看——不要直接执行bash命令。
将bat作为cat的现代替代工具,它拥有美观的语法高亮、Git集成和智能特性。

When to Use bat vs cat

bat与cat的使用场景对比

Use bat when:
  • Viewing source code or structured text files
  • Syntax highlighting improves readability
  • Need Git integration or line numbers
  • Working with files >50 lines where highlighting helps
  • Previewing changes from other tools
Use cat when:
  • Very small files (<10 lines)
  • Non-text/binary files
  • Simple concatenation without formatting
  • When highlighting would add noise
  • Performance-critical operations on many tiny files
Common workflow: Any skill → bat skill (preview enhanced output)
使用bat的场景:
  • 查看源代码或结构化文本文件
  • 语法高亮可提升可读性时
  • 需要Git集成或行号显示时
  • 处理超过50行、高亮有助于阅读的文件时
  • 预览其他工具的输出变更时
使用cat的场景:
  • 极小的文件(少于10行)
  • 非文本/二进制文件
  • 无需格式的简单拼接操作
  • 高亮会造成干扰时
  • 对大量微小文件进行性能敏感的操作时
常见工作流:任意技能 → bat技能(预览增强型输出)

Default Strategy

默认策略

Invoke bat skill for enhanced file viewing with syntax highlighting. Use when viewing source files, documentation, or when syntax highlighting improves readability.
Common workflow: Any discovery skill → bat skill (preview enhanced output).
调用bat技能进行带语法高亮的增强型文件查看。在查看源文件、文档或语法高亮能提升可读性时使用。
常见工作流:任意发现类技能 → bat技能(预览增强型输出)。

Key Options

核心选项

Display Control

显示控制

  • -n/--number
    line numbers only
  • -p/--plain
    plain output (no decorations)
  • -A/--show-all
    show non-printable characters
  • --line-range START:END
    view specific lines
  • --wrap never
    disable line wrapping
  • --tabs N
    set tab width to N spaces
  • -n/--number
    仅显示行号
  • -p/--plain
    纯文本输出(无装饰)
  • -A/--show-all
    显示不可打印字符
  • --line-range START:END
    查看指定行范围
  • --wrap never
    禁用自动换行
  • --tabs N
    将制表符宽度设置为N个空格

Language & Themes

语言与主题

  • -l/--language LANG
    force language detection
  • --list-languages
    show supported languages
  • --list-themes
    show available themes
  • --theme NAME
    set color theme (default: Monokai Extended)
  • --theme-dark/--theme-light
    auto-switch themes based on terminal
  • BAT_THEME
    environment variable for default theme
  • -l/--language LANG
    强制指定语言检测
  • --list-languages
    显示支持的语言列表
  • --list-themes
    显示可用主题
  • --theme NAME
    设置配色主题(默认:Monokai Extended)
  • --theme-dark/--theme-light
    根据终端自动切换主题
  • BAT_THEME
    用于设置默认主题的环境变量

Output Styling

输出样式

  • --style COMPONENTS
    control output (numbers,changes,header,grid,snip)
  • --decorations auto|never|always
    control decorations
  • --color always|never|auto
    control coloring
  • --style COMPONENTS
    控制输出元素(行号、变更、标题、网格、代码片段)
  • --decorations auto|never|always
    控制装饰元素的显示
  • --color always|never|auto
    控制颜色显示

Paging

分页

  • --paging auto|never|always
    control paging behavior
  • --pager COMMAND
    set custom pager
  • BAT_PAGER
    environment variable
  • --paging auto|never|always
    控制分页行为
  • --pager COMMAND
    设置自定义分页工具
  • BAT_PAGER
    分页工具的环境变量

When to Use

适用场景

  • Code Review: View source files with syntax highlighting and line numbers
  • Git Workflow: Check file modifications and view historical versions
  • Documentation: Colorize help pages and documentation
  • File Concatenation: Replace cat with enhanced features
  • Integration: Use as previewer for fzf or other tools
  • 代码评审:通过语法高亮和行号查看源文件
  • Git工作流:检查文件修改并查看历史版本
  • 文档查看:为帮助页面和文档添加颜色高亮
  • 文件拼接:用增强特性替代cat工具
  • 工具集成:作为fzf或其他工具的预览器

Core Principles

核心原则

  1. Enhanced cat: Drop-in replacement with intelligent improvements
  2. Smart Defaults: Automatic paging when appropriate, Git integration when in repo
  3. Syntax Highlighting: Supports 200+ languages with accurate detection
  4. Performance Optimized: Fast loading, efficient rendering, handles large files well
  1. 增强版cat:可直接替代cat的智能改进工具
  2. 智能默认值:在合适时自动分页,在Git仓库中自动启用Git集成
  3. 语法高亮:支持200+种语言,检测准确
  4. 性能优化:加载速度快,渲染高效,可轻松处理大文件

Detailed Reference

详细参考

For comprehensive usage patterns, integration examples, advanced features, and troubleshooting, load bat guide when needing:
  • Git integration workflows
  • Output styling and customization details
  • Theme configuration and options
  • Performance optimization tips
  • Shell integration examples
The guide includes:
  • Core usage patterns and language control
  • Git integration workflows
  • Output styling and customization
  • Integration with other tools (fzf, git, ripgrep)
  • Advanced features and configuration
  • Performance tips and troubleshooting
如需全面的使用模式、集成示例、高级特性和故障排除指南,请加载bat指南,适用于以下场景:
  • Git集成工作流
  • 输出样式与自定义细节
  • 主题配置与选项
  • 性能优化技巧
  • Shell集成示例
该指南包含:
  • 核心使用模式与语言控制
  • Git集成工作流
  • 输出样式与自定义
  • 与其他工具的集成(fzf、git、ripgrep)
  • 高级特性与配置
  • 性能技巧与故障排除

Skill Combinations

技能组合

For Discovery Phase

发现阶段

  • fd → fzf → bat: Find files, select interactively, view with syntax highlighting
  • ripgrep → fzf → bat: Search content, select matches, view with highlighting
  • jq/yq → fzf → bat: Extract data, select entries, view formatted output
  • fd → fzf → bat:查找文件、交互式选择、带语法高亮查看
  • ripgrep → fzf → bat:搜索内容、选择匹配项、带高亮查看
  • jq/yq → fzf → bat:提取数据、选择条目、查看格式化输出

For Analysis Phase

分析阶段

  • analyzing-code-structure → bat: Preview structural changes with syntax highlighting
  • sd → bat: Preview find-and-replace results before committing
  • extracting-code-structure → bat: View extracted code structure with formatting
  • analyzing-code-structure → bat:带语法高亮预览结构变更
  • sd → bat:提交前预览查找替换结果
  • extracting-code-structure → bat:带格式查看提取的代码结构

For Output Preview

输出预览

  • tokei → bat: View code statistics with formatted output
  • ripgrep → bat: Preview matched files with context highlighting
  • jq/yq → bat: View extracted structured data with syntax formatting
  • tokei → bat:查看带格式的代码统计信息
  • ripgrep → bat:带上下文高亮预览匹配文件
  • jq/yq → bat:带格式查看提取的结构化数据

Integration Examples

集成示例

bash
undefined
bash
undefined

Interactive file viewer

交互式文件查看器

fd --type file | fzf --preview="bat --color=always --style=numbers {}" --bind="enter:execute(bat {})"
fd --type file | fzf --preview="bat --color=always --style=numbers {}" --bind="enter:execute(bat {})"
undefined