Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add word wrapping mode#3597

Merged
keith-hall merged 7 commits intosharkdp:masterfrom
veeceey:feat/issue-2751-word-wrap
Mar 3, 2026
Merged

Add word wrapping mode#3597
keith-hall merged 7 commits intosharkdp:masterfrom
veeceey:feat/issue-2751-word-wrap

Conversation

@veeceey
Copy link
Contributor

@veeceey veeceey commented Feb 23, 2026

Adds a word option to --wrap that breaks lines at word boundaries (whitespace) instead of mid-character. When a single word exceeds the terminal width, it falls back to character wrapping so nothing gets lost.

Usage: bat --wrap=word file.rs

Closes #2751

@veeceey
Copy link
Contributor Author

veeceey commented Feb 23, 2026

Test results (macOS, local build):

cargo test
test result: ok. 214 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

Manual test with a long line:

$ echo "The quick brown fox jumps over the lazy dog and keeps running across the terminal width boundary to show word wrapping" | bat --wrap=word --terminal-width=40

Line breaks at word boundaries as expected. When a single word exceeds width (e.g. a long URL), it falls back to character wrapping.

Copy link
Collaborator

@keith-hall keith-hall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, thanks for your contribution. Let's add some tests to prove that word wrapping works as expected and prevent accidental regressions in future.
It would also be great if we can update the manpage and shell completions with the new option. I have asked Copilot to do that before with good results. But if you don't want to, we can always apply those changes separately later.

- Add integration tests for word wrapping: basic word boundary breaking,
  fallback to character wrapping for long words, line numbers, and
  short lines that fit without wrapping
- Update manpage to document the new 'word' wrapping mode
- Update bash, fish, zsh, and PowerShell completions with 'word' option
- Avoid unnecessary clone of line_buf when word wrap is disabled
Copy link
Collaborator

@keith-hall keith-hall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks!

@keith-hall keith-hall merged commit cc5f782 into sharkdp:master Mar 3, 2026
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

wrapping by word would be awesome

2 participants