From b6411beaa1ea2170fcdbb8b57bcb9522c189029f Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Wed, 18 Feb 2026 13:21:33 +0900 Subject: [PATCH] Implement word wrapping in the preview window Example: fzf --preview 'bat --style=plain --color=always {}' \ --preview-window wrap-word \ --bind space:toggle-preview-wrap-word Close https://github.com/junegunn/fzf/discussions/3383 --- CHANGELOG.md | 20 +++-- man/man1/fzf.1 | 6 +- src/actiontype_string.go | 147 ++++++++++++++++--------------- src/options.go | 20 ++++- src/options_test.go | 14 +++ src/terminal.go | 185 ++++++++++++++++++++++++++++++--------- src/terminal_test.go | 69 +++++++++++++++ src/tui/light.go | 46 +--------- src/tui/tcell.go | 99 ++++++++++----------- src/tui/tcell_test.go | 12 +-- src/tui/tui.go | 47 +++++++++- src/tui/tui_test.go | 40 +++++++++ 12 files changed, 483 insertions(+), 222 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 98db6270..b2be0443 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,14 @@ CHANGELOG 0.68.0 ------ +- Implemented word wrapping in the preview window + - Added `wrap-word` flag for `--preview-window` to enable word-level wrapping + - Added `toggle-preview-wrap-word` action + ```sh + fzf --preview 'bat --style=plain --color=always {}' \ + --preview-window wrap-word \ + --bind space:toggle-preview-wrap-word + ``` - Added support for underline style variants in `--color`: `underline-double`, `underline-curly`, `underline-dotted`, `underline-dashed` ```sh @@ -22,17 +30,17 @@ CHANGELOG - Bug fixes - Fixed symlinks to directories being returned as files (#4676) (@skk64) - Fixed SIGHUP signal handling (#4668) (@LangLangBart) - - Fixed preview process not killed on exit - - Fixed coloring of items with zero-width characters - - Fixed `track-current` unset after a combined movement action + - Fixed preview process not killed on exit (#4667) + - Fixed coloring of items with zero-width characters (#4620) + - Fixed `track-current` unset after a combined movement action (#4649) - Fixed `--accept-nth` being ignored in filter mode (#4636) (@charemma) - Fixed display width calculation with `maxWidth` (#4596) (@LangLangBart) - - Fixed clearing of the rest of the current line on start - - Fixed `x-api-key` header not required for GET requests + - Fixed clearing of the rest of the current line on start (#4652) + - Fixed `x-api-key` header not required for GET requests (#4627) - Fixed key reading not cancelled when `execute` triggered via a server request (#4653) - Fixed rebind of readline command `redraw-current-line` (#4635) (@jameslazo) - Fixed `fzf-tmux` `TERM` quoting and added `mktemp` usage (#4664) (@Goofygiraffe06) - - Do not allow very long queries in `FuzzyMatchV2` + - Do not allow very long queries in `FuzzyMatchV2` (#4608) 0.67.0 ------ diff --git a/man/man1/fzf.1 b/man/man1/fzf.1 index b0ff851d..b044645b 100644 --- a/man/man1/fzf.1 +++ b/man/man1/fzf.1 @@ -926,7 +926,7 @@ default value 0 (or \fBcenter\fR) will put the label at the center of the border line. .TP -.BI "\-\-preview\-window=" "[POSITION][,SIZE[%]][,border\-STYLE][,[no]wrap][,[no]follow][,[no]cycle][,[no]info][,[no]hidden][,+SCROLL[OFFSETS][/DENOM]][,~HEADER_LINES][,default][,= actionType(len(_actionType_index)-1) { diff --git a/src/options.go b/src/options.go index 51822240..fd9b11b4 100644 --- a/src/options.go +++ b/src/options.go @@ -157,7 +157,7 @@ Usage: fzf [options] --preview=COMMAND Command to preview highlighted line ({}) --preview-window=OPT Preview window layout (default: right:50%) [up|down|left|right][,SIZE[%]] - [,[no]wrap][,[no]cycle][,[no]follow][,[no]info] + [,[no]wrap[-word]][,[no]cycle][,[no]follow][,[no]info] [,[no]hidden][,border-STYLE] [,+SCROLL[OFFSETS][/DENOM]][,~HEADER_LINES] [,default][,